Skip to content

Commit fc27c1f

Browse files
authored
Merge pull request #784 from transformerlab/fix/download-progress-bar
Dont show nan in text if another model is deleted while downloading
2 parents bf17b78 + 1ec78be commit fc27c1f

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

src/renderer/components/Shared/DownloadProgressBox.tsx

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,17 @@ export default function DownloadProgressBox({
5050
100,
5151
);
5252

53-
const progressPercent = Math.round(progress);
54-
const downloaded = downloadProgress?.job_data?.downloaded || 0;
55-
const total = downloadProgress?.job_data?.total_size_of_model_in_mb || 0;
53+
const progressPercent = Number.isFinite(progress) ? Math.round(progress) : 0;
54+
const downloaded = Number.isFinite(
55+
Number(downloadProgress?.job_data?.downloaded),
56+
)
57+
? Number(downloadProgress?.job_data?.downloaded)
58+
: 0;
59+
const total = Number.isFinite(
60+
Number(downloadProgress?.job_data?.total_size_of_model_in_mb),
61+
)
62+
? Number(downloadProgress?.job_data?.total_size_of_model_in_mb)
63+
: 0;
5664
const downloadedBytes = downloaded * 1024 * 1024;
5765
const totalBytes = total * 1024 * 1024;
5866

@@ -73,10 +81,9 @@ export default function DownloadProgressBox({
7381

7482
<Box mt={1}>
7583
<Typography level="body-xs" sx={{ mb: 1, color: 'text.secondary' }}>
76-
{downloaded !== 0
77-
? formatBytes(downloadedBytes)
78-
: 'Download Starting'}
79-
{total > 0 && ` / ${formatBytes(totalBytes)} `}
84+
{downloaded > 0
85+
? `${formatBytes(downloadedBytes)}${total > 0 ? ` / ${formatBytes(totalBytes)}` : ''}`
86+
: 'Downloading...'}
8087
<ArrowDownIcon size="16px" style={{ verticalAlign: 'middle' }} />
8188
</Typography>
8289
<Divider sx={{ mb: 1 }} />
@@ -115,7 +122,9 @@ export default function DownloadProgressBox({
115122
: theme.vars.palette.text.primary,
116123
})}
117124
>
118-
{progressPercent}%
125+
{Number.isFinite(progressPercent)
126+
? `${progressPercent}%`
127+
: 'Loading...'}
119128
</Typography>
120129
</Box>
121130
)}

src/renderer/lib/utils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import { useEffect, useRef } from 'react';
99
* @returns string with human readable bytes
1010
*/
1111
export function formatBytes(bytes: number, decimals = 2): string {
12-
if (!+bytes) return '0 Bytes';
12+
// Handle invalid inputs (NaN, undefined, null, negative values)
13+
if (!Number.isFinite(bytes) || bytes < 0) return '0 Bytes';
1314

1415
const k = 1024;
1516
const dm = decimals < 0 ? 0 : decimals;

0 commit comments

Comments
 (0)