Compare commits
3 Commits
4d7fbeae42
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 8c23f974c3 | |||
| 36d39b524c | |||
| 9415c60287 |
@@ -51,15 +51,15 @@ public class DatabaseConnector
|
|||||||
{
|
{
|
||||||
meta.errorMessage = errorMessage;
|
meta.errorMessage = errorMessage;
|
||||||
await UpdateMetadataStatus(meta, SaveFileProcessingStatus.Error);
|
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})");
|
$"uploadDate: {meta.uploadDateTime:yyyy/MM/dd})");
|
||||||
await _db.DeleteAsync(meta);
|
await _db.DeleteAsync(meta);
|
||||||
DeleteAssociatedFiles(meta);
|
TryDeleteAssociatedFiles(meta);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -71,20 +71,21 @@ public class DatabaseConnector
|
|||||||
|
|
||||||
var expirationDate = DateTime.Now.AddDays(-_uploadsLifetimeDays);
|
var expirationDate = DateTime.Now.AddDays(-_uploadsLifetimeDays);
|
||||||
var metadataTable = _db.Table<SaveFileMetadata>();
|
var metadataTable = _db.Table<SaveFileMetadata>();
|
||||||
int rowCount = await metadataTable.CountAsync();
|
var metadataList = await metadataTable.ToListAsync();
|
||||||
int i = 0;
|
|
||||||
int deleteCount = 0;
|
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())
|
|
||||||
{
|
{
|
||||||
|
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++;
|
deleteCount++;
|
||||||
await DeleteMetadata(meta);
|
await DeleteMetadata(meta, deletionReason);
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_logger.LogInfo($"Deleted {deleteCount} invalid records");
|
_logger.LogInfo($"Deleted {deleteCount} invalid records");
|
||||||
@@ -97,7 +98,7 @@ public class DatabaseConnector
|
|||||||
File.Delete(file);
|
File.Delete(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DeleteAssociatedFiles(SaveFileMetadata meta)
|
private void TryDeleteAssociatedFiles(SaveFileMetadata meta)
|
||||||
{
|
{
|
||||||
TryDeleteFile(meta.GetSaveFilePath());
|
TryDeleteFile(meta.GetSaveFilePath());
|
||||||
TryDeleteFile(meta.GetParsedDataPath());
|
TryDeleteFile(meta.GetParsedDataPath());
|
||||||
|
|||||||
@@ -14,15 +14,15 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="DTLib.Web" Version="1.4.0" />
|
<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" />
|
<PackageReference Include="sqlite-net-pcl" Version="1.9.172" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<!-- <ItemGroup>-->
|
||||||
<Compile Include="obj\Protobuf\*.g.cs" />
|
<!-- <Compile Include="obj\Protobuf\*.g.cs" />-->
|
||||||
</ItemGroup>
|
<!-- </ItemGroup>-->
|
||||||
|
|
||||||
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
|
<!-- <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"" />
|
<!-- <Exec Command="sh -c "mkdir -p obj/Protobuf && protoc Protobuf/*.proto --csharp_out=obj/Protobuf --csharp_opt=file_extension=.g.cs"" />-->
|
||||||
</Target>
|
<!-- </Target>-->
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -4,7 +4,8 @@ namespace ParadoxSaveParser.WebAPI;
|
|||||||
|
|
||||||
public static class PathHelper
|
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 SAVES_DIR = Path.Concat(DATA_DIR, "saves");
|
||||||
public static readonly IOPath PARSED_DIR = Path.Concat(DATA_DIR, "parsed");
|
public static readonly IOPath PARSED_DIR = Path.Concat(DATA_DIR, "parsed");
|
||||||
public static readonly IOPath TEMP_DIR = "temp";
|
public static readonly IOPath TEMP_DIR = "temp";
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ public static class Program
|
|||||||
// http server
|
// http server
|
||||||
var router = new SimpleRouter(loggerRoot);
|
var router = new SimpleRouter(loggerRoot);
|
||||||
router.DefaultRoute = new SimpleRouter.RouteWithMethod(HttpMethod.GET,
|
router.DefaultRoute = new SimpleRouter.RouteWithMethod(HttpMethod.GET,
|
||||||
new ServeFilesRouteHandler("public"));
|
new ServeFilesRouteHandler(PathHelper.PUBLIC_DIR));
|
||||||
router.MapRoute("/uploadSave", HttpMethod.POST,
|
router.MapRoute("/uploadSave", HttpMethod.POST,
|
||||||
new UploadSaveHandler(mainCancel.Token, bgJobManager, saveFilters));
|
new UploadSaveHandler(mainCancel.Token, bgJobManager, saveFilters));
|
||||||
router.MapRoute("/getSaveStatus", HttpMethod.GET,
|
router.MapRoute("/getSaveStatus", HttpMethod.GET,
|
||||||
|
|||||||
1
TODO.md
1
TODO.md
@@ -1,3 +1,4 @@
|
|||||||
## WebAPI.SaveParsingOperation:
|
## WebAPI.SaveParsingOperation:
|
||||||
Save parsed data in protobuf
|
Save parsed data in protobuf
|
||||||
Re-parse if saved data was parsed with another query
|
Re-parse if saved data was parsed with another query
|
||||||
|
Implement automatic database cleanup
|
||||||
Reference in New Issue
Block a user