From 6380a49a5677262c471d69783612882c6e4fb646 Mon Sep 17 00:00:00 2001 From: YANG QIA <2013xile@gmail.com> Date: Mon, 13 May 2024 12:08:52 +0800 Subject: [PATCH] fix(logger): download path (#4327) * fix(logger): list log files by application name * fix: tips * fix(logger): download path --- .../@nocobase/plugin-logger/src/server/resourcer/logger.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/plugins/@nocobase/plugin-logger/src/server/resourcer/logger.ts b/packages/plugins/@nocobase/plugin-logger/src/server/resourcer/logger.ts index 7db64a962a..221f594d7f 100644 --- a/packages/plugins/@nocobase/plugin-logger/src/server/resourcer/logger.ts +++ b/packages/plugins/@nocobase/plugin-logger/src/server/resourcer/logger.ts @@ -15,11 +15,11 @@ import stream from 'stream'; import { pack } from 'tar-fs'; import zlib from 'zlib'; -const tarFiles = (files: string[]): Promise => { +const tarFiles = (path: string, files: string[]): Promise => { return new Promise((resolve, reject) => { const passthrough = new stream.PassThrough(); const gz = zlib.createGzip(); - pack(getLoggerFilePath(), { + pack(path, { entries: files, }) .on('data', (chunk) => { @@ -76,6 +76,7 @@ export default { await next(); }, download: async (ctx: Context, next: Next) => { + const path = getLoggerFilePath(ctx.app.name || 'main'); let { files = [] } = ctx.action.params.values || {}; const invalid = files.some((file: string) => !file.endsWith('.log')); if (invalid) { @@ -89,7 +90,7 @@ export default { }); try { ctx.attachment('logs.tar.gz'); - ctx.body = await tarFiles(files); + ctx.body = await tarFiles(path, files); } catch (err) { ctx.log.error(`download error: ${err.message}`, { files, err: err.stack }); ctx.throw(500, ctx.t('Download logs failed.'));