From 7d302ce2a65bac34f0795ce5eafb3e06b746872d Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Fri, 11 Jul 2025 17:52:57 -0500 Subject: return 205/ResetContent if retry loop is restarted by API call --- src/slskd/Core/API/Controllers/ServerController.cs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'src/slskd/Core/API') diff --git a/src/slskd/Core/API/Controllers/ServerController.cs b/src/slskd/Core/API/Controllers/ServerController.cs index aceaeec9..da777b02 100644 --- a/src/slskd/Core/API/Controllers/ServerController.cs +++ b/src/slskd/Core/API/Controllers/ServerController.cs @@ -21,6 +21,7 @@ namespace slskd.Core.API { using Asp.Versioning; using Microsoft.AspNetCore.Authorization; + using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Soulseek; @@ -36,7 +37,7 @@ namespace slskd.Core.API { public ServerController( ISoulseekClient soulseekClient, - IConnectionWatchdog connectionWatchdog, + ConnectionWatchdog connectionWatchdog, IOptionsSnapshot optionsSnapshot, IStateSnapshot stateSnapshot) { @@ -47,7 +48,7 @@ namespace slskd.Core.API } private ISoulseekClient Client { get; } - private IConnectionWatchdog ConnectionWatchdog { get; } + private ConnectionWatchdog ConnectionWatchdog { get; } private IOptionsSnapshot OptionsSnapshot { get; } private IStateSnapshot StateSnapshot { get; } @@ -59,6 +60,7 @@ namespace slskd.Core.API [Route("")] [Authorize(Policy = AuthPolicy.Any)] [ProducesResponseType(200)] + [ProducesResponseType(StatusCodes.Status205ResetContent)] [ProducesResponseType(403)] public IActionResult Connect() { @@ -67,10 +69,19 @@ namespace slskd.Core.API return Forbid(); } - // we use the watchdog here so that we get the correct auto-reconnect behavior + // if the watchdog is already enabled, we're already attempting to connect. the user might have changed something + // or perhaps is just being impatient; either way, restart the retry loop so they can see results faster + // remember, we may be in a ~5 minute delay at this moment + if (ConnectionWatchdog.IsEnabled) + { + ConnectionWatchdog.Restart(); + return StatusCode(StatusCodes.Status205ResetContent); + } + if (!ConnectionWatchdog.IsEnabled) { ConnectionWatchdog.Start(); + return Ok(); } return Ok(); -- cgit v1.2.3