Add feature to delete uploaded files with uploader and admin permissions
This commit is contained in:
parent
7cc9ba7f4d
commit
45629b122e
16 changed files with 587 additions and 8 deletions
|
|
@ -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))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue