53 lines
1.7 KiB
C#
53 lines
1.7 KiB
C#
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.Extensions.Options;
|
|
using Moonlight.Shared;
|
|
using Moonlight.Shared.Admin.Sys.ContainerHelper;
|
|
|
|
namespace Moonlight.Api.Admin.Sys.ContainerHelper;
|
|
|
|
[ApiController]
|
|
[Route("api/admin/ch")]
|
|
[Authorize(Policy = Permissions.System.Instance)]
|
|
public class ContainerHelperController : Controller
|
|
{
|
|
private readonly ContainerHelperService ContainerHelperService;
|
|
private readonly IOptions<ContainerHelperOptions> Options;
|
|
|
|
public ContainerHelperController(ContainerHelperService containerHelperService,
|
|
IOptions<ContainerHelperOptions> options)
|
|
{
|
|
ContainerHelperService = containerHelperService;
|
|
Options = options;
|
|
}
|
|
|
|
[HttpGet("status")]
|
|
public async Task<ActionResult<ContainerHelperStatusDto>> GetStatusAsync()
|
|
{
|
|
if (!Options.Value.IsEnabled)
|
|
return new ContainerHelperStatusDto(false, false);
|
|
|
|
var status = await ContainerHelperService.CheckConnectionAsync();
|
|
|
|
return new ContainerHelperStatusDto(true, status);
|
|
}
|
|
|
|
[HttpPost("rebuild")]
|
|
public Task<IResult> RebuildAsync([FromBody] RequestRebuildDto request)
|
|
{
|
|
var result = ContainerHelperService.RebuildAsync(request.NoBuildCache);
|
|
var mappedResult = result.Select(ContainerHelperMapper.ToDto);
|
|
|
|
return Task.FromResult<IResult>(
|
|
TypedResults.ServerSentEvents(mappedResult)
|
|
);
|
|
}
|
|
|
|
[HttpPost("version")]
|
|
public async Task<ActionResult> SetVersionAsync([FromBody] SetVersionDto request)
|
|
{
|
|
await ContainerHelperService.SetVersionAsync(request.Version);
|
|
return NoContent();
|
|
}
|
|
} |