Fixed previewer: first document refresh sometimes does not work

This commit is contained in:
MarcinZiabek
2022-04-02 00:23:58 +02:00
parent 9be497ee41
commit e27585a504
+15 -3
View File
@@ -11,7 +11,7 @@ class CommunicationService
{
public static CommunicationService Instance { get; } = new ();
public event Action<ICollection<PreviewPage>> OnDocumentRefreshed;
public event Action<ICollection<PreviewPage>>? OnDocumentRefreshed;
private WebApplication? Application { get; set; }
@@ -31,8 +31,8 @@ class CommunicationService
builder.Services.AddLogging(x => x.ClearProviders());
Application = builder.Build();
Application.MapGet("ping", () => Results.Ok());
Application.MapGet("version", () => Results.Json(GetType().Assembly.GetName().Version));
Application.MapGet("ping", HandlePing);
Application.MapGet("version", HandleVersion);
Application.MapPost("update/preview", HandleUpdatePreview);
return Application.RunAsync($"http://localhost:{port}/");
@@ -44,6 +44,18 @@ class CommunicationService
await Application.DisposeAsync();
}
private async Task<IResult> HandlePing()
{
return OnDocumentRefreshed == null
? Results.StatusCode(StatusCodes.Status503ServiceUnavailable)
: Results.Ok();
}
private async Task<IResult> HandleVersion()
{
return Results.Json(GetType().Assembly.GetName().Version);
}
private async Task<IResult> HandleUpdatePreview(HttpRequest request)
{
var command = JsonSerializer.Deserialize<DocumentSnapshot>(request.Form["command"], JsonSerializerOptions);