Enhance paste management and user interface

- Updated `AuthController.cs` to include user `Type` in responses.
- Added `DeletePaste` and `ChangePasteID` endpoints in `PasteController.cs` with authentication and error handling.
- Removed `Logging.cs`, indicating a refactor of the logging mechanism.
- Implemented methods for deleting and updating paste IDs in `DatabaseService.cs`.
- Modified `SharpbinV2.Server.csproj` to exclude `logs` and `pastes` directories from compilation.
- Enhanced `paste.css` with styles for an edit icon.
- Introduced `userTypes` object in `dash.js` for better role management.
- Added delete button functionality in `paste.js` for authorized users.
- Updated `paste.html` to include edit and delete buttons for improved user experience.
This commit is contained in:
whoswhip
2025-07-10 16:07:35 -04:00
parent b95f540ef4
commit 57f1709032
9 changed files with 225 additions and 33 deletions
@@ -699,5 +699,69 @@ namespace SharpbinV2.Server.Services
return null;
}
}
public async Task<bool> DeletePaste(Paste paste, ILogger logger)
{
if (paste == null || string.IsNullOrEmpty(paste.UUID))
return false;
try
{
using (var connection = new SqliteConnection(_connectionString))
{
await connection.OpenAsync();
using (var command = connection.CreateCommand())
{
command.CommandText = "DELETE FROM pastes WHERE UUID = @UUID;";
command.Parameters.AddWithValue("@UUID", paste.UUID);
await command.ExecuteNonQueryAsync();
}
using (var command = connection.CreateCommand())
{
command.CommandText = "DELETE FROM views WHERE PasteUUID = @PasteUUID;";
command.Parameters.AddWithValue("@PasteUUID", paste.UUID);
await command.ExecuteNonQueryAsync();
}
if (!string.IsNullOrEmpty(paste.FilePath) && File.Exists(paste.FilePath))
{
File.Delete(paste.FilePath);
}
}
return true;
}
catch (Exception ex)
{
logger.LogError(ex, "Failed to delete paste from database.");
return false;
}
}
public async Task<Paste?> UpdatePasteID(Paste paste, string newId, ILogger logger)
{
if (paste == null || string.IsNullOrEmpty(paste.UUID) || string.IsNullOrEmpty(newId))
return null;
try
{
using (var connection = new SqliteConnection(_connectionString))
{
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.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.");
return null;
}
}
}
}