Renamed SharedSerializationContext to SerializationContext. Added error handling and no build cache functionality

This commit is contained in:
2026-01-29 13:59:24 +01:00
parent 8181404f0c
commit 660319afec
10 changed files with 109 additions and 37 deletions

View File

@@ -1,4 +1,5 @@
using System.Net.Http.Json;
using System.Net.Http.Headers;
using System.Net.Http.Json;
using System.Text.Json;
using Moonlight.Api.Http.Services.ContainerHelper;
using Moonlight.Api.Http.Services.ContainerHelper.Requests;
@@ -32,11 +33,22 @@ public class ContainerHelperService
}
}
public async IAsyncEnumerable<RebuildEventDto> RebuildAsync()
public async IAsyncEnumerable<RebuildEventDto> RebuildAsync(bool noBuildCache)
{
var client = HttpClientFactory.CreateClient("ContainerHelper");
var response = await client.GetAsync("api/rebuild", HttpCompletionOption.ResponseHeadersRead);
var request = new HttpRequestMessage(HttpMethod.Post, "api/rebuild");
request.Content = JsonContent.Create(
new RequestRebuildDto(noBuildCache),
null,
SerializationContext.TunedOptions
);
var response = await client.SendAsync(
request,
HttpCompletionOption.ResponseHeadersRead
);
if (!response.IsSuccessStatusCode)
{
@@ -90,15 +102,16 @@ public class ContainerHelperService
new SetVersionDto(version),
SerializationContext.TunedOptions
);
if(response.IsSuccessStatusCode)
if (response.IsSuccessStatusCode)
return;
var problemDetails = await response.Content.ReadFromJsonAsync<ProblemDetails>(SerializationContext.TunedOptions);
if(problemDetails == null)
var problemDetails =
await response.Content.ReadFromJsonAsync<ProblemDetails>(SerializationContext.TunedOptions);
if (problemDetails == null)
throw new HttpRequestException($"Failed to set version: {response.ReasonPhrase}");
throw new HttpRequestException($"Failed to set version: {problemDetails.Detail ?? problemDetails.Title}");
}
}