From a631b5fbeaaf4e21c0a0a3c266d94d710eb4ffd7 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Thu, 29 Jan 2026 18:31:09 -0600 Subject: use /overlay endpoints --- .../Core/API/Controllers/OptionsController.cs | 33 ++++++++++++++-------- 1 file changed, 21 insertions(+), 12 deletions(-) (limited to 'src/slskd/Core/API/Controllers') diff --git a/src/slskd/Core/API/Controllers/OptionsController.cs b/src/slskd/Core/API/Controllers/OptionsController.cs index 291ae561..bfbb2dd7 100644 --- a/src/slskd/Core/API/Controllers/OptionsController.cs +++ b/src/slskd/Core/API/Controllers/OptionsController.cs @@ -42,18 +42,15 @@ namespace slskd.Core.API public class OptionsController : ControllerBase { public OptionsController( - IApplication application, OptionsAtStartup optionsAtStartup, IOptionsSnapshot optionsSnapshot, IStateMutator stateMutator) { - Application = application; OptionsAtStartup = optionsAtStartup; OptionsSnapshot = optionsSnapshot; StateMutator = stateMutator; } - private IApplication Application { get; } private IOptionsSnapshot OptionsSnapshot { get; } private OptionsAtStartup OptionsAtStartup { get; } private IStateMutator StateMutator { get; } @@ -72,21 +69,21 @@ namespace slskd.Core.API } /// - /// Patch the application options with new values. + /// Overlay the application options with new values. /// - /// The patch to apply. + /// The overlay to apply. /// - [HttpPatch] + [HttpPut("overlay")] [Authorize(Policy = AuthPolicy.Any)] [ProducesResponseType(typeof(Options), 200)] - public IActionResult Patch([FromBody] OptionsOverlay patch) + public IActionResult ApplyOverlay([FromBody] OptionsOverlay overlay) { - if (patch is null) + if (overlay is null) { return NoContent(); } - if (!patch.TryValidate(out var result)) + if (!overlay.TryValidate(out var result)) { var error = Regex.Replace(result.GetResultView().ToString(), @"\s+", " ").Trim(); Logger.Warning("Options patch validation failed: {Message}", error); @@ -95,15 +92,14 @@ namespace slskd.Core.API try { - Program.ApplyConfigurationOverlay(patch); + Program.ApplyConfigurationOverlay(overlay); + return Ok(OptionsSnapshot.Value.Redact()); } catch (Exception ex) { Logger.Error(ex, "Failed to apply options patch: {Message}", ex.Message); return StatusCode(500, $"Failed to apply options patch: {ex.Message}"); } - - return Ok(OptionsSnapshot.Value.Redact()); } /// @@ -119,6 +115,19 @@ namespace slskd.Core.API return Ok(OptionsAtStartup.Redact()); } + /// + /// Gets the current application option overlay, if one has been applied. + /// + /// + [HttpGet] + [Route("overlay")] + [Authorize(Policy = AuthPolicy.Any)] + [ProducesResponseType(typeof(OptionsOverlay), 200)] + public IActionResult GetOverlay() + { + return Ok(Program.ConfigurationOverlay?.Redact()); + } + /// /// Gets the debug view of the current application options. /// -- cgit v1.2.3