Add download client customizable url base (#43)
This commit is contained in:
@@ -214,15 +214,18 @@ services:
|
|||||||
# OR
|
# OR
|
||||||
# - DOWNLOAD_CLIENT=qBittorrent
|
# - DOWNLOAD_CLIENT=qBittorrent
|
||||||
# - QBITTORRENT__URL=http://localhost:8080
|
# - QBITTORRENT__URL=http://localhost:8080
|
||||||
|
# - QBITTORRENT__URL_BASE=myCustomPath
|
||||||
# - QBITTORRENT__USERNAME=user
|
# - QBITTORRENT__USERNAME=user
|
||||||
# - QBITTORRENT__PASSWORD=pass
|
# - QBITTORRENT__PASSWORD=pass
|
||||||
# OR
|
# OR
|
||||||
# - DOWNLOAD_CLIENT=deluge
|
# - DOWNLOAD_CLIENT=deluge
|
||||||
|
# - DELUGE__URL_BASE=myCustomPath
|
||||||
# - DELUGE__URL=http://localhost:8112
|
# - DELUGE__URL=http://localhost:8112
|
||||||
# - DELUGE__PASSWORD=testing
|
# - DELUGE__PASSWORD=testing
|
||||||
# OR
|
# OR
|
||||||
# - DOWNLOAD_CLIENT=transmission
|
# - DOWNLOAD_CLIENT=transmission
|
||||||
# - TRANSMISSION__URL=http://localhost:9091
|
# - TRANSMISSION__URL=http://localhost:9091
|
||||||
|
# - TRANSMISSION__URL_BASE=myCustomPath
|
||||||
# - TRANSMISSION__USERNAME=test
|
# - TRANSMISSION__USERNAME=test
|
||||||
# - TRANSMISSION__PASSWORD=testing
|
# - TRANSMISSION__PASSWORD=testing
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Common.Exceptions;
|
using Common.Exceptions;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
|
||||||
namespace Common.Configuration.DownloadClient;
|
namespace Common.Configuration.DownloadClient;
|
||||||
|
|
||||||
@@ -8,6 +9,9 @@ public sealed record DelugeConfig : IConfig
|
|||||||
|
|
||||||
public Uri? Url { get; init; }
|
public Uri? Url { get; init; }
|
||||||
|
|
||||||
|
[ConfigurationKeyName("URL_BASE")]
|
||||||
|
public string UrlBase { get; init; } = string.Empty;
|
||||||
|
|
||||||
public string? Password { get; init; }
|
public string? Password { get; init; }
|
||||||
|
|
||||||
public void Validate()
|
public void Validate()
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Common.Exceptions;
|
using Common.Exceptions;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
|
||||||
namespace Common.Configuration.DownloadClient;
|
namespace Common.Configuration.DownloadClient;
|
||||||
|
|
||||||
@@ -8,6 +9,9 @@ public sealed class QBitConfig : IConfig
|
|||||||
|
|
||||||
public Uri? Url { get; init; }
|
public Uri? Url { get; init; }
|
||||||
|
|
||||||
|
[ConfigurationKeyName("URL_BASE")]
|
||||||
|
public string UrlBase { get; init; } = string.Empty;
|
||||||
|
|
||||||
public string? Username { get; init; }
|
public string? Username { get; init; }
|
||||||
|
|
||||||
public string? Password { get; init; }
|
public string? Password { get; init; }
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Common.Exceptions;
|
using Common.Exceptions;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
|
||||||
namespace Common.Configuration.DownloadClient;
|
namespace Common.Configuration.DownloadClient;
|
||||||
|
|
||||||
@@ -8,6 +9,9 @@ public record TransmissionConfig : IConfig
|
|||||||
|
|
||||||
public Uri? Url { get; init; }
|
public Uri? Url { get; init; }
|
||||||
|
|
||||||
|
[ConfigurationKeyName("URL_BASE")]
|
||||||
|
public string UrlBase { get; init; } = "transmission";
|
||||||
|
|
||||||
public string? Username { get; init; }
|
public string? Username { get; init; }
|
||||||
|
|
||||||
public string? Password { get; init; }
|
public string? Password { get; init; }
|
||||||
|
|||||||
@@ -52,15 +52,18 @@
|
|||||||
"DOWNLOAD_CLIENT": "qbittorrent",
|
"DOWNLOAD_CLIENT": "qbittorrent",
|
||||||
"qBittorrent": {
|
"qBittorrent": {
|
||||||
"Url": "http://localhost:8080",
|
"Url": "http://localhost:8080",
|
||||||
|
"URL_BASE": "",
|
||||||
"Username": "test",
|
"Username": "test",
|
||||||
"Password": "testing"
|
"Password": "testing"
|
||||||
},
|
},
|
||||||
"Deluge": {
|
"Deluge": {
|
||||||
"Url": "http://localhost:8112",
|
"Url": "http://localhost:8112",
|
||||||
|
"URL_BASE": "",
|
||||||
"Password": "testing"
|
"Password": "testing"
|
||||||
},
|
},
|
||||||
"Transmission": {
|
"Transmission": {
|
||||||
"Url": "http://localhost:9091",
|
"Url": "http://localhost:9091",
|
||||||
|
"URL_BASE": "transmission",
|
||||||
"Username": "test",
|
"Username": "test",
|
||||||
"Password": "testing"
|
"Password": "testing"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -42,15 +42,18 @@
|
|||||||
"DOWNLOAD_CLIENT": "none",
|
"DOWNLOAD_CLIENT": "none",
|
||||||
"qBittorrent": {
|
"qBittorrent": {
|
||||||
"Url": "http://localhost:8080",
|
"Url": "http://localhost:8080",
|
||||||
|
"URL_BASE": "",
|
||||||
"Username": "",
|
"Username": "",
|
||||||
"Password": ""
|
"Password": ""
|
||||||
},
|
},
|
||||||
"Deluge": {
|
"Deluge": {
|
||||||
"Url": "http://localhost:8112",
|
"Url": "http://localhost:8112",
|
||||||
|
"URL_BASE": "",
|
||||||
"Password": "testing"
|
"Password": "testing"
|
||||||
},
|
},
|
||||||
"Transmission": {
|
"Transmission": {
|
||||||
"Url": "http://localhost:9091",
|
"Url": "http://localhost:9091",
|
||||||
|
"URL_BASE": "transmission",
|
||||||
"Username": "test",
|
"Username": "test",
|
||||||
"Password": "testing"
|
"Password": "testing"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ public sealed class DelugeClient
|
|||||||
public DelugeClient(IOptions<DelugeConfig> config, IHttpClientFactory httpClientFactory)
|
public DelugeClient(IOptions<DelugeConfig> config, IHttpClientFactory httpClientFactory)
|
||||||
{
|
{
|
||||||
_config = config.Value;
|
_config = config.Value;
|
||||||
|
_config.Validate();
|
||||||
_httpClient = httpClientFactory.CreateClient(nameof(DelugeService));
|
_httpClient = httpClientFactory.CreateClient(nameof(DelugeService));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,8 +122,12 @@ public sealed class DelugeClient
|
|||||||
{
|
{
|
||||||
StringContent content = new StringContent(json);
|
StringContent content = new StringContent(json);
|
||||||
content.Headers.ContentType = new MediaTypeWithQualityHeaderValue("application/json");
|
content.Headers.ContentType = new MediaTypeWithQualityHeaderValue("application/json");
|
||||||
|
|
||||||
var responseMessage = await _httpClient.PostAsync(new Uri(_config.Url, "/json"), content);
|
UriBuilder uriBuilder = new(_config.Url);
|
||||||
|
uriBuilder.Path = string.IsNullOrEmpty(_config.UrlBase)
|
||||||
|
? $"{uriBuilder.Path.TrimEnd('/')}/json"
|
||||||
|
: $"{uriBuilder.Path.TrimEnd('/')}/{_config.UrlBase.TrimStart('/').TrimEnd('/')}/json";
|
||||||
|
var responseMessage = await _httpClient.PostAsync(uriBuilder.Uri, content);
|
||||||
responseMessage.EnsureSuccessStatusCode();
|
responseMessage.EnsureSuccessStatusCode();
|
||||||
|
|
||||||
var responseJson = await responseMessage.Content.ReadAsStringAsync();
|
var responseJson = await responseMessage.Content.ReadAsStringAsync();
|
||||||
|
|||||||
@@ -45,7 +45,11 @@ public class QBitService : DownloadService, IQBitService
|
|||||||
{
|
{
|
||||||
_config = config.Value;
|
_config = config.Value;
|
||||||
_config.Validate();
|
_config.Validate();
|
||||||
_client = new(httpClientFactory.CreateClient(Constants.HttpClientWithRetryName), _config.Url);
|
UriBuilder uriBuilder = new(_config.Url);
|
||||||
|
uriBuilder.Path = string.IsNullOrEmpty(_config.UrlBase)
|
||||||
|
? uriBuilder.Path
|
||||||
|
: $"{uriBuilder.Path.TrimEnd('/')}/{_config.UrlBase.TrimStart('/')}";
|
||||||
|
_client = new(httpClientFactory.CreateClient(Constants.HttpClientWithRetryName), uriBuilder.Uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task LoginAsync()
|
public override async Task LoginAsync()
|
||||||
|
|||||||
@@ -64,9 +64,13 @@ public class TransmissionService : DownloadService, ITransmissionService
|
|||||||
{
|
{
|
||||||
_config = config.Value;
|
_config = config.Value;
|
||||||
_config.Validate();
|
_config.Validate();
|
||||||
|
UriBuilder uriBuilder = new(_config.Url);
|
||||||
|
uriBuilder.Path = string.IsNullOrEmpty(_config.UrlBase)
|
||||||
|
? $"{uriBuilder.Path.TrimEnd('/')}/rpc"
|
||||||
|
: $"{uriBuilder.Path.TrimEnd('/')}/{_config.UrlBase.TrimStart('/').TrimEnd('/')}/rpc";
|
||||||
_client = new(
|
_client = new(
|
||||||
httpClientFactory.CreateClient(Constants.HttpClientWithRetryName),
|
httpClientFactory.CreateClient(Constants.HttpClientWithRetryName),
|
||||||
new Uri(_config.Url, "/transmission/rpc").ToString(),
|
uriBuilder.Uri.ToString(),
|
||||||
login: _config.Username,
|
login: _config.Username,
|
||||||
password: _config.Password
|
password: _config.Password
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -378,6 +378,12 @@
|
|||||||
- Default: `http://localhost:8080`.
|
- Default: `http://localhost:8080`.
|
||||||
- Required: No.
|
- Required: No.
|
||||||
|
|
||||||
|
#### **`QBITTORRENT__URL_BASE`**
|
||||||
|
- Adds a prefix to the qBittorrent url, such as `[QBITTORRENT__URL]/[QBITTORRENT__URL_BASE]/api`.
|
||||||
|
- Type: String.
|
||||||
|
- Default: Empty.
|
||||||
|
- Required: No.
|
||||||
|
|
||||||
#### **`QBITTORRENT__USERNAME`**
|
#### **`QBITTORRENT__USERNAME`**
|
||||||
- Username for qBittorrent authentication.
|
- Username for qBittorrent authentication.
|
||||||
- Type: String.
|
- Type: String.
|
||||||
@@ -396,6 +402,12 @@
|
|||||||
- Default: `http://localhost:8112`.
|
- Default: `http://localhost:8112`.
|
||||||
- Required: No.
|
- Required: No.
|
||||||
|
|
||||||
|
#### **`DELUGE__URL_BASE`**
|
||||||
|
- Adds a prefix to the deluge json url, such as `[DELUGE__URL]/[DELUGE__URL_BASE]/json`.
|
||||||
|
- Type: String.
|
||||||
|
- Default: Empty.
|
||||||
|
- Required: No.
|
||||||
|
|
||||||
#### **`DELUGE__PASSWORD`**
|
#### **`DELUGE__PASSWORD`**
|
||||||
- Password for Deluge authentication.
|
- Password for Deluge authentication.
|
||||||
- Type: String.
|
- Type: String.
|
||||||
@@ -408,6 +420,12 @@
|
|||||||
- Default: `http://localhost:9091`.
|
- Default: `http://localhost:9091`.
|
||||||
- Required: No.
|
- Required: No.
|
||||||
|
|
||||||
|
#### **`TRANSMISSION__URL_BASE`**
|
||||||
|
- Adds a prefix to the Transmission rpc url, such as `[TRANSMISSION__URL]/[TRANSMISSION__URL_BASE]/rpc`.
|
||||||
|
- Type: String.
|
||||||
|
- Default: `transmission`.
|
||||||
|
- Required: No.
|
||||||
|
|
||||||
#### **`TRANSMISSION__USERNAME`**
|
#### **`TRANSMISSION__USERNAME`**
|
||||||
- Username for Transmission authentication.
|
- Username for Transmission authentication.
|
||||||
- Type: String.
|
- Type: String.
|
||||||
|
|||||||
Reference in New Issue
Block a user