assign progress in one go
rather than checking for `NaN`, just `|| 0` - it will leave `0` as is, and convert any `NaN`s to `0`
This commit is contained in:
parent
f5f2760f80
commit
6909fb3851
2 changed files with 5 additions and 21 deletions
|
|
@ -2,7 +2,7 @@ import { Pipe, PipeTransform } from '@angular/core';
|
||||||
import { Download } from './models/download.model';
|
import { Download } from './models/download.model';
|
||||||
import { FileSizePipe } from './filesize.pipe';
|
import { FileSizePipe } from './filesize.pipe';
|
||||||
|
|
||||||
@Pipe({ name: 'downloadStatus', })
|
@Pipe({ name: 'downloadStatus' })
|
||||||
export class DownloadStatusPipe implements PipeTransform {
|
export class DownloadStatusPipe implements PipeTransform {
|
||||||
constructor(private pipe: FileSizePipe) {}
|
constructor(private pipe: FileSizePipe) {}
|
||||||
|
|
||||||
|
|
@ -24,11 +24,7 @@ export class DownloadStatusPipe implements PipeTransform {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value.unpackingStarted) {
|
if (value.unpackingStarted) {
|
||||||
let progress = (value.bytesDone / value.bytesTotal) * 100;
|
const progress = (value.bytesDone / value.bytesTotal || 0) * 100;
|
||||||
|
|
||||||
if (isNaN(progress)) {
|
|
||||||
progress = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return `Unpacking ${progress.toFixed(2)}%`;
|
return `Unpacking ${progress.toFixed(2)}%`;
|
||||||
}
|
}
|
||||||
|
|
@ -42,11 +38,7 @@ export class DownloadStatusPipe implements PipeTransform {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value.downloadStarted) {
|
if (value.downloadStarted) {
|
||||||
let progress = (value.bytesDone / value.bytesTotal) * 100;
|
const progress = (value.bytesDone / value.bytesTotal || 0) * 100;
|
||||||
|
|
||||||
if (isNaN(progress)) {
|
|
||||||
progress = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
const speed = this.pipe.transform(value.speed, 'filesize');
|
const speed = this.pipe.transform(value.speed, 'filesize');
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,11 +24,7 @@ export class TorrentStatusPipe implements PipeTransform {
|
||||||
if (downloading.length > 0) {
|
if (downloading.length > 0) {
|
||||||
const bytesDone = downloading.reduce((sum, m) => sum + m.bytesDone, 0);
|
const bytesDone = downloading.reduce((sum, m) => sum + m.bytesDone, 0);
|
||||||
const bytesTotal = downloading.reduce((sum, m) => sum + m.bytesTotal, 0);
|
const bytesTotal = downloading.reduce((sum, m) => sum + m.bytesTotal, 0);
|
||||||
let progress = (bytesDone / bytesTotal) * 100;
|
const progress = (bytesDone / bytesTotal || 0) * 100;
|
||||||
|
|
||||||
if (isNaN(progress)) {
|
|
||||||
progress = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
let allSpeeds = downloading.reduce((sum, m) => sum + m.speed, 0);
|
let allSpeeds = downloading.reduce((sum, m) => sum + m.speed, 0);
|
||||||
|
|
||||||
|
|
@ -45,11 +41,7 @@ export class TorrentStatusPipe implements PipeTransform {
|
||||||
if (unpacking.length > 0) {
|
if (unpacking.length > 0) {
|
||||||
const bytesDone = unpacking.reduce((sum, m) => sum + m.bytesDone, 0);
|
const bytesDone = unpacking.reduce((sum, m) => sum + m.bytesDone, 0);
|
||||||
const bytesTotal = unpacking.reduce((sum, m) => sum + m.bytesTotal, 0);
|
const bytesTotal = unpacking.reduce((sum, m) => sum + m.bytesTotal, 0);
|
||||||
let progress = (bytesDone / bytesTotal) * 100;
|
const progress = (bytesDone / bytesTotal || 0) * 100;
|
||||||
|
|
||||||
if (isNaN(progress)) {
|
|
||||||
progress = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return `Extracting file ${unpacking.length + unpacked.length}/${torrent.downloads.length} (${progress.toFixed(
|
return `Extracting file ${unpacking.length + unpacked.length}/${torrent.downloads.length} (${progress.toFixed(
|
||||||
2,
|
2,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue