fixed Deluge failing when WebUI is not connected
This commit is contained in:
@@ -0,0 +1,12 @@
|
|||||||
|
namespace Common.Exceptions;
|
||||||
|
|
||||||
|
public class FatalException : Exception
|
||||||
|
{
|
||||||
|
public FatalException()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public FatalException(string message) : base(message)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
using Common.Configuration;
|
using Common.Configuration;
|
||||||
using Common.Configuration.DownloadClient;
|
using Common.Configuration.DownloadClient;
|
||||||
|
using Common.Exceptions;
|
||||||
using Domain.Models.Deluge.Exceptions;
|
using Domain.Models.Deluge.Exceptions;
|
||||||
using Domain.Models.Deluge.Request;
|
using Domain.Models.Deluge.Request;
|
||||||
using Domain.Models.Deluge.Response;
|
using Domain.Models.Deluge.Response;
|
||||||
@@ -43,9 +44,23 @@ public sealed class DelugeClient
|
|||||||
return await SendRequest<bool>("auth.login", _config.Password);
|
return await SendRequest<bool>("auth.login", _config.Password);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task ListMethodsAsync()
|
public async Task<bool> IsConnected()
|
||||||
{
|
{
|
||||||
await SendRequest<object>("system.listMethods");
|
return await SendRequest<bool>("web.connected");
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<bool> Connect()
|
||||||
|
{
|
||||||
|
string? firstHost = await GetHost();
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(firstHost))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var result = await SendRequest<List<string>?>("web.connect", firstHost);
|
||||||
|
|
||||||
|
return result?.Count > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<bool> Logout()
|
public async Task<bool> Logout()
|
||||||
@@ -53,6 +68,18 @@ public sealed class DelugeClient
|
|||||||
return await SendRequest<bool>("auth.delete_session");
|
return await SendRequest<bool>("auth.delete_session");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<string?> GetHost()
|
||||||
|
{
|
||||||
|
var hosts = await SendRequest<List<List<string>?>?>("web.get_hosts");
|
||||||
|
|
||||||
|
if (hosts?.Count > 1)
|
||||||
|
{
|
||||||
|
throw new FatalException("multiple Deluge hosts found - please connect to only one host");
|
||||||
|
}
|
||||||
|
|
||||||
|
return hosts?.FirstOrDefault()?.FirstOrDefault();
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<List<DelugeTorrent>> ListTorrents(Dictionary<string, string>? filters = null)
|
public async Task<List<DelugeTorrent>> ListTorrents(Dictionary<string, string>? filters = null)
|
||||||
{
|
{
|
||||||
filters ??= new Dictionary<string, string>();
|
filters ??= new Dictionary<string, string>();
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ using Common.Configuration.ContentBlocker;
|
|||||||
using Common.Configuration.DownloadCleaner;
|
using Common.Configuration.DownloadCleaner;
|
||||||
using Common.Configuration.DownloadClient;
|
using Common.Configuration.DownloadClient;
|
||||||
using Common.Configuration.QueueCleaner;
|
using Common.Configuration.QueueCleaner;
|
||||||
|
using Common.Exceptions;
|
||||||
using Domain.Enums;
|
using Domain.Enums;
|
||||||
using Domain.Models.Deluge.Response;
|
using Domain.Models.Deluge.Response;
|
||||||
using Infrastructure.Extensions;
|
using Infrastructure.Extensions;
|
||||||
@@ -49,7 +50,11 @@ public class DelugeService : DownloadService, IDelugeService
|
|||||||
public override async Task LoginAsync()
|
public override async Task LoginAsync()
|
||||||
{
|
{
|
||||||
await _client.LoginAsync();
|
await _client.LoginAsync();
|
||||||
await _client.ListMethodsAsync();
|
|
||||||
|
if (!await _client.IsConnected() && !await _client.Connect())
|
||||||
|
{
|
||||||
|
throw new FatalException("Deluge WebUI is not connected to the daemon");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
|
|||||||
Reference in New Issue
Block a user