@samitouri / QOSami-HFS / commits / c8935884

admin/logs: avoid breaking upload size

Massimo Melina committed Dec 23, 2023 at 20:23 UTC c8935884ce303c58209bbff31d9f5afe4a2d7df9
3 files changed +5 -4
admin/src/LogsPage.ts
+2 -2
@@ -4,7 +4,7 @@ import { createElement as h, Fragment, useMemo, useState } from 'react';
4 import { Box, Tab, Tabs, Tooltip } from '@mui/material'
5 import { API_URL, useApiList } from './api'
6 import { DataTable } from './DataTable'
7 -import { Dict, formatBytes, HTTP_UNAUTHORIZED, prefix, shortenAgent, splitAt, tryJson, typedKeys } from '@hfs/shared'
7 +import { Dict, formatBytes, HTTP_UNAUTHORIZED, NBSP, prefix, shortenAgent, splitAt, tryJson, typedKeys } from '@hfs/shared'
8 import { logLabels } from './OptionsPage'
9 import { Flex, useBreakpoint, usePauseButton, useToggleButton } from './mui';
10 import { GridColDef } from '@mui/x-data-grid'
@@ -49,7 +49,7 @@ function LogFile({ file, pause, showApi }: { file: string, pause?: boolean, show
49 if (extra?.ua && !showAgent)
50 setShowAgent(true)
51 x.notes = extra?.dl ? "fully downloaded"
52 - : (x.method === 'PUT' || extra?.ul) ? "uploaded " + formatBytes(extra.size)
52 + : (x.method === 'PUT' || extra?.ul) ? "uploaded " + formatBytes(extra.size, { sep: NBSP })
53 : x.status === HTTP_UNAUTHORIZED && x.uri?.startsWith(API_URL + 'loginSrp') ? "login failed" + prefix(':\n', extra?.u)
54 : x.notes
55 return x
src/cross-const.ts
+1
@@ -4,6 +4,7 @@ export const ADMIN_URI = SPECIAL_URI + 'admin/'
4 export const API_URI = SPECIAL_URI + 'api/'
5 export const PLUGINS_PUB_URI = SPECIAL_URI + 'plugins/'
6 export const PORT_DISABLED = -1
7 +export const NBSP = '\xA0'
8
9 export const HTTP_OK = 200
10 export const HTTP_NO_CONTENT = 204
src/cross.ts
+2 -2
@@ -93,14 +93,14 @@ export function isWhoObject(v: undefined | Who): v is WhoObject {
93 }
94
95 const MULTIPLIERS = ['', 'K', 'M', 'G', 'T']
96 -export function formatBytes(n: number, { post='B', k=1024, digits=NaN }={}) {
96 +export function formatBytes(n: number, { post='B', k=1024, digits=NaN, sep=' ' }={}) {
97 if (isNaN(Number(n)) || n < 0)
98 return ''
99 const i = n && Math.floor(Math.log2(n) / Math.log2(k))
100 n /= k ** i
101 const nAsString = i && !isNaN(digits) ? n.toFixed(digits)
102 : _.round(n, isNaN(digits) ? (n >= 100 ? 0 : 1) : digits)
103 - return nAsString + ' ' + (MULTIPLIERS[i]||'') + post
103 + return nAsString + sep + (MULTIPLIERS[i]||'') + post
104 } // formatBytes
105
106 export function formatSpeed(n: number, options: { digits?: number }={}) {