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:
Cucumberrbob 2025-06-07 18:43:42 +01:00
parent f5f2760f80
commit 6909fb3851
No known key found for this signature in database
GPG key ID: 2B935C47401C3614
2 changed files with 5 additions and 21 deletions

View file

@ -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');

View file

@ -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,