diff --git a/client/.editorconfig b/client/.editorconfig index 59d9a3a..c5cf666 100644 --- a/client/.editorconfig +++ b/client/.editorconfig @@ -7,6 +7,7 @@ indent_style = space indent_size = 2 insert_final_newline = true trim_trailing_whitespace = true +max_line_length = 120 [*.ts] quote_type = single diff --git a/client/src/app/file-status.pipe.ts b/client/src/app/file-status.pipe.ts index 16888d4..436dc93 100644 --- a/client/src/app/file-status.pipe.ts +++ b/client/src/app/file-status.pipe.ts @@ -1,29 +1,58 @@ import { Pipe, PipeTransform } from '@angular/core'; +import { FileSizePipe } from 'ngx-filesize'; import { TorrentFile } from './models/torrent.model'; -import { DownloadStatus } from './models/download.model'; @Pipe({ name: 'fileStatus', }) export class FileStatusPipe implements PipeTransform { + constructor(private pipe: FileSizePipe) {} + transform(value: TorrentFile): string { - if ( - !value.download || - value.download.status === DownloadStatus.PendingDownload - ) { + 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'; } - if (value.download.status === DownloadStatus.Downloading) { - const progress = ( - (value.download.bytesDownloaded / value.download.bytesSize) * - 100 - ).toFixed(2); - return `${progress || 0}%`; - } - - if (value.download.status === DownloadStatus.Finished) { - return `Finished`; - } + return ''; } } diff --git a/client/src/app/models/download.model.ts b/client/src/app/models/download.model.ts index 8bfcca3..fe2c712 100644 --- a/client/src/app/models/download.model.ts +++ b/client/src/app/models/download.model.ts @@ -1,24 +1,17 @@ export class Download { public downloadId: string; - public torrentId: string; - public link: string; - public added: Date; - - public status: DownloadStatus; - - public bytesDownloaded: number; - - public bytesSize: number; - + public downloadQueued: Date; + public downloadStarted: Date; + public downloadFinished: Date; + public unpackingQueued: Date; + public unpackingStarted: Date; + public unpackingFinished: Date; + public completed: Date; + public error: string; + public bytesTotal: number; + public bytesDone: number; public speed: number; } - -export enum DownloadStatus { - PendingDownload = 0, - Downloading = 1, - Unpacking = 2, - Finished = 3, -} diff --git a/client/src/app/models/profile.model.ts b/client/src/app/models/profile.model.ts index cc3a993..d84b49b 100644 --- a/client/src/app/models/profile.model.ts +++ b/client/src/app/models/profile.model.ts @@ -1,4 +1,4 @@ export class Profile { - userName: string; - expiration: Date; + public userName: string; + public expiration: Date; } diff --git a/client/src/app/models/torrent.model.ts b/client/src/app/models/torrent.model.ts index d065b29..e44f5c5 100644 --- a/client/src/app/models/torrent.model.ts +++ b/client/src/app/models/torrent.model.ts @@ -1,41 +1,47 @@ import { Download } from './download.model'; export class Torrent { - torrentId: string; - hash: string; - status: TorrentStatus; - rdId: string; - rdName: string; - rdSize: number; - rdHost: string; - rdSplit: number; - rdProgress: number; - rdStatus: string; - rdAdded: Date; - rdEnded: Date; - rdSpeed: number; - rdSeeders: number; - rdFiles: string; + public torrentId: string; + public hash: string; + public category: string; + public added: Date; + public completed: Date; + public autoDownload: boolean; + public autoUnpack: boolean; + public autoDelete: boolean; - files: TorrentFile[]; - downloads: Download[]; + public rdId: string; + public rdName: string; + public rdSize: number; + public rdHost: string; + public rdSplit: number; + public rdProgress: number; + public rdStatus: RealDebridStatus; + public rdStatusRaw: string; + public rdAdded: Date; + public rdEnded: Date; + public rdSpeed: number; + public rdSeeders: number; + public rdFiles: string; + + public files: TorrentFile[]; + public downloads: Download[]; } export class TorrentFile { - id: string; - path: string; - bytes: number; - selected: boolean; + public id: string; + public path: string; + public bytes: number; + public selected: boolean; - download: Download; + public download: Download; } -export enum TorrentStatus { - RealDebrid = 0, - WaitingForDownload = 1, - DownloadQueued = 2, - Downloading = 3, - Finished = 4, +export enum RealDebridStatus { + Processing = 0, + WaitingForFileSelection = 1, + Downloading = 2, + Finished = 3, Error = 99, } 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 7e81a8a..87a1675 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 @@ -47,6 +47,10 @@ Download torrent to host when finished downloading on Real-Debrid +