initial commit
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>disable</ImplicitUsings>
|
||||
<InvariantGlobalization>true</InvariantGlobalization>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ParadoxSaveParser.Lib\ParadoxSaveParser.Lib.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,6 @@
|
||||
@ParadoxSaveParser.WebAPI_HostAddress = http://localhost:5226
|
||||
|
||||
GET {{ParadoxSaveParser.WebAPI_HostAddress}}/weatherforecast/
|
||||
Accept: application/json
|
||||
|
||||
###
|
||||
@@ -0,0 +1,76 @@
|
||||
global using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using ParadoxSaveParser.Lib;
|
||||
|
||||
namespace ParadoxSaveParser.WebAPI;
|
||||
|
||||
public enum SaveFileProcessingStatus
|
||||
{
|
||||
NotFound, Uploading, Parsing, SavingResults, Done, Error
|
||||
}
|
||||
|
||||
public class SaveFileMetadata
|
||||
{
|
||||
public required string guid;
|
||||
public required SaveFileProcessingStatus status { get; set; }
|
||||
}
|
||||
|
||||
public class Program
|
||||
{
|
||||
private const string DATA_DIR = "data";
|
||||
private static string SAVES_DIR = Path.Join(DATA_DIR, "saves");
|
||||
private static ConcurrentDictionary<string, SaveFileMetadata> _saveMetadataStorage = new();
|
||||
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
var app = builder.Build();
|
||||
|
||||
foreach (var metaFilePath in Directory.GetFiles(SAVES_DIR, "*.meta.json", SearchOption.TopDirectoryOnly))
|
||||
{
|
||||
using var metaFile = File.Open(metaFilePath, FileMode.Open, FileAccess.Read);
|
||||
var meta = JsonSerializer.Deserialize<SaveFileMetadata>(metaFile) ?? throw new NullReferenceException(metaFilePath);
|
||||
if (meta.status != SaveFileProcessingStatus.Done)
|
||||
{
|
||||
app.Logger.Log(LogLevel.Warning, $"metadata file '{metaFilePath}' status has invalid status {meta.status}"));
|
||||
}
|
||||
|
||||
if(!_saveMetadataStorage.TryAdd(meta.guid, meta))
|
||||
throw new Exception("Guid collision!");
|
||||
}
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
app.MapPost("/parse/eu4", async httpContext =>
|
||||
{
|
||||
var remoteFile = httpContext.Request.Form.Files.FirstOrDefault();
|
||||
if(remoteFile is null)
|
||||
return;
|
||||
string save_id = Guid.NewGuid().ToString();
|
||||
string meta_file_path = Path.Join(SAVES_DIR, save_id + ".meta.json");
|
||||
// string save_file_path = Path.Join(SAVES_DIR, save_id + ".eu4");
|
||||
// await using var metaFile = File.Open(meta_file_path, FileMode.CreateNew, FileAccess.Write);
|
||||
if (File.Exists(meta_file_path))
|
||||
{
|
||||
httpContext.Response.StatusCode = StatusCodes.Status500InternalServerError;
|
||||
throw new Exception($"Guid collision! file {meta_file_path} already exists.")
|
||||
}
|
||||
|
||||
await using var saveFile =
|
||||
await remoteFile.OpenReadStream().CopyToAsync();
|
||||
var parser = new ParserEU4(stream);
|
||||
|
||||
|
||||
});
|
||||
|
||||
app.Run();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
{
|
||||
"$schema": "http://json.schemastore.org/launchsettings.json",
|
||||
"iisSettings": {
|
||||
"windowsAuthentication": false,
|
||||
"anonymousAuthentication": true,
|
||||
"iisExpress": {
|
||||
"applicationUrl": "http://localhost:38396",
|
||||
"sslPort": 44312
|
||||
}
|
||||
},
|
||||
"profiles": {
|
||||
"http": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "/",
|
||||
"applicationUrl": "http://localhost:5226",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"https": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "/",
|
||||
"applicationUrl": "https://localhost:7032;http://localhost:5226",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"IIS Express": {
|
||||
"commandName": "IISExpress",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "/",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
||||
Reference in New Issue
Block a user