Use browser download in missing model dialog (#1362)

* Remove custom backend download logic

* Add download hooks

* Download button

* Use browser download

* Update test
This commit is contained in:
Chenlei Hu
2024-10-29 14:07:16 -04:00
committed by GitHub
parent 1f91a88d7b
commit 8dddffe840
10 changed files with 118 additions and 293 deletions

View File

@@ -60,14 +60,15 @@ export function formatNumberWithSuffix(
return `${formattedNum}${suffixes[exp]}`
}
export function formatMemory(value?: number) {
export function formatSize(value?: number) {
if (value === null || value === undefined) {
return '-'
}
const mb = Math.round(value / (1024 * 1024))
if (mb >= 1024) {
return `${(mb / 1024).toFixed(2)} GB`
}
return `${mb} MB`
const bytes = value
if (bytes === 0) return '0 B'
const k = 1024
const sizes = ['B', 'KB', 'MB', 'GB']
const i = Math.floor(Math.log(bytes) / Math.log(k))
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(2))} ${sizes[i]}`
}