Fix false positive Soulseek connection test by checking network state
This commit is contained in:
parent
2c56b23c27
commit
7726e86a78
2 changed files with 15 additions and 4 deletions
|
|
@ -1442,11 +1442,22 @@ class SoulseekClient:
|
||||||
return await self.download(best_result.username, best_result.filename, best_result.size)
|
return await self.download(best_result.username, best_result.filename, best_result.size)
|
||||||
|
|
||||||
async def check_connection(self) -> bool:
|
async def check_connection(self) -> bool:
|
||||||
"""Check if slskd is running and accessible"""
|
"""Check if slskd is running and connected to the Soulseek network"""
|
||||||
if not self.base_url:
|
if not self.base_url:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
# Primary check: server/state tells us if slskd is connected to the Soulseek network
|
||||||
|
state = await self._make_request('GET', 'server/state')
|
||||||
|
if state is not None:
|
||||||
|
is_connected = state.get('isConnected') or state.get('IsConnected', False)
|
||||||
|
is_logged_in = state.get('isLoggedIn') or state.get('IsLoggedIn', False)
|
||||||
|
if not (is_connected and is_logged_in):
|
||||||
|
logger.debug(f"Soulseek not fully connected: isConnected={is_connected}, isLoggedIn={is_logged_in}")
|
||||||
|
return is_connected and is_logged_in
|
||||||
|
|
||||||
|
# Fallback: if server/state endpoint unavailable (older slskd), check API reachability
|
||||||
|
logger.debug("server/state endpoint unavailable, falling back to session check")
|
||||||
response = await self._make_request('GET', 'session')
|
response = await self._make_request('GET', 'session')
|
||||||
return response is not None
|
return response is not None
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
|
||||||
|
|
@ -1733,7 +1733,7 @@ def run_service_test(service, test_config):
|
||||||
if run_async(soulseek_client.check_connection()):
|
if run_async(soulseek_client.check_connection()):
|
||||||
# Success message based on active mode
|
# Success message based on active mode
|
||||||
mode_messages = {
|
mode_messages = {
|
||||||
'soulseek': "Successfully connected to slskd.",
|
'soulseek': "Successfully connected to Soulseek network via slskd.",
|
||||||
'youtube': "YouTube download source ready.",
|
'youtube': "YouTube download source ready.",
|
||||||
'hybrid': "Download sources ready (Hybrid mode)."
|
'hybrid': "Download sources ready (Hybrid mode)."
|
||||||
}
|
}
|
||||||
|
|
@ -1742,7 +1742,7 @@ def run_service_test(service, test_config):
|
||||||
else:
|
else:
|
||||||
# Failure message based on active mode
|
# Failure message based on active mode
|
||||||
mode_errors = {
|
mode_errors = {
|
||||||
'soulseek': "Could not connect to slskd. Check URL and API Key.",
|
'soulseek': "slskd is not connected to the Soulseek network. Check slskd status and credentials.",
|
||||||
'youtube': "YouTube download source not available.",
|
'youtube': "YouTube download source not available.",
|
||||||
'hybrid': "Could not connect to download sources. Check configuration."
|
'hybrid': "Could not connect to download sources. Check configuration."
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue