Add feature to delete uploaded files with uploader and admin permissions

This commit is contained in:
tyuXX 2026-10-31 16:45:58 +03:00
parent 7cc9ba7f4d
commit 45629b122e
16 changed files with 587 additions and 8 deletions

View file

@ -171,6 +171,29 @@ public class FileStorageService
return await _db.GetFileRecordAsync(fileId);
}
public async Task<bool> DeleteFileAsync(string fileId)
{
var record = await _db.GetFileRecordAsync(fileId);
if (record == null)
{
return false;
}
try
{
if (!string.IsNullOrWhiteSpace(record.StoragePath) && File.Exists(record.StoragePath))
{
File.Delete(record.StoragePath);
}
}
catch
{
// Best effort disk cleanup
}
return await _db.DeleteFileRecordAsync(fileId);
}
public Stream? OpenFileStream(FileRecord record)
{
if (File.Exists(record.StoragePath))