From c90c336e70b5bbbcf26361e204a906799e368c9b Mon Sep 17 00:00:00 2001 From: Roger Far Date: Mon, 11 Oct 2021 14:22:45 -0600 Subject: [PATCH] Add aria2 test connection button on the settings. --- client/src/app/settings.service.ts | 7 ++++++ .../src/app/settings/settings.component.html | 23 ++++++++++++++++--- client/src/app/settings/settings.component.ts | 20 ++++++++++++++++ .../Services/Downloaders/Aria2cDownloader.cs | 2 +- server/RdtClient.Service/Services/Settings.cs | 14 +++++++++-- .../Controllers/SettingsController.cs | 15 ++++++++++++ 6 files changed, 75 insertions(+), 6 deletions(-) diff --git a/client/src/app/settings.service.ts b/client/src/app/settings.service.ts index 4824d16..106fa81 100644 --- a/client/src/app/settings.service.ts +++ b/client/src/app/settings.service.ts @@ -33,4 +33,11 @@ export class SettingsService { public testWriteSpeed(): Observable { return this.http.get(`/Api/Settings/TestWriteSpeed`); } + + public testAria2cConnection(url: string, secret: string): Observable<{ version: string }> { + return this.http.post<{ version: string }>(`/Api/Settings/TestAria2cConnection`, { + url, + secret, + }); + } } diff --git a/client/src/app/settings/settings.component.html b/client/src/app/settings/settings.component.html index 6b1d404..52c9473 100644 --- a/client/src/app/settings/settings.component.html +++ b/client/src/app/settings/settings.component.html @@ -146,9 +146,26 @@
-

- The secret of your Aria2c instance. Optional. -

+

The secret of your Aria2c instance. Optional.

+ + + + +
+ Could connect to Aria2 client
+ {{ testAria2cConnectionError }} +
+ +
+ Found Aria2 client version {{ testAria2cConnectionSuccess }}
diff --git a/client/src/app/settings/settings.component.ts b/client/src/app/settings/settings.component.ts index 31d7fbb..921098b 100644 --- a/client/src/app/settings/settings.component.ts +++ b/client/src/app/settings/settings.component.ts @@ -22,6 +22,9 @@ export class SettingsComponent implements OnInit { public testWriteSpeedError: string; public testWriteSpeedSuccess: number; + public testAria2cConnectionError: string = null; + public testAria2cConnectionSuccess: string = null; + public settingLogLevel: string; public settingRealDebridApiKey: string; public settingDownloadPath: string; @@ -203,6 +206,23 @@ export class SettingsComponent implements OnInit { ); } + public testAria2cConnection(): void { + this.saving = true; + this.testAria2cConnectionError = null; + this.testAria2cConnectionSuccess = null; + + this.settingsService.testAria2cConnection(this.aria2cUrl, this.aria2cSecret).subscribe( + (result) => { + this.saving = false; + this.testAria2cConnectionSuccess = result.version; + }, + (err) => { + this.testAria2cConnectionError = err.error; + this.saving = false; + } + ); + } + private getSetting(settings: Setting[], key: string): string { const setting = settings.filter((m) => m.settingId === key); diff --git a/server/RdtClient.Service/Services/Downloaders/Aria2cDownloader.cs b/server/RdtClient.Service/Services/Downloaders/Aria2cDownloader.cs index a909306..ee8e51a 100644 --- a/server/RdtClient.Service/Services/Downloaders/Aria2cDownloader.cs +++ b/server/RdtClient.Service/Services/Downloaders/Aria2cDownloader.cs @@ -33,7 +33,7 @@ namespace RdtClient.Service.Services.Downloaders _timer.Elapsed += OnTimedEvent; - _timer.Interval = 1000; + _timer.Interval = 100; _timer.Enabled = false; } diff --git a/server/RdtClient.Service/Services/Settings.cs b/server/RdtClient.Service/Services/Settings.cs index df44408..1d503ad 100644 --- a/server/RdtClient.Service/Services/Settings.cs +++ b/server/RdtClient.Service/Services/Settings.cs @@ -4,6 +4,7 @@ using System.Diagnostics; using System.IO; using System.Threading; using System.Threading.Tasks; +using Aria2NET; using RdtClient.Data.Data; using RdtClient.Data.Models.Data; using RdtClient.Data.Models.Internal; @@ -78,13 +79,13 @@ namespace RdtClient.Service.Services var downloadClient = new DownloadClient(download, download.Torrent, downloadPath); - downloadClient.Start(Get); + await downloadClient.Start(Get); while (!downloadClient.Finished) { #pragma warning disable CA2016 // Forward the 'CancellationToken' parameter to methods that take one // ReSharper disable once MethodSupportsCancellation - await Task.Delay(1000); + await Task.Delay(10); #pragma warning restore CA2016 // Forward the 'CancellationToken' parameter to methods that take one if (cancellationToken.IsCancellationRequested) @@ -95,6 +96,8 @@ namespace RdtClient.Service.Services if (downloadClient.BytesDone > 1024 * 1024 * 50) { downloadClient.Cancel(); + + break; } } @@ -152,6 +155,13 @@ namespace RdtClient.Service.Services return writeSpeed; } + public async Task GetAria2cVersion(String url, String secret) + { + var client = new Aria2NetClient(url, secret); + + return await client.GetVersion(); + } + public void Clean() { try diff --git a/server/RdtClient.Web/Controllers/SettingsController.cs b/server/RdtClient.Web/Controllers/SettingsController.cs index 3f1ff79..8b4fbea 100644 --- a/server/RdtClient.Web/Controllers/SettingsController.cs +++ b/server/RdtClient.Web/Controllers/SettingsController.cs @@ -82,6 +82,15 @@ namespace RdtClient.Web.Controllers return Ok(writeSpeed); } + + [HttpPost] + [Route("TestAria2cConnection")] + public async Task> TestAria2cConnection([FromBody] SettingsControllerTestAria2cConnectionRequest request) + { + var version = await _settings.GetAria2cVersion(request.Url, request.Secret); + + return Ok(version); + } } public class SettingsControllerUpdateRequest @@ -93,4 +102,10 @@ namespace RdtClient.Web.Controllers { public String Path { get; set; } } + + public class SettingsControllerTestAria2cConnectionRequest + { + public String Url { get; set; } + public String Secret { get; set; } + } } \ No newline at end of file