mirror of
https://github.com/whoswhip/Sharpbin.git
synced 2026-12-06 02:48:43 +00:00
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.
This commit is contained in:
+5
-3
@@ -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 += $"<a title=\"{paste.Title}\" href=\"/{paste.Id}\"><li>{title} {difference} {ConvertToBytes(paste.Size)}</li></a>";
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user