Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions ReplayBrowser/Controllers/AccountController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,17 +230,24 @@ [FromQuery] string guid
var historyEntry = archive.CreateEntry("history.json");
using (var entryStream = historyEntry.Open())
{
await JsonSerializer.SerializeAsync(entryStream, user.History);
await JsonSerializer.SerializeAsync(entryStream, user.History, new JsonSerializerOptions()
{
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
ReferenceHandler = ReferenceHandler.IgnoreCycles,
WriteIndented = true
});
}

user.History = [];

var baseEntry = archive.CreateEntry("user.json");
using (var entryStream = baseEntry.Open())
{
await JsonSerializer.SerializeAsync(entryStream, user, new JsonSerializerOptions
await JsonSerializer.SerializeAsync(entryStream, user, new JsonSerializerOptions()
{
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
ReferenceHandler = ReferenceHandler.IgnoreCycles,
WriteIndented = true
});
}
}
Expand All @@ -256,10 +263,11 @@ [FromQuery] string guid
var replayEntry = archive.CreateEntry($"replay-{replay.Id}.json");
using (var entryStream = replayEntry.Open())
{
await JsonSerializer.SerializeAsync(entryStream, replay, new JsonSerializerOptions
await JsonSerializer.SerializeAsync(entryStream, replay, new JsonSerializerOptions()
{
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
ReferenceHandler = ReferenceHandler.IgnoreCycles
ReferenceHandler = ReferenceHandler.IgnoreCycles,
WriteIndented = true
});
}
}
Expand Down Expand Up @@ -424,7 +432,12 @@ public async Task<IActionResult> DownloadAccount()
var historyEntry = archive.CreateEntry("history.json");
using (var entryStream = historyEntry.Open())
{
await JsonSerializer.SerializeAsync(entryStream, user.History);
await JsonSerializer.SerializeAsync(entryStream, user.History, new JsonSerializerOptions()
{
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
ReferenceHandler = ReferenceHandler.IgnoreCycles,
WriteIndented = true
});
}

user.History = [];
Expand All @@ -434,7 +447,9 @@ public async Task<IActionResult> DownloadAccount()
{
await JsonSerializer.SerializeAsync(entryStream, user, new JsonSerializerOptions
{
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
ReferenceHandler = ReferenceHandler.IgnoreCycles,
WriteIndented = true
});
}
}
Expand Down
17 changes: 15 additions & 2 deletions ReplayBrowser/Controllers/ReplayController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json;
using ReplayBrowser.Data;
using ReplayBrowser.Data.Models;
using ReplayBrowser.Helpers;
Expand Down Expand Up @@ -33,13 +34,25 @@ public ReplayController(ReplayDbContext dbContext, AccountService accountService
public async Task<IActionResult> GetReplay(int replayId)
{
var authState = new AuthenticationState(HttpContext.User);
var replay = await _replayHelper.GetReplay(replayId, authState);
var replay = await _replayHelper.GetFullReplay(replayId, authState);
if (replay == null)
{
return NotFound();
}

return Ok(replay);
// Sort replay events by time
if (replay.Events != null)
replay.Events = replay.Events.OrderBy(e => e.Time).ToList();

var settings = new JsonSerializerSettings
{
ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
Formatting = Formatting.Indented,
TypeNameHandling = TypeNameHandling.None,
TypeNameAssemblyFormatHandling = TypeNameAssemblyFormatHandling.Simple
};

return Ok(JsonConvert.SerializeObject(replay, settings));
}

/// <summary>
Expand Down
Loading