From 4eac674d0996966913622194407a846d6f47ab93 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Wed, 15 Sep 2021 08:22:22 -0500 Subject: use SoulseekClient directly --- .../Management/API/Controllers/ServerController.cs | 28 +++++++++++++--------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'src/slskd/Application/Management/API/Controllers/ServerController.cs') diff --git a/src/slskd/Application/Management/API/Controllers/ServerController.cs b/src/slskd/Application/Management/API/Controllers/ServerController.cs index f929b46e..e3199d78 100644 --- a/src/slskd/Application/Management/API/Controllers/ServerController.cs +++ b/src/slskd/Application/Management/API/Controllers/ServerController.cs @@ -15,11 +15,14 @@ // along with this program. If not, see https://www.gnu.org/licenses/. // +using Microsoft.Extensions.Options; + namespace slskd.Management.API { using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; + using Soulseek; /// /// Server. @@ -32,15 +35,18 @@ namespace slskd.Management.API public class ServerController : ControllerBase { public ServerController( - IApplication application, - IStateMonitor applicationStateMonitor) + ISoulseekClient soulseekClient, + IOptionsSnapshot optionsSnapshot, + IStateSnapshot stateSnapshot) { - Application = application; - ApplicationStateMonitor = applicationStateMonitor; + Client = soulseekClient; + OptionsSnapshot = optionsSnapshot; + StateSnapshot = stateSnapshot; } - private IApplication Application { get; } - private IStateMonitor ApplicationStateMonitor { get; } + private ISoulseekClient Client { get; } + private IOptionsSnapshot OptionsSnapshot { get; } + private IStateSnapshot StateSnapshot { get; } /// /// Connects the client. @@ -53,9 +59,9 @@ namespace slskd.Management.API [ProducesResponseType(403)] public async Task Connect() { - if (!ApplicationStateMonitor.CurrentValue.Server.IsConnected) + if (!Client.State.HasFlag(SoulseekClientStates.Connected)) { - await Application.ConnectAsync(); + await Client.ConnectAsync(OptionsSnapshot.Value.Soulseek.Username, OptionsSnapshot.Value.Soulseek.Password); } return Ok(); @@ -73,9 +79,9 @@ namespace slskd.Management.API [ProducesResponseType(403)] public IActionResult Disconnect([FromBody] string message) { - if (ApplicationStateMonitor.CurrentValue.Server.IsConnected) + if (Client.State.HasFlag(SoulseekClientStates.Connected)) { - Application.Disconnect(message); + Client.Disconnect(message, new IntentionalDisconnectException(message)); } return NoContent(); @@ -93,7 +99,7 @@ namespace slskd.Management.API [ProducesResponseType(403)] public IActionResult Get() { - return Ok(ApplicationStateMonitor.CurrentValue.Server); + return Ok(StateSnapshot.Value.Server); } } } \ No newline at end of file -- cgit v1.2.3