From 878cebacb695ecbea9865baa7233d0faf2705b4e Mon Sep 17 00:00:00 2001 From: whoswhip Date: Mon, 9 Sep 2024 21:41:06 -0400 Subject: [PATCH] Enhance null safety, UI, and SQL query handling Improved null safety in `Program.cs` by using the null-conditional operator (`?.`) when accessing cookies. Modified SQL queries to exclude 'Unlisted' pastes and added checks to skip processing 'Private' or 'Unlisted' pastes. Adjusted the command to count total pastes to exclude 'Unlisted' pastes. Updated `admin/user.html` to support multiple notifications, added functionality to copy the new password to the clipboard, and improved notification display and animation logic. Removed a hardcoded paste link from `archives.html` which was for testing. Enhanced `index.html` with a hamburger menu for mobile navigation, improved notification handling, and added CSS styles and media queries for better mobile support. Fixed minor formatting issues and improved code readability. --- PasteBin/Program.cs | 8 ++- PasteBin/Sharpbin.csproj | 8 +++ PasteBin/assets/admin/user.html | 56 +++++++++++------ PasteBin/assets/archives.html | 1 - PasteBin/assets/index.html | 103 ++++++++++++++++++++++++++++++-- 5 files changed, 149 insertions(+), 27 deletions(-) diff --git a/PasteBin/Program.cs b/PasteBin/Program.cs index 031d843..e0813ca 100644 --- a/PasteBin/Program.cs +++ b/PasteBin/Program.cs @@ -94,7 +94,7 @@ class Program bool loggedIn = await IsLoggedInAsync(context.Request.Cookies["token"]); if (loggedIn) { - var user = await GetLoggedInUserAsync(context.Request.Cookies["token"]); + var user = await GetLoggedInUserAsync(context?.Request?.Cookies?["token"]); if (user.State != 0) { var punishment = await GetPunishmentAsync(user.UUID); @@ -639,7 +639,7 @@ class Program { await connection.OpenAsync(); var command = connection.CreateCommand(); - command.CommandText = $"SELECT * FROM pastes WHERE Visibility != 'Private' ORDER BY UID DESC LIMIT {pastesPerPage} OFFSET {skipCount}"; + command.CommandText = $"SELECT * FROM pastes WHERE Visibility != 'Private' AND Visibility != 'Unlisted' ORDER BY UID DESC LIMIT {pastesPerPage} OFFSET {skipCount}"; var reader = await command.ExecuteReaderAsync(); string pastes = string.Empty; while (await reader.ReadAsync()) @@ -652,6 +652,7 @@ class Program Visibility = reader.GetString(4), Id = reader.GetString(5), }; + string title = paste.Title; if (paste.Visibility == "Private" || paste.Visibility == "Unlisted") { @@ -668,8 +669,9 @@ class Program var difference = GetTimeDifference(DateTimeOffset.FromUnixTimeSeconds(paste.UnixDate ?? 0), DateTimeOffset.FromUnixTimeSeconds(DateTimeOffset.Now.ToUnixTimeSeconds())); pastes += $"
  • {title} {difference} {ConvertToBytes(paste.Size)}
  • "; } + var findCountCommand = connection.CreateCommand(); - findCountCommand.CommandText = "SELECT COUNT(*) FROM pastes WHERE Visibility != 'Private'"; + findCountCommand.CommandText = "SELECT COUNT(*) FROM pastes WHERE Visibility != 'Private' AND Visibility != 'Unlisted'"; int totalPastes = Convert.ToInt32(await findCountCommand.ExecuteScalarAsync()); int totalPages = (int)Math.Ceiling((double)totalPastes / pastesPerPage); diff --git a/PasteBin/Sharpbin.csproj b/PasteBin/Sharpbin.csproj index 5925c7c..810a3e8 100644 --- a/PasteBin/Sharpbin.csproj +++ b/PasteBin/Sharpbin.csproj @@ -22,9 +22,11 @@ + + @@ -43,6 +45,12 @@ Always + + Always + + + Always + diff --git a/PasteBin/assets/admin/user.html b/PasteBin/assets/admin/user.html index 4f40908..8cac62c 100644 --- a/PasteBin/assets/admin/user.html +++ b/PasteBin/assets/admin/user.html @@ -45,8 +45,8 @@ -
    -

    +
    +