Line data Source code
1 : import type { MissingModelDownloadState } from '@/platform/workflowErrors/missingModel/missingModelDownloadStore'
2 : import { formatSize } from '@/utils/formatUtil'
3 :
4 : /** Received and total bytes of a running download, as far as the host reported them. */
5 34 : export function formatDownloadedBytes(
6 : state: MissingModelDownloadState
7 : ): string | undefined {
8 34 : if (state.status !== 'downloading') return undefined
9 0 : const { receivedBytes, totalBytes } = state
10 34 : if (
11 : receivedBytes !== null &&
12 : totalBytes !== null &&
13 : totalBytes > 0 &&
14 : receivedBytes <= totalBytes
15 : ) {
16 0 : return `${formatSize(receivedBytes)} / ${formatSize(totalBytes)}`
17 : }
18 0 : if (receivedBytes !== null) return formatSize(receivedBytes)
19 : return undefined
20 : }
|