compress parsed data to .json.zst

This commit is contained in:
2026-09-23 18:25:15 +02:00
parent c6b27cd3c9
commit 55f7d453b1
9 changed files with 67 additions and 35 deletions
+18 -4
View File
@@ -1,4 +1,5 @@
using System.Text.Json.Serialization;
using ZstdSharp;
namespace ParadoxSaveParser.WebAPI;
@@ -11,13 +12,21 @@ public class Config
public int UploadLifetimeDays { get; set; } = 30;
public string DbPath { get; set; } = "database.sqlite";
public SaveUploadConfig SaveUpload { get; set; } = new();
/// level used to compress parsed save data
public int ZstdCompressionLevel { get; set; } = 10;
public class SaveUploadConfig
{
/// max size of game data entry after decompression
public long MaxSizePlainTextBytes { get; set; } = 200 * 1024 * 1024;
/// max size of uploaded .tar.zst
public long MaxSizeCompressedBytes { get; set; } = 60 * 1024 * 1024;
/// max size of game data entry after decompression, in MiB
public int MaxSizePlainTextMegabytes { get; set; } = 200;
/// max size of uploaded .tar.zst, in MiB
public int MaxSizeCompressedMegabytes { get; set; } = 60;
// long, because int overflows at 2048 MiB
[JsonIgnore]
public long MaxSizePlainTextBytes => MaxSizePlainTextMegabytes * 1024L * 1024L;
[JsonIgnore]
public long MaxSizeCompressedBytes => MaxSizeCompressedMegabytes * 1024L * 1024L;
}
public static JsonSerializerOptions JsonOptions = new()
@@ -35,6 +44,11 @@ public class Config
throw new Exception($"config is obsolete (config v{cfg.Version} < program v{ActualVersion})");
if (cfg.Version > ActualVersion)
throw new Exception($"program is obsolete (config v{cfg.Version} > program v{ActualVersion})");
// fail on start instead of on first parsed save
if (cfg.ZstdCompressionLevel < Compressor.MinCompressionLevel
|| cfg.ZstdCompressionLevel > Compressor.MaxCompressionLevel)
throw new Exception($"{nameof(ZstdCompressionLevel)} must be in range "
+ $"[{Compressor.MinCompressionLevel}, {Compressor.MaxCompressionLevel}]");
return cfg;
}