Compare commits
3 Commits
4d7fbeae42
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 8c23f974c3 | |||
| 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)
|
||||
{
|
||||
var meta = await metadataTable.ElementAtAsync(i)!;
|
||||
if(meta.status != SaveFileProcessingStatus.Done ||
|
||||
meta.uploadDateTime < expirationDate ||
|
||||
!meta.AssociatedFilesExist())
|
||||
foreach (var meta in metadataList)
|
||||
{
|
||||
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);
|
||||
}
|
||||
i++;
|
||||
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());
|
||||
|
||||
@@ -14,15 +14,15 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="DTLib.Web" Version="1.4.0" />
|
||||
<PackageReference Include="Google.Protobuf" Version="3.31.0" />
|
||||
<!-- <PackageReference Include="Google.Protobuf" Version="3.31.0" />-->
|
||||
<PackageReference Include="sqlite-net-pcl" Version="1.9.172" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="obj\Protobuf\*.g.cs" />
|
||||
</ItemGroup>
|
||||
<!-- <ItemGroup>-->
|
||||
<!-- <Compile Include="obj\Protobuf\*.g.cs" />-->
|
||||
<!-- </ItemGroup>-->
|
||||
|
||||
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
|
||||
<Exec Command="sh -c "mkdir -p obj/Protobuf && protoc Protobuf/*.proto --csharp_out=obj/Protobuf --csharp_opt=file_extension=.g.cs"" />
|
||||
</Target>
|
||||
<!-- <Target Name="PreBuild" BeforeTargets="PreBuildEvent">-->
|
||||
<!-- <Exec Command="sh -c "mkdir -p obj/Protobuf && protoc Protobuf/*.proto --csharp_out=obj/Protobuf --csharp_opt=file_extension=.g.cs"" />-->
|
||||
<!-- </Target>-->
|
||||
</Project>
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user