admin/logs: write "uploaded up to..." for partial uploads made because of split_uploads

Massimo Melina committed Nov 3, 2024 at 22:17 UTC ace8190098203a92a4db7c61ce35e21af24c6de5
2 files changed +21 -11
admin/src/LogsPage.ts
+16 -11
@@ -4,8 +4,10 @@ import { createElement as h, Fragment, ReactNode, useEffect, useMemo, useState }
4 import { Box, Tab, Tabs } from '@mui/material'
5 import { API_URL, apiCall, useApi, useApiList } from './api'
6 import { DataTable } from './DataTable'
7 -import { CFG, Dict, formatBytes, HTTP_UNAUTHORIZED, newDialog, prefix, shortenAgent, splitAt, tryJson, md,
8 - typedKeys, NBSP, _dbg, mapFilter, safeDecodeURIComponent } from '@hfs/shared'
7 +import {
8 + CFG, Dict, formatBytes, HTTP_UNAUTHORIZED, newDialog, prefix, shortenAgent, splitAt, tryJson, md,
9 + typedKeys, NBSP, _dbg, mapFilter, safeDecodeURIComponent, stringAfter
10 +} from '@hfs/shared'
11 import {
12 NetmaskField, Flex, IconBtn, useBreakpoint, usePauseButton, useToggleButton, WildcardsSupported, Country,
13 hTooltip, Btn, wikiLink
@@ -286,18 +288,21 @@ function LogFile({ file, addToFooter, hidden }: { hidden?: boolean, file: string
288 ]
289 })
290
289 - function enhanceLogLine(x: any) {
290 - if (!x) return
291 - const { extra } = x
292 - if ((extra?.country || x.country) && !showCountry)
291 + function enhanceLogLine(row: any) {
292 + if (!row) return
293 + const { extra } = row
294 + if ((extra?.country || row.country) && !showCountry)
295 setShowCountry(true)
296 if (extra?.ua && !showAgent)
297 setShowAgent(true)
296 - x.notes = extra?.dl ? "fully downloaded"
297 - : (x.method === 'PUT' || extra?.ul) ? "uploaded " + formatBytes(extra?.size, { sep: NBSP })
298 - : x.status === HTTP_UNAUTHORIZED && x.uri?.startsWith(API_URL + 'loginSrp') ? "login failed" + prefix(':\n', extra?.u)
299 - : _.map(extra?.params, (v, k) => `${k}: ${v}\n`).join('') + (x.notes || '')
300 - return x
298 + if (row.uri) {
299 + const partial = stringAfter('?', row.uri).includes('partial=')
300 + row.notes = extra?.dl ? "fully downloaded"
301 + : (row.method === 'PUT' || extra?.ul) ? "uploaded " + (partial ? "up to " : "") + formatBytes(extra?.size, { sep: NBSP })
302 + : row.status === HTTP_UNAUTHORIZED && row.uri?.startsWith(API_URL + 'loginSrp') ? "login failed" + prefix(':\n', extra?.u)
303 + : _.map(extra?.params, (v, k) => `${k}: ${v}\n`).join('') + (row.notes || '')
304 + }
305 + return row
306 }
307 }
308
src/cross.ts
+5
@@ -150,6 +150,11 @@ export function splitAt(sub: string | number, all: string): [string, string] {
150 return i < 0 ? [all,''] : [all.slice(0, i), all.slice(i + sub.length)]
151 }
152
153 +export function stringAfter(sub: string, all: string) {
154 + const i = all.indexOf(sub)
155 + return i < 0 ? '' : all.slice(i + sub.length)
156 +}
157 +
158 export function truthy<T>(value: T): value is Truthy<T> {
159 return Boolean(value)
160 }