fix(logger): download path (#4327)

* fix(logger): list log files by application name

* fix: tips

* fix(logger): download path
This commit is contained in:
YANG QIA 2024-05-13 12:08:52 +08:00 committed by GitHub
parent 562b29aebb
commit 6380a49a56
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -15,11 +15,11 @@ import stream from 'stream';
import { pack } from 'tar-fs';
import zlib from 'zlib';
const tarFiles = (files: string[]): Promise<any> => {
const tarFiles = (path: string, files: string[]): Promise<any> => {
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.'));