From 78c26fa2d24ca17d80fb1426b767503879b63905 Mon Sep 17 00:00:00 2001 From: whoswhip Date: Tue, 7 Oct 2025 21:26:46 -0400 Subject: [PATCH] refactor: update UpdatePasteID method to UpdatePaste --- SharpbinV2.Server/Services/DatabaseService.cs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/SharpbinV2.Server/Services/DatabaseService.cs b/SharpbinV2.Server/Services/DatabaseService.cs index 34347c7..8889caa 100644 --- a/SharpbinV2.Server/Services/DatabaseService.cs +++ b/SharpbinV2.Server/Services/DatabaseService.cs @@ -740,9 +740,9 @@ namespace SharpbinV2.Server.Services return false; } } - public async Task UpdatePasteID(Paste paste, string newId, ILogger logger) + public async Task UpdatePaste(Paste paste, ILogger logger) { - if (paste == null || string.IsNullOrEmpty(paste.UUID) || string.IsNullOrEmpty(newId)) + if (paste == null || string.IsNullOrEmpty(paste.UUID)) return null; try { @@ -751,20 +751,23 @@ namespace SharpbinV2.Server.Services await connection.OpenAsync(); using (var command = connection.CreateCommand()) { - command.CommandText = "UPDATE pastes SET ID = @NewID, Fileath = @FilePath WHERE UUID = @UUID;"; - command.Parameters.AddWithValue("@NewID", newId); - command.Parameters.AddWithValue("@FilePath", $"pastes/{newId}" ?? paste.FilePath); + command.CommandText = "UPDATE pastes SET Visibility = @Visibility, Title = @Title, Edited = @Edited, Size = @Size, TrueSize = @TrueSize, Syntax = @Syntax, FilePath = @FilePath WHERE UUID = @UUID;"; + command.Parameters.AddWithValue("@Visibility", paste.Visibility ?? 0); + command.Parameters.AddWithValue("@Title", paste.Title ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@Edited", DateTimeOffset.UtcNow.ToUnixTimeSeconds()); + command.Parameters.AddWithValue("@Size", paste.Size ?? 0); + command.Parameters.AddWithValue("@TrueSize", paste.TrueSize ?? 0); + command.Parameters.AddWithValue("@Syntax", paste.Syntax ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@FilePath", paste.FilePath); command.Parameters.AddWithValue("@UUID", paste.UUID); await command.ExecuteNonQueryAsync(); } } - paste.ID = newId; - paste.FilePath = $"pastes/{newId}"; return paste; } catch (Exception ex) { - logger.LogError(ex, "Failed to update paste ID in database."); + logger.LogError(ex, "Failed to update paste in database."); return null; } }