From 67532645aaa624c93e3428c6f872a4a92720ec68 Mon Sep 17 00:00:00 2001 From: Roger Far Date: Tue, 12 Jan 2021 20:42:06 -0700 Subject: [PATCH] Fixed status columns, separate downloads and files in the detail list. Add UnpackLimit setting. --- client/src/app/app.module.ts | 46 ++++------ client/src/app/download-status.pipe.ts | 54 +++++++++++ client/src/app/file-status.pipe.ts | 58 ------------ .../add-new-torrent.component.html | 4 +- client/src/app/navbar/navbar.component.html | 3 +- client/src/app/navbar/navbar.component.scss | 3 + .../navbar/settings/settings.component.html | 70 ++++---------- .../app/navbar/settings/settings.component.ts | 6 ++ .../torrent-download.component.html | 11 +++ .../torrent-download.component.scss | 3 + .../torrent-download.component.ts | 18 ++++ .../torrent-file/torrent-file.component.html | 10 +- .../torrent-file/torrent-file.component.ts | 7 +- .../torrent-row/torrent-row.component.html | 6 +- client/src/app/torrent-status.pipe.ts | 92 ++++++++++--------- .../torrent-table.component.html | 13 ++- .../torrent-table.component.scss | 7 ++ .../torrent-table/torrent-table.component.ts | 15 --- client/src/app/torrent.service.ts | 4 - server/RdtClient.Data/Data/DataContext.cs | 6 ++ server/RdtClient.Data/Data/DownloadData.cs | 12 ++- server/RdtClient.Service/Models/Profile.cs | 2 +- .../RdtClient.Service/Services/Downloads.cs | 6 ++ .../Services/TorrentRunner.cs | 7 +- server/RdtClient.Service/Services/Torrents.cs | 3 +- .../Controllers/TorrentsController.cs | 23 ++--- 26 files changed, 253 insertions(+), 236 deletions(-) create mode 100644 client/src/app/download-status.pipe.ts delete mode 100644 client/src/app/file-status.pipe.ts create mode 100644 client/src/app/torrent-download/torrent-download.component.html create mode 100644 client/src/app/torrent-download/torrent-download.component.scss create mode 100644 client/src/app/torrent-download/torrent-download.component.ts diff --git a/client/src/app/app.module.ts b/client/src/app/app.module.ts index 6d84dd0..036ff92 100644 --- a/client/src/app/app.module.ts +++ b/client/src/app/app.module.ts @@ -1,24 +1,24 @@ -import { BrowserModule } from '@angular/platform-browser'; +import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http'; import { NgModule } from '@angular/core'; import { FormsModule } from '@angular/forms'; -import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http'; -import { NgxFilesizeModule, FileSizePipe } from 'ngx-filesize'; - +import { BrowserModule } from '@angular/platform-browser'; +import { curray } from 'curray'; +import { FileSizePipe, NgxFilesizeModule } from 'ngx-filesize'; import { AppRoutingModule } from './app-routing.module'; import { AppComponent } from './app.component'; -import { MainLayoutComponent } from './main-layout/main-layout.component'; -import { NavbarComponent } from './navbar/navbar.component'; -import { AddNewTorrentComponent } from './navbar/add-new-torrent/add-new-torrent.component'; -import { TorrentTableComponent } from './torrent-table/torrent-table.component'; -import { TorrentRowComponent } from './torrent-row/torrent-row.component'; -import { TorrentFileComponent } from './torrent-file/torrent-file.component'; -import { SettingsComponent } from './navbar/settings/settings.component'; -import { TorrentStatusPipe } from './torrent-status.pipe'; -import { FileStatusPipe } from './file-status.pipe'; -import { LoginComponent } from './login/login.component'; import { AuthInterceptor } from './auth.interceptor'; -import { curray } from 'curray'; +import { DownloadStatusPipe } from './download-status.pipe'; +import { LoginComponent } from './login/login.component'; +import { MainLayoutComponent } from './main-layout/main-layout.component'; +import { AddNewTorrentComponent } from './navbar/add-new-torrent/add-new-torrent.component'; +import { NavbarComponent } from './navbar/navbar.component'; +import { SettingsComponent } from './navbar/settings/settings.component'; import { SetupComponent } from './setup/setup.component'; +import { TorrentDownloadComponent } from './torrent-download/torrent-download.component'; +import { TorrentFileComponent } from './torrent-file/torrent-file.component'; +import { TorrentRowComponent } from './torrent-row/torrent-row.component'; +import { TorrentStatusPipe } from './torrent-status.pipe'; +import { TorrentTableComponent } from './torrent-table/torrent-table.component'; curray(); @@ -33,21 +33,13 @@ curray(); TorrentFileComponent, SettingsComponent, TorrentStatusPipe, - FileStatusPipe, + DownloadStatusPipe, LoginComponent, SetupComponent, + TorrentDownloadComponent, ], - imports: [ - BrowserModule, - AppRoutingModule, - FormsModule, - HttpClientModule, - NgxFilesizeModule, - ], - providers: [ - FileSizePipe, - { provide: HTTP_INTERCEPTORS, useClass: AuthInterceptor, multi: true }, - ], + imports: [BrowserModule, AppRoutingModule, FormsModule, HttpClientModule, NgxFilesizeModule], + providers: [FileSizePipe, { provide: HTTP_INTERCEPTORS, useClass: AuthInterceptor, multi: true }], bootstrap: [AppComponent], }) export class AppModule {} diff --git a/client/src/app/download-status.pipe.ts b/client/src/app/download-status.pipe.ts new file mode 100644 index 0000000..5bacacf --- /dev/null +++ b/client/src/app/download-status.pipe.ts @@ -0,0 +1,54 @@ +import { Pipe, PipeTransform } from '@angular/core'; +import { FileSizePipe } from 'ngx-filesize'; +import { Download } from './models/download.model'; + +@Pipe({ + name: 'downloadStatus', +}) +export class DownloadStatusPipe implements PipeTransform { + constructor(private pipe: FileSizePipe) {} + + transform(value: Download): string { + if (!value) { + return 'Pending'; + } + + if (value.error) { + return `Error: ${value.error}`; + } + + if (value.completed != null) { + return 'Finished'; + } + + if (value.unpackingFinished) { + return 'Unpacking finished'; + } + + if (value.unpackingStarted) { + const progress = ((value.bytesDone / value.bytesTotal) * 100).toFixed(2); + return `Unpacking ${progress || 0}%`; + } + + if (value.unpackingQueued) { + return 'Unpacking queued'; + } + + if (value.downloadFinished) { + return 'Download finished'; + } + + if (value.downloadStarted) { + const progress = ((value.bytesDone / value.bytesTotal) * 100).toFixed(2); + const speed = this.pipe.transform(value.speed, 'filesize'); + + return `Downloading ${progress || 0}% (${speed}/s)`; + } + + if (value.downloadQueued) { + return 'Download queued'; + } + + return 'Pending'; + } +} diff --git a/client/src/app/file-status.pipe.ts b/client/src/app/file-status.pipe.ts deleted file mode 100644 index 436dc93..0000000 --- a/client/src/app/file-status.pipe.ts +++ /dev/null @@ -1,58 +0,0 @@ -import { Pipe, PipeTransform } from '@angular/core'; -import { FileSizePipe } from 'ngx-filesize'; -import { TorrentFile } from './models/torrent.model'; - -@Pipe({ - name: 'fileStatus', -}) -export class FileStatusPipe implements PipeTransform { - constructor(private pipe: FileSizePipe) {} - - transform(value: TorrentFile): string { - if (!value.download) { - return 'Pending download'; - } - - if (value.download.error) { - return `Error: ${value.download.error}`; - } - - if (value.download.completed != null) { - return 'Finished'; - } - - if (value.download.unpackingFinished) { - return 'Unpacking finished'; - } - - if (value.download.unpackingStarted) { - const progress = ((value.download.bytesDone / value.download.bytesTotal) * 100).toFixed(2); - return `Unpacking ${progress || 0}%`; - } - - if (value.download.unpackingQueued) { - return 'Unpacking queued'; - } - - if (value.download.downloadFinished) { - return 'Download finished'; - } - - if (value.download.downloadStarted) { - const progress = ((value.download.bytesDone / value.download.bytesTotal) * 100).toFixed(2); - const speed = this.pipe.transform(value.download.speed, 'filesize'); - - return `Downloading ${progress || 0}% (${speed}/s)`; - } - - if (value.download.downloadQueued) { - return 'Download queued'; - } - - if (value.download.added) { - return 'Pending'; - } - - return ''; - } -} diff --git a/client/src/app/navbar/add-new-torrent/add-new-torrent.component.html b/client/src/app/navbar/add-new-torrent/add-new-torrent.component.html index 87a1675..8f094ca 100644 --- a/client/src/app/navbar/add-new-torrent/add-new-torrent.component.html +++ b/client/src/app/navbar/add-new-torrent/add-new-torrent.component.html @@ -56,8 +56,8 @@ Remove torrent when finished downloading on host -
- Cannot add torrent: {{ error }} +
+ Cannot add torrent: {{ error | json }}
diff --git a/client/src/app/navbar/navbar.component.html b/client/src/app/navbar/navbar.component.html index f365aea..f81a529 100644 --- a/client/src/app/navbar/navbar.component.html +++ b/client/src/app/navbar/navbar.component.html @@ -46,7 +46,8 @@ - Premium Status: {{ profile.expiration | date }} + Premium Status: {{ profile.expiration | date }} + Not premium
diff --git a/client/src/app/navbar/navbar.component.scss b/client/src/app/navbar/navbar.component.scss index e69de29..b4f314f 100644 --- a/client/src/app/navbar/navbar.component.scss +++ b/client/src/app/navbar/navbar.component.scss @@ -0,0 +1,3 @@ +.no-premium { + color: red; +} diff --git a/client/src/app/navbar/settings/settings.component.html b/client/src/app/navbar/settings/settings.component.html index 6b013da..dcc1e5c 100644 --- a/client/src/app/navbar/settings/settings.component.html +++ b/client/src/app/navbar/settings/settings.component.html @@ -9,59 +9,38 @@
- +

You can find your API key here: - https://real-debrid.com/apitokenhttps://real-debrid.com/apitoken.

- +

Path on the host where RealDebrid Client is hosted.

- +
-

- Maximum amount of torrents that get downloaded to your host at the - same time. -

+

Maximum amount of torrents that get downloaded to your host at the same time.

-
- Error saving settings: {{ error }} +
+ +
+ +
+

Maximum amount of downloads that get unpacked on your host at the same time.

+
Error saving settings: {{ error }}
-
+
Could not test your download folder
{{ testFolderError }}
@@ -71,30 +50,13 @@
- - - +
diff --git a/client/src/app/navbar/settings/settings.component.ts b/client/src/app/navbar/settings/settings.component.ts index 76ef926..e0e44fb 100644 --- a/client/src/app/navbar/settings/settings.component.ts +++ b/client/src/app/navbar/settings/settings.component.ts @@ -31,6 +31,7 @@ export class SettingsComponent implements OnInit { public settingRealDebridApiKey: string; public settingDownloadFolder: string; public settingDownloadLimit: number; + public settingUnpackLimit: number; constructor(private settingsService: SettingsService) {} @@ -45,6 +46,7 @@ export class SettingsComponent implements OnInit { this.settingRealDebridApiKey = this.getSetting(results, 'RealDebridApiKey'); this.settingDownloadFolder = this.getSetting(results, 'DownloadFolder'); this.settingDownloadLimit = parseInt(this.getSetting(results, 'DownloadLimit'), 10); + this.settingUnpackLimit = parseInt(this.getSetting(results, 'UnpackLimit'), 10); }, (err) => { this.error = err.error; @@ -69,6 +71,10 @@ export class SettingsComponent implements OnInit { settingId: 'DownloadLimit', value: (this.settingDownloadLimit ?? 10).toString(), }, + { + settingId: 'UnpackLimit', + value: (this.settingUnpackLimit ?? 1).toString(), + }, ]; this.settingsService.update(settings).subscribe( diff --git a/client/src/app/torrent-download/torrent-download.component.html b/client/src/app/torrent-download/torrent-download.component.html new file mode 100644 index 0000000..0b3f8e2 --- /dev/null +++ b/client/src/app/torrent-download/torrent-download.component.html @@ -0,0 +1,11 @@ + + + {{ download.link }} + + + {{ download.bytesTotal | filesize }} + + + {{ download | downloadStatus }} + + diff --git a/client/src/app/torrent-download/torrent-download.component.scss b/client/src/app/torrent-download/torrent-download.component.scss new file mode 100644 index 0000000..03bcfa7 --- /dev/null +++ b/client/src/app/torrent-download/torrent-download.component.scss @@ -0,0 +1,3 @@ +td { + font-size: smaller; +} diff --git a/client/src/app/torrent-download/torrent-download.component.ts b/client/src/app/torrent-download/torrent-download.component.ts new file mode 100644 index 0000000..b228b64 --- /dev/null +++ b/client/src/app/torrent-download/torrent-download.component.ts @@ -0,0 +1,18 @@ +import { Component, Input, OnInit } from '@angular/core'; +import { Download } from '../models/download.model'; + +@Component({ + selector: '[app-torrent-download]', + templateUrl: './torrent-download.component.html', + styleUrls: ['./torrent-download.component.scss'], +}) +export class TorrentDownloadComponent implements OnInit { + @Input() + public download: Download; + + constructor() {} + + ngOnInit(): void { + + } +} diff --git a/client/src/app/torrent-file/torrent-file.component.html b/client/src/app/torrent-file/torrent-file.component.html index df36df9..267193d 100644 --- a/client/src/app/torrent-file/torrent-file.component.html +++ b/client/src/app/torrent-file/torrent-file.component.html @@ -1,12 +1,6 @@ - + {{ file.path }} {{ file.bytes | filesize }} - - - - {{ file | fileStatus }} - - - + diff --git a/client/src/app/torrent-file/torrent-file.component.ts b/client/src/app/torrent-file/torrent-file.component.ts index e390f17..4ae3346 100644 --- a/client/src/app/torrent-file/torrent-file.component.ts +++ b/client/src/app/torrent-file/torrent-file.component.ts @@ -1,6 +1,5 @@ -import { Component, OnInit, Input } from '@angular/core'; -import { Torrent, TorrentFile } from '../models/torrent.model'; -import { TorrentService } from '../torrent.service'; +import { Component, Input, OnInit } from '@angular/core'; +import { TorrentFile } from '../models/torrent.model'; @Component({ selector: '[app-torrent-file]', @@ -11,7 +10,7 @@ export class TorrentFileComponent implements OnInit { @Input() public file: TorrentFile; - constructor(private torrentService: TorrentService) {} + constructor() {} ngOnInit(): void {} } diff --git a/client/src/app/torrent-row/torrent-row.component.html b/client/src/app/torrent-row/torrent-row.component.html index 36c2acd..82da83e 100644 --- a/client/src/app/torrent-row/torrent-row.component.html +++ b/client/src/app/torrent-row/torrent-row.component.html @@ -1,7 +1,4 @@ {{ torrent.rdName }} - - {{ torrent.rdSize | filesize }} - {{ torrent.files.length | number }} @@ -13,6 +10,9 @@ + + {{ torrent.rdSize | filesize }} + {{ torrent | status }} diff --git a/client/src/app/torrent-status.pipe.ts b/client/src/app/torrent-status.pipe.ts index 22ac8a6..eae1507 100644 --- a/client/src/app/torrent-status.pipe.ts +++ b/client/src/app/torrent-status.pipe.ts @@ -13,59 +13,69 @@ export class TorrentStatusPipe implements PipeTransform { return 'Finished'; } - if (torrent.downloads && torrent.downloads.length > 0) { - const allFinished = torrent.downloads.all((m) => m.completed != null); - if (allFinished) { - return 'Finished'; + const allFinished = torrent.downloads.all((m) => m.completed != null); + + if (allFinished) { + return 'Finished'; + } + + const errors = torrent.downloads.where((m) => m.error != null); + + if (errors.length > 0) { + return 'Error'; + } + + const downloading = torrent.downloads.where((m) => m.downloadStarted && !m.downloadFinished); + + if (downloading.length > 0) { + const bytesDone = downloading.sum((m) => m.bytesDone); + const bytesTotal = downloading.sum((m) => m.bytesTotal); + let progress = (bytesDone / bytesTotal) * 100; + let allSpeeds = downloading.sum((m) => m.speed) / downloading.length; + + let speed: string | string[] = '0'; + if (allSpeeds > 0) { + speed = this.pipe.transform(allSpeeds, 'filesize'); + + return `Downloading (${progress.toFixed(2)}% - ${speed}/s)`; } + } - const errors = torrent.downloads.where((m) => m.error != null); - const downloading = torrent.downloads.where((m) => m.downloadStarted && !m.downloadFinished); - const downloaded = torrent.downloads.where((m) => m.downloadFinished != null); - const unpacking = torrent.downloads.where((m) => m.unpackingStarted && !m.unpackingFinished); - const queuedForDownload = torrent.downloads.where((m) => m.downloadQueued && !m.downloadStarted); - const queuedForUnpacking = torrent.downloads.where((m) => m.unpackingQueued && !m.unpackingStarted); + const unpacking = torrent.downloads.where((m) => m.unpackingStarted && !m.unpackingFinished); - if (errors.length > 0) { - return 'Error'; + if (unpacking.length > 0) { + const bytesDone = unpacking.sum((m) => m.bytesDone); + const bytesTotal = unpacking.sum((m) => m.bytesTotal); + let progress = (bytesDone / bytesTotal) * 100; + let allSpeeds = unpacking.sum((m) => m.speed) / unpacking.length; + + if (allSpeeds > 0) { + return `Extracting (${progress.toFixed(2)}%)`; } + } - if (downloading.length > 0) { - const bytesDone = downloading.sum((m) => m.bytesDone); - const bytesTotal = downloading.sum((m) => m.bytesTotal); - let progress = (bytesDone / bytesTotal) * 100; - let allSpeeds = downloading.sum((m) => m.speed) / downloading.length; + const queuedForUnpacking = torrent.downloads.where((m) => m.unpackingQueued && !m.unpackingStarted); - let speed: string | string[] = '0'; - if (allSpeeds > 0) { - speed = this.pipe.transform(allSpeeds, 'filesize'); + if (queuedForUnpacking.length > 0) { + return `Queued for unpacking`; + } - return `Downloading (${progress.toFixed(2)}% - ${speed}/s)`; - } - } + const queuedForDownload = torrent.downloads.where((m) => m.downloadQueued && !m.downloadStarted); - if (unpacking.length > 0) { - const bytesDone = unpacking.sum((m) => m.bytesDone); - const bytesTotal = unpacking.sum((m) => m.bytesTotal); - let progress = (bytesDone / bytesTotal) * 100; - let allSpeeds = unpacking.sum((m) => m.speed) / unpacking.length; + if (queuedForDownload.length > 0) { + return `Queued for downloading`; + } - if (allSpeeds > 0) { - return `Extracting (${progress.toFixed(2)}%)`; - } - } + const unpacked = torrent.downloads.where((m) => m.unpackingFinished != null); - if (queuedForUnpacking.length > 0) { - return `Queued for unpacking`; - } + if (unpacked.length > 0) { + return `Files unpacked`; + } - if (queuedForDownload.length > 0) { - return `Queued for downloading`; - } + const downloaded = torrent.downloads.where((m) => m.downloadFinished != null); - if (downloaded.length > 0) { - return `Files downloaded to host`; - } + if (downloaded.length > 0) { + return `Files downloaded to host`; } switch (torrent.rdStatus) { diff --git a/client/src/app/torrent-table/torrent-table.component.html b/client/src/app/torrent-table/torrent-table.component.html index c6a12ac..f7abded 100644 --- a/client/src/app/torrent-table/torrent-table.component.html +++ b/client/src/app/torrent-table/torrent-table.component.html @@ -5,8 +5,8 @@
- - + + @@ -16,10 +16,10 @@ - + @@ -33,6 +33,13 @@ (delete)="showDeleteModal($event)" > + + + + + + + diff --git a/client/src/app/torrent-table/torrent-table.component.scss b/client/src/app/torrent-table/torrent-table.component.scss index 41c6f23..fd54999 100644 --- a/client/src/app/torrent-table/torrent-table.component.scss +++ b/client/src/app/torrent-table/torrent-table.component.scss @@ -2,4 +2,11 @@ table { tr { cursor: pointer; } + + tr.separator { + td { + font-size: smaller; + font-weight: bold; + } + } } diff --git a/client/src/app/torrent-table/torrent-table.component.ts b/client/src/app/torrent-table/torrent-table.component.ts index ff227de..a0b0da6 100644 --- a/client/src/app/torrent-table/torrent-table.component.ts +++ b/client/src/app/torrent-table/torrent-table.component.ts @@ -45,21 +45,6 @@ export class TorrentTableComponent implements OnInit, OnDestroy { public selectTorrent(torrent: Torrent): void { this.showFiles[torrent.torrentId] = !this.showFiles[torrent.torrentId]; - - if (this.showFiles[torrent.torrentId]) { - this.torrentService.getDetails(torrent.torrentId).subscribe((result) => { - torrent.files = result.files; - torrent.downloads = result.downloads; - - torrent.files.forEach((file) => { - const downloads = torrent.downloads.filter((m) => m.link === file.path); - - if (downloads.length > 0) { - file.download = downloads[0]; - } - }); - }); - } } public trackByMethod(index: number, el: Torrent): string { diff --git a/client/src/app/torrent.service.ts b/client/src/app/torrent.service.ts index 9a4fcd3..5e89346 100644 --- a/client/src/app/torrent.service.ts +++ b/client/src/app/torrent.service.ts @@ -31,10 +31,6 @@ export class TorrentService { return this.http.get(`/Api/Torrents`); } - public getDetails(torrentId: string): Observable { - return this.http.get(`/Api/Torrents/${torrentId}`); - } - public uploadMagnet( magnetLink: string, autoDownload: boolean, diff --git a/server/RdtClient.Data/Data/DataContext.cs b/server/RdtClient.Data/Data/DataContext.cs index 01b8c12..b6ef146 100644 --- a/server/RdtClient.Data/Data/DataContext.cs +++ b/server/RdtClient.Data/Data/DataContext.cs @@ -61,6 +61,12 @@ namespace RdtClient.Data.Data SettingId = "DownloadLimit", Type = "Int32", Value = "10" + }, + new Setting + { + SettingId = "UnpackLimit", + Type = "Int32", + Value = "1" } }; diff --git a/server/RdtClient.Data/Data/DownloadData.cs b/server/RdtClient.Data/Data/DownloadData.cs index 9b39d52..2e18692 100644 --- a/server/RdtClient.Data/Data/DownloadData.cs +++ b/server/RdtClient.Data/Data/DownloadData.cs @@ -18,6 +18,7 @@ namespace RdtClient.Data.Data Task UpdateUnpackingQueued(Guid downloadId, DateTimeOffset? dateTime); Task UpdateUnpackingStarted(Guid downloadId, DateTimeOffset? dateTime); Task UpdateUnpackingFinished(Guid downloadId, DateTimeOffset? dateTime); + Task UpdateCompleted(Guid downloadId, DateTimeOffset? dateTime); Task UpdateError(Guid downloadId, String error); Task DeleteForTorrent(Guid torrentId); } @@ -122,13 +123,22 @@ namespace RdtClient.Data.Data await _dataContext.SaveChangesAsync(); } + + public async Task UpdateCompleted(Guid downloadId, DateTimeOffset? dateTime) + { + var dbDownload = await _dataContext.Downloads + .FirstOrDefaultAsync(m => m.DownloadId == downloadId); + + dbDownload.Completed = dateTime; + + await _dataContext.SaveChangesAsync(); + } public async Task UpdateError(Guid downloadId, String error) { var dbDownload = await _dataContext.Downloads .FirstOrDefaultAsync(m => m.DownloadId == downloadId); - dbDownload.Completed = DateTimeOffset.UtcNow; dbDownload.Error = error; await _dataContext.SaveChangesAsync(); diff --git a/server/RdtClient.Service/Models/Profile.cs b/server/RdtClient.Service/Models/Profile.cs index c2eaa11..44113bf 100644 --- a/server/RdtClient.Service/Models/Profile.cs +++ b/server/RdtClient.Service/Models/Profile.cs @@ -5,6 +5,6 @@ namespace RdtClient.Service.Models public class Profile { public String UserName { get; set; } - public DateTimeOffset Expiration { get; set; } + public DateTimeOffset? Expiration { get; set; } } } diff --git a/server/RdtClient.Service/Services/Downloads.cs b/server/RdtClient.Service/Services/Downloads.cs index 6b61ffc..9d78eb6 100644 --- a/server/RdtClient.Service/Services/Downloads.cs +++ b/server/RdtClient.Service/Services/Downloads.cs @@ -17,6 +17,7 @@ namespace RdtClient.Service.Services Task UpdateUnpackingQueued(Guid downloadId, DateTimeOffset? dateTime); Task UpdateUnpackingStarted(Guid downloadId, DateTimeOffset? dateTime); Task UpdateUnpackingFinished(Guid downloadId, DateTimeOffset? dateTime); + Task UpdateCompleted(Guid downloadId, DateTimeOffset? dateTime); Task UpdateError(Guid downloadId, String error); Task DeleteForTorrent(Guid torrentId); } @@ -75,6 +76,11 @@ namespace RdtClient.Service.Services await _downloadData.UpdateUnpackingFinished(downloadId, dateTime); } + public async Task UpdateCompleted(Guid downloadId, DateTimeOffset? dateTime) + { + await _downloadData.UpdateCompleted(downloadId, dateTime); + } + public async Task UpdateError(Guid downloadId, String error) { await _downloadData.UpdateError(downloadId, error); diff --git a/server/RdtClient.Service/Services/TorrentRunner.cs b/server/RdtClient.Service/Services/TorrentRunner.cs index 758c883..f7f008f 100644 --- a/server/RdtClient.Service/Services/TorrentRunner.cs +++ b/server/RdtClient.Service/Services/TorrentRunner.cs @@ -36,7 +36,9 @@ namespace RdtClient.Service.Services { // When starting up reset any pending downloads or unpackings so that they are restarted. var torrents = await _torrents.Get(); - + + torrents = torrents.Where(m => m.Completed == null).ToList(); + var downloads = torrents.SelectMany(m => m.Downloads) .Where(m => m.DownloadQueued != null && m.DownloadStarted != null && m.DownloadFinished == null) .OrderBy(m => m.DownloadQueued); @@ -75,6 +77,7 @@ namespace RdtClient.Service.Services if (downloadClient.Error != null) { await _downloads.UpdateError(downloadId, downloadClient.Error); + await _downloads.UpdateCompleted(downloadId, DateTimeOffset.UtcNow); } else { @@ -95,10 +98,12 @@ namespace RdtClient.Service.Services if (unpackClient.Error != null) { await _downloads.UpdateError(downloadId, unpackClient.Error); + await _downloads.UpdateCompleted(downloadId, DateTimeOffset.UtcNow); } else { await _downloads.UpdateUnpackingFinished(downloadId, DateTimeOffset.UtcNow); + await _downloads.UpdateCompleted(downloadId, DateTimeOffset.UtcNow); } ActiveUnpackClients.TryRemove(downloadId, out _); diff --git a/server/RdtClient.Service/Services/Torrents.cs b/server/RdtClient.Service/Services/Torrents.cs index c04fb65..cb8e100 100644 --- a/server/RdtClient.Service/Services/Torrents.cs +++ b/server/RdtClient.Service/Services/Torrents.cs @@ -234,8 +234,7 @@ namespace RdtClient.Service.Services public async Task Unpack(Guid downloadId) { - //var settingUnpackLimit = await _settings.GetNumber("UnpackLimit"); - var settingUnpackLimit = 1; + var settingUnpackLimit = await _settings.GetNumber("UnpackLimit"); var settingDownloadFolder = await _settings.GetString("DownloadFolder"); var download = await _downloads.GetById(downloadId); diff --git a/server/RdtClient.Web/Controllers/TorrentsController.cs b/server/RdtClient.Web/Controllers/TorrentsController.cs index 369759e..8777674 100644 --- a/server/RdtClient.Web/Controllers/TorrentsController.cs +++ b/server/RdtClient.Web/Controllers/TorrentsController.cs @@ -18,11 +18,13 @@ namespace RdtClient.Web.Controllers { private readonly ITorrents _torrents; private readonly IDownloads _downloads; + private readonly ITorrentRunner _torrentRunner; - public TorrentsController(ITorrents torrents, IDownloads downloads) + public TorrentsController(ITorrents torrents, IDownloads downloads, ITorrentRunner torrentRunner) { _torrents = torrents; _downloads = downloads; + _torrentRunner = torrentRunner; } [HttpGet] @@ -40,19 +42,18 @@ namespace RdtClient.Web.Controllers return Ok(results); } + /// + /// Used for debugging only. Force a tick. + /// + /// [HttpGet] - [Route("{id}")] - public async Task> Get(Guid id) + [Route("Tick")] + public async Task Tick() { - var result = await _torrents.GetById(id); + await _torrentRunner.Tick(); - if (result == null) - { - throw new Exception("Torrent not found"); - } - - return Ok(result); - } + return Ok(); + } [HttpPost] [Route("UploadFile")]
NameSize Files Downloads AutoSize Status Action
Downloads
Files in torrent