Skip to content

Commit

Permalink
Base64 the json inside html
Browse files Browse the repository at this point in the history
  • Loading branch information
Aragas committed Apr 6, 2024
1 parent 7887e66 commit c05fe7e
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/BUTR.CrashReportServer/Controllers/CrashUploadController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using BUTR.CrashReport.Bannerlord;
using BUTR.CrashReport.Bannerlord.Parser;
using BUTR.CrashReport.Bannerlord.Parser;
using BUTR.CrashReport.Models;
using BUTR.CrashReportServer.Contexts;
using BUTR.CrashReportServer.Extensions;
Expand All @@ -18,6 +17,7 @@
using System.Collections.Generic;
using System.Diagnostics.Metrics;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Text.Json;
using System.Text.Json.Serialization;
Expand Down Expand Up @@ -122,7 +122,7 @@ private async Task<IActionResult> UploadJsonAsync(CancellationToken ct)
return Ok($"{_options.BaseUri}/{idEntity.FileId}");

var json = JsonSerializer.Serialize(crashReport, _jsonSerializerOptionsWeb);
var html = CrashReportHtml.AddData(CrashReportHtml.Build(crashReport, logSources), json);
var html = CrashReportHtml.AddData(CrashReportHtml.Build(crashReport, logSources), await CompressJson(crashReport));

await using var compressedHtmlStream = await _gZipCompressor.CompressAsync(html.AsStream(), ct);

Expand All @@ -136,6 +136,17 @@ private async Task<IActionResult> UploadJsonAsync(CancellationToken ct)

return Ok($"{_options.BaseUri}/{idEntity.FileId}");
}

private static async Task<string> CompressJson(CrashReportModel crashReport)
{
using var compressedStream = new MemoryStream();
await using (var compressorStream = new DeflateStream(compressedStream, CompressionLevel.Fastest, true))
{
await JsonSerializer.SerializeAsync(compressorStream, crashReport, _jsonSerializerOptionsWeb);
}
var compressedBytes = compressedStream.ToArray();
return Convert.ToBase64String(compressedBytes);
}

[AllowAnonymous]
[HttpPost("crash-upload.py")]
Expand Down

0 comments on commit c05fe7e

Please sign in to comment.