mirror of
https://github.com/JogmansonReal/Radicade.git
synced 2026-10-25 23:18:56 -07:00
57 lines
1.4 KiB
C#
57 lines
1.4 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Cors;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using RadicadeServer.DB;
|
|
using RadicadeServer.RecNet.Config;
|
|
using RadicadeServer.Utils;
|
|
|
|
namespace RadicadeServer.Admin
|
|
{
|
|
[Route("admin/config")]
|
|
[EnableCors("AdminPanel")]
|
|
public class AdminConfigAPI(RecDBContext db) : Controller
|
|
{
|
|
private Task<IActionResult?> RejectInvalidKey(string key)
|
|
{
|
|
return Task.FromResult<IActionResult?>(key.IsAdminKey() ? null : Unauthorized("Invalid secret"));
|
|
}
|
|
|
|
[HttpGet("forcerefresh")]
|
|
public async Task<IActionResult> ForceRefresh([FromQuery] string key)
|
|
{
|
|
var rejection = await RejectInvalidKey(key);
|
|
if (rejection != null) return rejection;
|
|
|
|
MainConfig? config = await db.Config.FirstOrDefaultAsync();
|
|
if (config == null) return StatusCode(500);
|
|
|
|
bool didChanges = false;
|
|
|
|
if (config.ExpectingReload)
|
|
{
|
|
didChanges = true;
|
|
config.SetAsActive();
|
|
config.ExpectingReload = false;
|
|
}
|
|
|
|
if (config.RefreshConfig(true))
|
|
didChanges = true;
|
|
|
|
if (didChanges)
|
|
await db.SaveChangesAsync();
|
|
|
|
return Ok(config?.ToActualConfig());
|
|
}
|
|
|
|
[HttpGet("full")]
|
|
public async Task<IActionResult> GetFullConfig([FromQuery] string key)
|
|
{
|
|
var rejection = await RejectInvalidKey(key);
|
|
if (rejection != null) return rejection;
|
|
|
|
MainConfig? config = await db.Config.FirstOrDefaultAsync();
|
|
return Ok(config);
|
|
}
|
|
}
|
|
}
|