code reformat and cleanup
This commit is contained in:
@@ -5,10 +5,10 @@ namespace ParadoxSaveParser.WebAPI;
|
||||
public class Config
|
||||
{
|
||||
public const int ActualVersion = 1;
|
||||
|
||||
public int Version = ActualVersion;
|
||||
public string BaseUrl = "http://127.0.0.1:5226/";
|
||||
|
||||
public int Version = ActualVersion;
|
||||
|
||||
public static Config FromDtsod(DtsodV23 d)
|
||||
{
|
||||
var cfg = new Config
|
||||
@@ -18,16 +18,16 @@ public class Config
|
||||
};
|
||||
if (cfg.Version < ActualVersion)
|
||||
throw new Exception($"config is obsolete (config v{cfg.Version} < program v{ActualVersion})");
|
||||
if(cfg.Version > ActualVersion)
|
||||
if (cfg.Version > ActualVersion)
|
||||
throw new Exception($"program is obsolete (config v{cfg.Version} > program v{ActualVersion})");
|
||||
return cfg;
|
||||
}
|
||||
|
||||
public DtsodV23 ToDtsod() =>
|
||||
new()
|
||||
public DtsodV23 ToDtsod()
|
||||
=> new()
|
||||
{
|
||||
{ "version", Version },
|
||||
{ "baseUrl", BaseUrl },
|
||||
{ "baseUrl", BaseUrl }
|
||||
};
|
||||
|
||||
public override string ToString() => ToDtsod().ToString();
|
||||
|
||||
@@ -9,10 +9,10 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ParadoxSaveParser.Lib\ParadoxSaveParser.Lib.csproj" />
|
||||
<ProjectReference Include="..\ParadoxSaveParser.Lib\ParadoxSaveParser.Lib.csproj"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="DTLib.Web" Version="1.2.2" />
|
||||
<PackageReference Include="DTLib.Web" Version="1.2.2"/>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
@@ -4,7 +4,10 @@ public static class PathHelper
|
||||
{
|
||||
public static readonly IOPath DATA_DIR = "data";
|
||||
public static readonly IOPath SAVES_DIR = Path.Concat(DATA_DIR, "saves");
|
||||
|
||||
public static IOPath GetMetaFilePath(string save_id) => Path.Concat(SAVES_DIR, save_id + ".meta.json");
|
||||
|
||||
public static IOPath GetSaveFilePath(string save_id) => Path.Concat(SAVES_DIR, save_id + ".eu4");
|
||||
|
||||
public static IOPath GetParsedSaveFilePath(string save_id) => Path.Concat(SAVES_DIR, save_id + ".parsed.json");
|
||||
}
|
||||
@@ -14,7 +14,7 @@ public partial class Program
|
||||
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
|
||||
MaxDepth = 1024
|
||||
};
|
||||
|
||||
|
||||
public static async Task<HttpStatusCode> ReturnResponseString(HttpListenerContext ctx,
|
||||
string value, HttpStatusCode statusCode = HttpStatusCode.OK)
|
||||
{
|
||||
@@ -53,6 +53,17 @@ public partial class Program
|
||||
return error.StatusCode;
|
||||
}
|
||||
|
||||
|
||||
internal static ValueOrError<string> GetRequestQueryValue(HttpListenerContext ctx, string paramName)
|
||||
{
|
||||
string[]? values = ctx.Request.QueryString.GetValues(paramName);
|
||||
string? value = values?.FirstOrDefault();
|
||||
if (string.IsNullOrEmpty(value))
|
||||
return new ErrorMessage(HttpStatusCode.BadRequest,
|
||||
$"No request parameter '{paramName}' provided");
|
||||
return value;
|
||||
}
|
||||
|
||||
public record ErrorMessage
|
||||
{
|
||||
public ErrorMessage(HttpStatusCode statusCode, string message)
|
||||
@@ -83,15 +94,4 @@ public partial class Program
|
||||
|
||||
public static implicit operator ValueOrError<T>(ErrorMessage e) => new(default, e);
|
||||
}
|
||||
|
||||
|
||||
internal static ValueOrError<string> GetRequestQueryValue(HttpListenerContext ctx, string paramName)
|
||||
{
|
||||
string[]? values = ctx.Request.QueryString.GetValues(paramName);
|
||||
string? value = values?.FirstOrDefault();
|
||||
if (string.IsNullOrEmpty(value))
|
||||
return new ErrorMessage(HttpStatusCode.BadRequest,
|
||||
$"No request parameter '{paramName}' provided");
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@@ -4,26 +4,31 @@ namespace ParadoxSaveParser.WebAPI;
|
||||
|
||||
public enum SaveFileProcessingStatus
|
||||
{
|
||||
Initialized, Uploading, Uploaded, Parsing, SavingResults, Done
|
||||
Initialized,
|
||||
Uploading,
|
||||
Uploaded,
|
||||
Parsing,
|
||||
SavingResults,
|
||||
Done
|
||||
}
|
||||
|
||||
public enum Game
|
||||
{
|
||||
Unknown, EU4
|
||||
Unknown,
|
||||
EU4
|
||||
}
|
||||
|
||||
public class SaveFileMetadata
|
||||
{
|
||||
private static readonly JsonSerializerOptions _jsonOptions = new() { WriteIndented = true };
|
||||
public required string id { get; init; }
|
||||
|
||||
|
||||
[JsonConverter(typeof(JsonStringEnumConverter))]
|
||||
public required Game game { get; init; }
|
||||
|
||||
|
||||
[JsonConverter(typeof(JsonStringEnumConverter))]
|
||||
public required SaveFileProcessingStatus status { get; set; }
|
||||
|
||||
|
||||
private static readonly JsonSerializerOptions _jsonOptions = new() { WriteIndented = true };
|
||||
|
||||
public void SaveToFile()
|
||||
{
|
||||
using var metaFile = File.OpenWrite(PathHelper.GetMetaFilePath(id));
|
||||
|
||||
Reference in New Issue
Block a user