fix: admin/monitoring: cache hit were displayed as browsing
Massimo Melina committed
Jan 4, 2024 at 10:49 UTC
19e92f7ccf176d0ee10a4d739d76c4e342332971
6 files changed
+22
-17
admin/src/MonitorPage.ts
+3
-3
@@ -141,15 +141,15 @@ function Connections() {
141
headerName: "File",
142
flex: 1.5,
143
renderCell({ value, row }) {
144
- if (!value) return
145
- if (!row.op)
144
+ if (!value || !row.op) return
145
+ if (row.op === 'browsing')
146
return h(Box, {}, value, h(Box, { fontSize: 'x-small' }, "browsing"))
147
return h(Fragment, {},
148
h(IconProgress, {
149
icon: row.archive ? FolderZip : row.op === 'upload' ? Upload : Download,
150
progress: row.opProgress ?? row.opOffset,
151
offset: row.opOffset,
152
- addTitle: row.opTotal && h('div', {}, "Total: " + formatBytes(row.opTotal)),
152
+ addTitle: row.op === 'cache' ? "Cache hit" : (row.opTotal && ("Total: " + formatBytes(row.opTotal))),
153
sx: { mr: 1 }
154
}),
155
row.archive ? h(Box, {}, value, h(Box, { fontSize: 'x-small', color: 'text.secondary' }, row.archive))
admin/src/mui.ts
+5
-2
@@ -36,13 +36,16 @@ export function IconProgress({ icon, progress, offset, addTitle, sx }: IconProgr
36
return h(Fragment, {},
37
h(icon, { sx: { position:'absolute', ml: '4px' } }),
38
h(CircularProgress, {
39
- value: progress * 100,
39
+ value: progress * 100 || 0,
40
variant: 'determinate',
41
size: 32,
42
sx: { position: 'absolute' },
43
}),
44
h(Tooltip, {
45
- title: h(Fragment, {}, _.isNumber(progress) ? formatPerc(progress) : "Size unknown", addTitle),
45
+ title: h(Fragment, {},
46
+ _.isNumber(progress) ? formatPerc(progress) : "Size unknown",
47
+ addTitle && h('div', {}, addTitle)
48
+ ),
49
children: h(CircularProgress, {
50
color: 'success',
51
value: (offset || 1e-7) * 100,
src/api.get_file_list.ts
+2
-2
@@ -40,11 +40,11 @@ export const get_file_list: ApiHandler = async ({ uri='/', offset, limit, search
40
const can_comment = can_upload && areCommentsEnabled()
41
const can_overwrite = can_upload && (can_delete || !dontOverwriteUploading.get())
42
const props = { can_archive, can_upload, can_delete, can_overwrite, accept: node.accept, can_comment }
43
+ ctx.state.browsing = uri.replace(/\/{2,}/g, '/')
44
+ updateConnection(getConnection(ctx)!, { ctx })
45
if (!list)
46
return { ...props, list: await asyncGeneratorToArray(produceEntries()) }
47
setTimeout(async () => {
46
- ctx.state.browsing = uri.replace(/\/{2,}/g, '/')
47
- updateConnection(getConnection(ctx)!, { ctx })
48
list.props(props)
49
for await (const entry of produceEntries())
50
list.add(entry)
src/api.monitor.ts
+6
-6
@@ -81,15 +81,15 @@ const apis: ApiHandlers = {
81
82
function fromCtx(ctx?: Koa.Context) {
83
if (!ctx) return
84
- const path = ctx.state.browsing && decodeURIComponent(ctx.state.browsing)
85
- || ctx.state.uploadPath && decodeURIComponent(ctx.state.uploadPath)
86
- || (ctx.fileSource || ctx.state.archive) && decodeURIComponent(ctx.path) // downloads
84
+ const s = ctx.state // short alias
85
return {
86
user: getCurrentUsername(ctx),
87
agent: shortenAgent(ctx.get('user-agent')),
90
- archive: ctx.state.archive,
91
- upload: ctx.state.uploadProgress,
92
- ...path && { path },
88
+ archive: s.archive,
89
+ upload: s.uploadProgress,
90
+ ...s.browsing ? { op: 'browsing', path: decodeURIComponent(s.browsing) }
91
+ : s.uploadPath ? { op: 'upload',path: decodeURIComponent(s.uploadPath) }
92
+ : (ctx.fileSource || s.archive) && { path: decodeURIComponent(ctx.path) }
93
}
94
}
95
},
src/connections.ts
+3
-3
@@ -11,7 +11,7 @@ export class Connection {
11
got = 0
12
outSpeed?: number
13
inSpeed?: number
14
- op?: 'download' | 'upload'
14
+ op?: 'download' | 'upload' | 'browsing' | 'cache'
15
opTotal?: number
16
opProgress?: number
17
opOffset?: number
@@ -63,8 +63,8 @@ export function getConnection(ctx: Context) {
63
}
64
65
export function updateConnection(conn: Connection, change: Partial<Connection>) {
66
- if (change.op)
67
- change.opProgress ??= change.opOffset || 0
66
+ if (change.opOffset !== undefined)
67
+ change.opProgress = change.opOffset || 0
68
Object.assign(conn, change)
69
events.emit('connectionUpdated', conn, change)
70
}
src/serveFile.ts
+3
-1
@@ -75,8 +75,10 @@ export async function serveFile(ctx: Koa.Context, source:string, mime?:string, c
75
ctx.fileSource = source
76
ctx.fileStats = stats
77
ctx.status = HTTP_OK
78
- if (ctx.fresh)
78
+ if (ctx.fresh) {
79
+ updateConnection(ctx.state.connection, { ctx, op: 'cache' })
80
return ctx.status = HTTP_NOT_MODIFIED
81
+ }
82
if (content !== undefined)
83
return ctx.body = content
84
const { size } = stats