Add aria2 test connection button on the settings.
This commit is contained in:
parent
ae41865bb2
commit
c90c336e70
6 changed files with 75 additions and 6 deletions
|
|
@ -33,4 +33,11 @@ export class SettingsService {
|
|||
public testWriteSpeed(): Observable<number> {
|
||||
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,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -146,9 +146,26 @@
|
|||
<div class="control">
|
||||
<input class="input" type="text" maxlength="1000" [(ngModel)]="aria2cSecret" />
|
||||
</div>
|
||||
<p class="help">
|
||||
The secret of your Aria2c instance. Optional.
|
||||
</p>
|
||||
<p class="help">The secret of your Aria2c instance. Optional.</p>
|
||||
</div>
|
||||
|
||||
<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>
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ namespace RdtClient.Service.Services.Downloaders
|
|||
|
||||
_timer.Elapsed += OnTimedEvent;
|
||||
|
||||
_timer.Interval = 1000;
|
||||
_timer.Interval = 100;
|
||||
_timer.Enabled = false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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<VersionResult> GetAria2cVersion(String url, String secret)
|
||||
{
|
||||
var client = new Aria2NetClient(url, secret);
|
||||
|
||||
return await client.GetVersion();
|
||||
}
|
||||
|
||||
public void Clean()
|
||||
{
|
||||
try
|
||||
|
|
|
|||
|
|
@ -82,6 +82,15 @@ namespace RdtClient.Web.Controllers
|
|||
|
||||
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
|
||||
|
|
@ -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; }
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue