Add aria2 test connection button on the settings.

This commit is contained in:
Roger Far 2021-10-11 14:22:45 -06:00
parent ae41865bb2
commit c90c336e70
6 changed files with 75 additions and 6 deletions

View file

@ -33,4 +33,11 @@ export class SettingsService {
public testWriteSpeed(): Observable<number> { public testWriteSpeed(): Observable<number> {
return this.http.get<number>(`/Api/Settings/TestWriteSpeed`); return this.http.get<number>(`/Api/Settings/TestWriteSpeed`);
} }
public testAria2cConnection(url: string, secret: string): Observable<{ version: string }> {
return this.http.post<{ version: string }>(`/Api/Settings/TestAria2cConnection`, {
url,
secret,
});
}
} }

View file

@ -146,9 +146,26 @@
<div class="control"> <div class="control">
<input class="input" type="text" maxlength="1000" [(ngModel)]="aria2cSecret" /> <input class="input" type="text" maxlength="1000" [(ngModel)]="aria2cSecret" />
</div> </div>
<p class="help"> <p class="help">The secret of your Aria2c instance. Optional.</p>
The secret of your Aria2c instance. Optional. </div>
</p>
<button
class="button is-warning"
(click)="testAria2cConnection()"
[disabled]="saving"
[ngClass]="{ 'is-loading': saving }"
*ngIf="settingDownloadClient === 'Aria2c'"
>
Test aria2 connection
</button>
<div class="notification is-danger is-light" *ngIf="testAria2cConnectionError">
Could connect to Aria2 client<br />
{{ testAria2cConnectionError }}
</div>
<div class="notification is-success is-light" *ngIf="testAria2cConnectionSuccess">
Found Aria2 client version {{ testAria2cConnectionSuccess }}
</div> </div>
</div> </div>

View file

@ -22,6 +22,9 @@ export class SettingsComponent implements OnInit {
public testWriteSpeedError: string; public testWriteSpeedError: string;
public testWriteSpeedSuccess: number; public testWriteSpeedSuccess: number;
public testAria2cConnectionError: string = null;
public testAria2cConnectionSuccess: string = null;
public settingLogLevel: string; public settingLogLevel: string;
public settingRealDebridApiKey: string; public settingRealDebridApiKey: string;
public settingDownloadPath: 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 { private getSetting(settings: Setting[], key: string): string {
const setting = settings.filter((m) => m.settingId === key); const setting = settings.filter((m) => m.settingId === key);

View file

@ -33,7 +33,7 @@ namespace RdtClient.Service.Services.Downloaders
_timer.Elapsed += OnTimedEvent; _timer.Elapsed += OnTimedEvent;
_timer.Interval = 1000; _timer.Interval = 100;
_timer.Enabled = false; _timer.Enabled = false;
} }

View file

@ -4,6 +4,7 @@ using System.Diagnostics;
using System.IO; using System.IO;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Aria2NET;
using RdtClient.Data.Data; using RdtClient.Data.Data;
using RdtClient.Data.Models.Data; using RdtClient.Data.Models.Data;
using RdtClient.Data.Models.Internal; using RdtClient.Data.Models.Internal;
@ -78,13 +79,13 @@ namespace RdtClient.Service.Services
var downloadClient = new DownloadClient(download, download.Torrent, downloadPath); var downloadClient = new DownloadClient(download, download.Torrent, downloadPath);
downloadClient.Start(Get); await downloadClient.Start(Get);
while (!downloadClient.Finished) while (!downloadClient.Finished)
{ {
#pragma warning disable CA2016 // Forward the 'CancellationToken' parameter to methods that take one #pragma warning disable CA2016 // Forward the 'CancellationToken' parameter to methods that take one
// ReSharper disable once MethodSupportsCancellation // 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 #pragma warning restore CA2016 // Forward the 'CancellationToken' parameter to methods that take one
if (cancellationToken.IsCancellationRequested) if (cancellationToken.IsCancellationRequested)
@ -95,6 +96,8 @@ namespace RdtClient.Service.Services
if (downloadClient.BytesDone > 1024 * 1024 * 50) if (downloadClient.BytesDone > 1024 * 1024 * 50)
{ {
downloadClient.Cancel(); downloadClient.Cancel();
break;
} }
} }
@ -152,6 +155,13 @@ namespace RdtClient.Service.Services
return writeSpeed; return writeSpeed;
} }
public async Task<VersionResult> GetAria2cVersion(String url, String secret)
{
var client = new Aria2NetClient(url, secret);
return await client.GetVersion();
}
public void Clean() public void Clean()
{ {
try try

View file

@ -82,6 +82,15 @@ namespace RdtClient.Web.Controllers
return Ok(writeSpeed); return Ok(writeSpeed);
} }
[HttpPost]
[Route("TestAria2cConnection")]
public async Task<ActionResult<String>> TestAria2cConnection([FromBody] SettingsControllerTestAria2cConnectionRequest request)
{
var version = await _settings.GetAria2cVersion(request.Url, request.Secret);
return Ok(version);
}
} }
public class SettingsControllerUpdateRequest public class SettingsControllerUpdateRequest
@ -93,4 +102,10 @@ namespace RdtClient.Web.Controllers
{ {
public String Path { get; set; } public String Path { get; set; }
} }
public class SettingsControllerTestAria2cConnectionRequest
{
public String Url { get; set; }
public String Secret { get; set; }
}
} }