mirror of
https://github.com/JogmansonReal/Radicade.git
synced 2026-10-26 07:29:00 -07:00
Radicade Public Code
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user