♻️ Changed the way to clean upload folder
This commit is contained in:
@@ -7,12 +7,27 @@ namespace DysonNetwork.Drive.Storage;
|
||||
public class CloudFileUnusedRecyclingJob(
|
||||
AppDatabase db,
|
||||
FileReferenceService fileRefService,
|
||||
ILogger<CloudFileUnusedRecyclingJob> logger
|
||||
ILogger<CloudFileUnusedRecyclingJob> logger,
|
||||
IConfiguration configuration
|
||||
)
|
||||
: IJob
|
||||
{
|
||||
public async Task Execute(IJobExecutionContext context)
|
||||
{
|
||||
logger.LogInformation("Cleaning tus cloud files...");
|
||||
var storePath = configuration["Tus:StorePath"];
|
||||
if (Directory.Exists(storePath))
|
||||
{
|
||||
var oneHourAgo = SystemClock.Instance.GetCurrentInstant() - Duration.FromHours(1);
|
||||
var files = Directory.GetFiles(storePath);
|
||||
foreach (var file in files)
|
||||
{
|
||||
var creationTime = File.GetCreationTime(file).ToUniversalTime();
|
||||
if (creationTime < oneHourAgo.ToDateTimeUtc())
|
||||
File.Delete(file);
|
||||
}
|
||||
}
|
||||
|
||||
logger.LogInformation("Marking unused cloud files...");
|
||||
|
||||
var recyclablePools = await db.Pools
|
||||
|
@@ -48,11 +48,9 @@ public class FileExpirationJob(AppDatabase db, FileService fileService, ILogger<
|
||||
if (remainingReferences == 0)
|
||||
{
|
||||
var file = await db.Files.FirstOrDefaultAsync(f => f.Id == fileId);
|
||||
if (file != null)
|
||||
{
|
||||
logger.LogInformation("Deleting file {fileId} as all references have expired", fileId);
|
||||
await fileService.DeleteFileAsync(file);
|
||||
}
|
||||
if (file == null) continue;
|
||||
logger.LogInformation("Deleting file {fileId} as all references have expired", fileId);
|
||||
await fileService.DeleteFileAsync(file);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@@ -170,7 +170,6 @@ public class FileService(
|
||||
// await db.SaveChangesAsync();
|
||||
// // Since the file content is a duplicate, we can delete the new upload and we are done.
|
||||
// await stream.DisposeAsync();
|
||||
// await store.DeleteFileAsync(file.Id, CancellationToken.None);
|
||||
// return file;
|
||||
// }
|
||||
|
||||
@@ -432,7 +431,6 @@ public class FileService(
|
||||
}
|
||||
finally
|
||||
{
|
||||
await store.DeleteFileAsync(fileId, CancellationToken.None);
|
||||
await nfs._PurgeCacheAsync(fileId);
|
||||
}
|
||||
}
|
||||
|
@@ -142,8 +142,6 @@ public abstract class TusService
|
||||
{
|
||||
eventContext.HttpContext.Response.StatusCode = StatusCodes.Status400BadRequest;
|
||||
await eventContext.HttpContext.Response.WriteAsync(ex.Message);
|
||||
if (eventContext.Store is TusDiskStore disk)
|
||||
await disk.DeleteFileAsync(file.Id, eventContext.CancellationToken);
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
Reference in New Issue
Block a user