mirror of
https://github.com/whoswhip/Sharpbin.git
synced 2026-12-06 02:48:43 +00:00
refactor: update UpdatePasteID method to UpdatePaste
This commit is contained in:
@@ -740,9 +740,9 @@ namespace SharpbinV2.Server.Services
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public async Task<Paste?> UpdatePasteID(Paste paste, string newId, ILogger logger)
|
public async Task<Paste?> UpdatePaste(Paste paste, ILogger logger)
|
||||||
{
|
{
|
||||||
if (paste == null || string.IsNullOrEmpty(paste.UUID) || string.IsNullOrEmpty(newId))
|
if (paste == null || string.IsNullOrEmpty(paste.UUID))
|
||||||
return null;
|
return null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -751,20 +751,23 @@ namespace SharpbinV2.Server.Services
|
|||||||
await connection.OpenAsync();
|
await connection.OpenAsync();
|
||||||
using (var command = connection.CreateCommand())
|
using (var command = connection.CreateCommand())
|
||||||
{
|
{
|
||||||
command.CommandText = "UPDATE pastes SET ID = @NewID, Fileath = @FilePath WHERE UUID = @UUID;";
|
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("@NewID", newId);
|
command.Parameters.AddWithValue("@Visibility", paste.Visibility ?? 0);
|
||||||
command.Parameters.AddWithValue("@FilePath", $"pastes/{newId}" ?? paste.FilePath);
|
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);
|
command.Parameters.AddWithValue("@UUID", paste.UUID);
|
||||||
await command.ExecuteNonQueryAsync();
|
await command.ExecuteNonQueryAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
paste.ID = newId;
|
|
||||||
paste.FilePath = $"pastes/{newId}";
|
|
||||||
return paste;
|
return paste;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
logger.LogError(ex, "Failed to update paste ID in database.");
|
logger.LogError(ex, "Failed to update paste in database.");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user