From 8859b9a6c82b1490349f7ffb4f6699b502384f8a Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Tue, 27 Jan 2026 19:48:25 -0600 Subject: call it an overlay --- src/slskd/Common/Validation/Extensions.cs | 6 +- .../Core/API/Controllers/OptionsController.cs | 4 +- src/slskd/Core/OptionsOverlay.cs | 66 +++++++++++++++++++++ src/slskd/Core/OptionsPatch.cs | 69 ---------------------- 4 files changed, 71 insertions(+), 74 deletions(-) create mode 100644 src/slskd/Core/OptionsOverlay.cs delete mode 100644 src/slskd/Core/OptionsPatch.cs (limited to 'src') diff --git a/src/slskd/Common/Validation/Extensions.cs b/src/slskd/Common/Validation/Extensions.cs index 6233d53b..87d83965 100644 --- a/src/slskd/Common/Validation/Extensions.cs +++ b/src/slskd/Common/Validation/Extensions.cs @@ -48,15 +48,15 @@ namespace slskd.Validation /// /// Validates options. /// - /// The options patch instance to validate. + /// The options overlay instance to validate. /// The result of the validation, if invalid. /// A value indicating whether the instance is valid. - public static bool TryValidate(this OptionsPatch patch, out CompositeValidationResult result) + public static bool TryValidate(this OptionsOverlay overlay, out CompositeValidationResult result) { result = null; var results = new List(); - if (!Validator.TryValidateObject(patch, new ValidationContext(patch), results, true)) + if (!Validator.TryValidateObject(overlay, new ValidationContext(overlay), results, true)) { result = new CompositeValidationResult("Invalid configuration", results); return false; diff --git a/src/slskd/Core/API/Controllers/OptionsController.cs b/src/slskd/Core/API/Controllers/OptionsController.cs index f14acc39..291ae561 100644 --- a/src/slskd/Core/API/Controllers/OptionsController.cs +++ b/src/slskd/Core/API/Controllers/OptionsController.cs @@ -79,7 +79,7 @@ namespace slskd.Core.API [HttpPatch] [Authorize(Policy = AuthPolicy.Any)] [ProducesResponseType(typeof(Options), 200)] - public IActionResult Patch([FromBody] OptionsPatch patch) + public IActionResult Patch([FromBody] OptionsOverlay patch) { if (patch is null) { @@ -95,7 +95,7 @@ namespace slskd.Core.API try { - Application.ApplyOptionsPatchAsync(patch); + Program.ApplyConfigurationOverlay(patch); } catch (Exception ex) { diff --git a/src/slskd/Core/OptionsOverlay.cs b/src/slskd/Core/OptionsOverlay.cs new file mode 100644 index 00000000..faea4ea7 --- /dev/null +++ b/src/slskd/Core/OptionsOverlay.cs @@ -0,0 +1,66 @@ +// +// Copyright (c) slskd Team. All rights reserved. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published +// by the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see https://www.gnu.org/licenses/. +// +namespace slskd +{ + using System; + using System.ComponentModel.DataAnnotations; + using slskd.Validation; + + /// + /// Volatile run-time overlay for application . + /// + /// + /// + /// The values specified in this overlay are applied at run-time only, are volatile (lost when the application restarts), + /// and take precedence over all other options, regardless of which method was used to define them. + /// + /// + /// Only options that can be applied while the application is running can be overlaid, given the nature of how + /// an overlay is applied. + /// + /// + /// Every property in this class must be nullable, and must have a null default value; the application + /// selectively applies the patch overlay only information explicitly supplied. + /// + /// + public class OptionsOverlay + { + /// + /// Gets options for the Soulseek client. + /// + [Validate] + public SoulseekOptionsPatch Soulseek { get; init; } = null; + + /// + /// Soulseek client options. + /// + public class SoulseekOptionsPatch + { + /// + /// Gets the local IP address on which to listen for incoming connections. + /// + [IPAddress] + public string ListenIpAddress { get; init; } = null; + + /// + /// Gets the port on which to listen for incoming connections. + /// + [Range(1024, 65535)] + public int? ListenPort { get; init; } = null; + } + } +} \ No newline at end of file diff --git a/src/slskd/Core/OptionsPatch.cs b/src/slskd/Core/OptionsPatch.cs deleted file mode 100644 index 6eee75e3..00000000 --- a/src/slskd/Core/OptionsPatch.cs +++ /dev/null @@ -1,69 +0,0 @@ -// -// Copyright (c) slskd Team. All rights reserved. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published -// by the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see https://www.gnu.org/licenses/. -// -namespace slskd -{ - using System; - using System.ComponentModel.DataAnnotations; - using slskd.Validation; - - /// - /// Run-time patch for application . - /// - /// - /// - /// The values specified in this patch are applied at run-time only, are volatile (lost when the application restarts), - /// and take precedence over all other options, regardless of which method was used to define them. - /// - /// - /// Only options that can be applied while the application is running can be patched, given the nature of how - /// a patch is applied. - /// - /// - /// Every property in this class must be nullable, and must have a null default value; the application - /// selectively applies the patch using only information explicitly supplied. - /// - /// - public class OptionsPatch - { - public static OptionsPatch Current { get; private set; } = new(); - - [Validate] - public SoulseekOptionsPatch Soulseek { get; init; } = null; - - public static void SetCurrent(OptionsPatch patch) => Current = patch; - - /// - /// Soulseek client options. - /// - public class SoulseekOptionsPatch - { - /// - /// Gets the local IP address on which to listen for incoming connections. - /// - [IPAddress] -#pragma warning disable CS8632 // The annotation for nullable reference types should only be used in code within a '#nullable' annotations context. - public string? ListenIpAddress { get; init; } = null; -#pragma warning restore CS8632 // The annotation for nullable reference types should only be used in code within a '#nullable' annotations context. - - /// - /// Gets the port on which to listen for incoming connections. - /// - [Range(1024, 65535)] - public int? ListenPort { get; init; } = null; - } - } -} \ No newline at end of file -- cgit v1.2.3