admin/monitoring: show zip downloads properly

Massimo Melina committed May 25, 2022 at 10:48 UTC 8f5c35f3644b78a682dd7c88b9ede0906863d21c
3 files changed +13 -3
admin/src/MonitorPage.ts
+4 -2
@@ -3,7 +3,7 @@
3 import _ from "lodash"
4 import { isValidElement, createElement as h, useMemo, Fragment, useState } from "react"
5 import { apiCall, useApiComp, useApiList } from "./api"
6 -import { PauseCircle, PlayCircle, Delete, Lock, Block } from '@mui/icons-material'
6 +import { PauseCircle, PlayCircle, Delete, Lock, Block, FolderZip } from '@mui/icons-material'
7 import { Box, Chip } from '@mui/material'
8 import { DataGrid } from "@mui/x-data-grid"
9 import { Alert } from '@mui/material'
@@ -86,8 +86,10 @@ function Connections() {
86 field: 'path',
87 headerName: "File",
88 flex: 1,
89 - renderCell({ value }) {
89 + renderCell({ value, row }) {
90 if (!value) return
91 + if (row.archive)
92 + return h(Fragment, {}, h(FolderZip, { sx: { mr: 1 } }), row.archive, h(Box, { ml: 2, color: 'text.secondary' }, value))
93 const i = value?.lastIndexOf('/')
94 return h(Fragment, {}, value.slice(i + 1),
95 i > 0 && h(Box, { ml: 2, color: 'text.secondary' }, value.slice(0, i)))
server/src/api.monitor.ts
+4 -1
@@ -44,7 +44,10 @@ const apis: ApiHandlers = {
44 }
45
46 function fromCtx(ctx?: Koa.Context) {
47 - return ctx && { path: ctx.fileSource && ctx.path } // only for downloading files
47 + return ctx && {
48 + archive: ctx.state.archive,
49 + path: (ctx.fileSource || ctx.state.archive) && ctx.path // only for downloading files
50 + }
51 }
52 },
53
server/src/zip.ts
+5
@@ -8,6 +8,7 @@ import { createReadStream } from 'fs'
8 import fs from 'fs/promises'
9 import { defineConfig } from './config'
10 import { dirname } from 'path'
11 +import { updateConnection } from './connections'
12
13 export async function zipStreamFromFolder(node: VfsNode, ctx: Koa.Context) {
14 ctx.status = 200
@@ -55,6 +56,10 @@ export async function zipStreamFromFolder(node: VfsNode, ctx: Koa.Context) {
56 ctx.response.length = await zip.calculateSize(time)
57 ctx.body = zip
58 ctx.req.on('close', ()=> zip.destroy())
59 + ctx.state.archive = 'zip'
60 + const conn = ctx.state.connection
61 + if (conn)
62 + updateConnection(conn, { ctx }) // update connection data
63 }
64
65 const zipSeconds = defineConfig('zip_calculate_size_for_seconds', 1)