diff --git a/client/src/app/download-status.pipe.ts b/client/src/app/download-status.pipe.ts index 100777f..0105727 100644 --- a/client/src/app/download-status.pipe.ts +++ b/client/src/app/download-status.pipe.ts @@ -2,7 +2,7 @@ import { Pipe, PipeTransform } from '@angular/core'; import { Download } from './models/download.model'; import { FileSizePipe } from './filesize.pipe'; -@Pipe({ name: 'downloadStatus', }) +@Pipe({ name: 'downloadStatus' }) export class DownloadStatusPipe implements PipeTransform { constructor(private pipe: FileSizePipe) {} @@ -24,11 +24,7 @@ export class DownloadStatusPipe implements PipeTransform { } if (value.unpackingStarted) { - let progress = (value.bytesDone / value.bytesTotal) * 100; - - if (isNaN(progress)) { - progress = 0; - } + const progress = (value.bytesDone / value.bytesTotal || 0) * 100; return `Unpacking ${progress.toFixed(2)}%`; } @@ -42,11 +38,7 @@ export class DownloadStatusPipe implements PipeTransform { } if (value.downloadStarted) { - let progress = (value.bytesDone / value.bytesTotal) * 100; - - if (isNaN(progress)) { - progress = 0; - } + const progress = (value.bytesDone / value.bytesTotal || 0) * 100; const speed = this.pipe.transform(value.speed, 'filesize'); diff --git a/client/src/app/torrent-status.pipe.ts b/client/src/app/torrent-status.pipe.ts index 6b330d2..ac9da79 100644 --- a/client/src/app/torrent-status.pipe.ts +++ b/client/src/app/torrent-status.pipe.ts @@ -24,11 +24,7 @@ export class TorrentStatusPipe implements PipeTransform { if (downloading.length > 0) { const bytesDone = downloading.reduce((sum, m) => sum + m.bytesDone, 0); const bytesTotal = downloading.reduce((sum, m) => sum + m.bytesTotal, 0); - let progress = (bytesDone / bytesTotal) * 100; - - if (isNaN(progress)) { - progress = 0; - } + const progress = (bytesDone / bytesTotal || 0) * 100; let allSpeeds = downloading.reduce((sum, m) => sum + m.speed, 0); @@ -45,11 +41,7 @@ export class TorrentStatusPipe implements PipeTransform { if (unpacking.length > 0) { const bytesDone = unpacking.reduce((sum, m) => sum + m.bytesDone, 0); const bytesTotal = unpacking.reduce((sum, m) => sum + m.bytesTotal, 0); - let progress = (bytesDone / bytesTotal) * 100; - - if (isNaN(progress)) { - progress = 0; - } + const progress = (bytesDone / bytesTotal || 0) * 100; return `Extracting file ${unpacking.length + unpacked.length}/${torrent.downloads.length} (${progress.toFixed( 2,