using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Options; using Moonlight.Api.Configuration; using Moonlight.Api.Services; using Moonlight.Shared.Http.Responses.Admin; namespace Moonlight.Api.Http.Controllers.Admin; [ApiController] [Route("api/admin/ch")] public class ChController : Controller { private readonly ContainerHelperService ContainerHelperService; private readonly IOptions Options; public ChController(ContainerHelperService containerHelperService, IOptions options) { ContainerHelperService = containerHelperService; Options = options; } [HttpGet("status")] public async Task> GetStatusAsync() { if (!Options.Value.IsEnabled) return new ContainerHelperStatusDto(false, false); var status = await ContainerHelperService.CheckConnectionAsync(); return new ContainerHelperStatusDto(true, status); } [HttpPost("rebuild")] public Task RebuildAsync() { var result = ContainerHelperService.RebuildAsync(); return Task.FromResult( TypedResults.ServerSentEvents(result) ); } }