Added container rebuild flow with real-time logs and updated UI, backend implementation, config options, and container helper API integration.

This commit is contained in:
2026-01-23 16:38:42 +01:00
parent 76a8a72e83
commit e2f344ab4e
11 changed files with 300 additions and 37 deletions

View File

@@ -0,0 +1,67 @@
using System.Text.Json;
using Moonlight.Shared.Http;
using Moonlight.Shared.Http.Events;
namespace Moonlight.Api.Services;
public class ContainerHelperService
{
private readonly IHttpClientFactory HttpClientFactory;
public ContainerHelperService(IHttpClientFactory httpClientFactory)
{
HttpClientFactory = httpClientFactory;
}
public async IAsyncEnumerable<RebuildEvent> RebuildAsync()
{
var options = new JsonSerializerOptions()
{
PropertyNameCaseInsensitive = true
};
options.TypeInfoResolverChain.Add(SerializationContext.Default);
var client = HttpClientFactory.CreateClient("ContainerHelper");
var response = await client.GetAsync("api/rebuild", HttpCompletionOption.ResponseHeadersRead);
if (!response.IsSuccessStatusCode)
{
var responseText = await response.Content.ReadAsStringAsync();
yield return new RebuildEvent()
{
Type = RebuildEventType.Failed,
Data = responseText
};
yield break;
}
await using var responseStream = await response.Content.ReadAsStreamAsync();
using var streamReader = new StreamReader(responseStream);
do
{
var line = await streamReader.ReadLineAsync();
if(line == null)
break;
if(string.IsNullOrWhiteSpace(line))
continue;
var data = line.Trim("data: ");
var deserializedData = JsonSerializer.Deserialize<RebuildEvent>(data, options);
yield return deserializedData;
} while (true);
yield return new RebuildEvent()
{
Type = RebuildEventType.Succeeded,
Data = string.Empty
};
}
}