Compare commits
2 Commits
4d7fbeae42
...
36d39b524c
| Author | SHA1 | Date | |
|---|---|---|---|
| 36d39b524c | |||
| 9415c60287 |
@ -51,15 +51,15 @@ public class DatabaseConnector
|
||||
{
|
||||
meta.errorMessage = errorMessage;
|
||||
await UpdateMetadataStatus(meta, SaveFileProcessingStatus.Error);
|
||||
DeleteAssociatedFiles(meta);
|
||||
TryDeleteAssociatedFiles(meta);
|
||||
}
|
||||
|
||||
public async Task DeleteMetadata(SaveFileMetadata meta)
|
||||
public async Task DeleteMetadata(SaveFileMetadata meta, string reason)
|
||||
{
|
||||
_logger.LogDebug($"Deleting save file (id: {meta.id} status: {meta.status} " +
|
||||
_logger.LogDebug($"Deleting save file (id: {meta.id} reason: {reason}" +
|
||||
$"uploadDate: {meta.uploadDateTime:yyyy/MM/dd})");
|
||||
await _db.DeleteAsync(meta);
|
||||
DeleteAssociatedFiles(meta);
|
||||
TryDeleteAssociatedFiles(meta);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -71,20 +71,21 @@ public class DatabaseConnector
|
||||
|
||||
var expirationDate = DateTime.Now.AddDays(-_uploadsLifetimeDays);
|
||||
var metadataTable = _db.Table<SaveFileMetadata>();
|
||||
int rowCount = await metadataTable.CountAsync();
|
||||
int i = 0;
|
||||
var metadataList = await metadataTable.ToListAsync();
|
||||
int deleteCount = 0;
|
||||
while(i < rowCount)
|
||||
foreach (var meta in metadataList)
|
||||
{
|
||||
var meta = await metadataTable.ElementAtAsync(i)!;
|
||||
if(meta.status != SaveFileProcessingStatus.Done ||
|
||||
meta.uploadDateTime < expirationDate ||
|
||||
!meta.AssociatedFilesExist())
|
||||
{
|
||||
deleteCount++;
|
||||
await DeleteMetadata(meta);
|
||||
}
|
||||
i++;
|
||||
string deletionReason;
|
||||
if(meta.status != SaveFileProcessingStatus.Done)
|
||||
deletionReason = $"invalid status ({meta.status})";
|
||||
else if (meta.uploadDateTime < expirationDate)
|
||||
deletionReason = "expired";
|
||||
else if(!meta.AssociatedFilesExist())
|
||||
deletionReason = "files not found";
|
||||
else continue;
|
||||
|
||||
deleteCount++;
|
||||
await DeleteMetadata(meta, deletionReason);
|
||||
}
|
||||
|
||||
_logger.LogInfo($"Deleted {deleteCount} invalid records");
|
||||
@ -97,7 +98,7 @@ public class DatabaseConnector
|
||||
File.Delete(file);
|
||||
}
|
||||
|
||||
private void DeleteAssociatedFiles(SaveFileMetadata meta)
|
||||
private void TryDeleteAssociatedFiles(SaveFileMetadata meta)
|
||||
{
|
||||
TryDeleteFile(meta.GetSaveFilePath());
|
||||
TryDeleteFile(meta.GetParsedDataPath());
|
||||
|
||||
@ -4,7 +4,8 @@ namespace ParadoxSaveParser.WebAPI;
|
||||
|
||||
public static class PathHelper
|
||||
{
|
||||
public static readonly IOPath DATA_DIR = "data";
|
||||
public static readonly IOPath PUBLIC_DIR = "public";
|
||||
public static readonly IOPath DATA_DIR = Path.Concat(PUBLIC_DIR, "data");
|
||||
public static readonly IOPath SAVES_DIR = Path.Concat(DATA_DIR, "saves");
|
||||
public static readonly IOPath PARSED_DIR = Path.Concat(DATA_DIR, "parsed");
|
||||
public static readonly IOPath TEMP_DIR = "temp";
|
||||
|
||||
@ -97,7 +97,7 @@ public static class Program
|
||||
// http server
|
||||
var router = new SimpleRouter(loggerRoot);
|
||||
router.DefaultRoute = new SimpleRouter.RouteWithMethod(HttpMethod.GET,
|
||||
new ServeFilesRouteHandler("public"));
|
||||
new ServeFilesRouteHandler(PathHelper.PUBLIC_DIR));
|
||||
router.MapRoute("/uploadSave", HttpMethod.POST,
|
||||
new UploadSaveHandler(mainCancel.Token, bgJobManager, saveFilters));
|
||||
router.MapRoute("/getSaveStatus", HttpMethod.GET,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user