diff options
| author | JP Dillingham <jp@dillingham.me> | 2026-01-29 18:31:09 -0600 |
|---|---|---|
| committer | JP Dillingham <jp@dillingham.me> | 2026-01-29 18:31:09 -0600 |
| commit | a631b5fbeaaf4e21c0a0a3c266d94d710eb4ffd7 (patch) | |
| tree | c8fd2c979efc0e3bc049e164485caed37565d1ce /src/slskd/Core/API/Controllers | |
| parent | 94c6943c23e6b3c6cb6efb8a8ca45055b9153d58 (diff) | |
| download | slskd-a631b5fbeaaf4e21c0a0a3c266d94d710eb4ffd7.tar.gz | |
use /overlay endpoints
Diffstat (limited to 'src/slskd/Core/API/Controllers')
| -rw-r--r-- | src/slskd/Core/API/Controllers/OptionsController.cs | 33 |
1 files changed, 21 insertions, 12 deletions
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<Options> optionsSnapshot, IStateMutator<State> stateMutator) { - Application = application; OptionsAtStartup = optionsAtStartup; OptionsSnapshot = optionsSnapshot; StateMutator = stateMutator; } - private IApplication Application { get; } private IOptionsSnapshot<Options> OptionsSnapshot { get; } private OptionsAtStartup OptionsAtStartup { get; } private IStateMutator<State> StateMutator { get; } @@ -72,21 +69,21 @@ namespace slskd.Core.API } /// <summary> - /// Patch the application options with new values. + /// Overlay the application options with new values. /// </summary> - /// <param name="patch">The patch to apply.</param> + /// <param name="overlay">The overlay to apply.</param> /// <returns></returns> - [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()); } /// <summary> @@ -120,6 +116,19 @@ namespace slskd.Core.API } /// <summary> + /// Gets the current application option overlay, if one has been applied. + /// </summary> + /// <returns></returns> + [HttpGet] + [Route("overlay")] + [Authorize(Policy = AuthPolicy.Any)] + [ProducesResponseType(typeof(OptionsOverlay), 200)] + public IActionResult GetOverlay() + { + return Ok(Program.ConfigurationOverlay?.Redact()); + } + + /// <summary> /// Gets the debug view of the current application options. /// </summary> /// <returns></returns> |
