diff --git a/back/api/script.ts b/back/api/script.ts index ee6db133..c9278790 100644 --- a/back/api/script.ts +++ b/back/api/script.ts @@ -32,52 +32,52 @@ export default (app: Router) => { }), }), async (req: Request, res: Response, next: NextFunction) => { - const logger: Logger = Container.get('logger'); - try { - let result: IFile[] = []; - const blacklist = [ - 'node_modules', - '.git', - '.pnpm', - 'pnpm-lock.yaml', - 'yarn.lock', - 'package-lock.json', - ]; - if (req.query.path) { - result = await readDir( - req.query.path as string, - config.scriptPath, - blacklist, - ); - } else { - result = await readDirs( - config.scriptPath, - config.scriptPath, - blacklist, - (a, b) => { - if (a.type === b.type) { - return a.title.localeCompare(b.title); - } else { - return a.type === 'directory' ? -1 : 1; - } - }, - ); + const logger: Logger = Container.get('logger'); + try { + let result: IFile[] = []; + const blacklist = [ + 'node_modules', + '.git', + '.pnpm', + 'pnpm-lock.yaml', + 'yarn.lock', + 'package-lock.json', + ]; + if (req.query.path) { + result = await readDir( + req.query.path as string, + config.scriptPath, + blacklist, + ); + } else { + result = await readDirs( + config.scriptPath, + config.scriptPath, + blacklist, + (a, b) => { + if (a.type === b.type) { + return a.title.localeCompare(b.title); + } else { + return a.type === 'directory' ? -1 : 1; + } + }, + ); + } + res.send({ + code: 200, + data: result, + }); + } catch (e) { + logger.error('🔥 error: %o', e); + return next(e); } - res.send({ - code: 200, - data: result, - }); - } catch (e) { - logger.error('🔥 error: %o', e); - return next(e); - } - }); + }); route.get( '/detail', celebrate({ query: Joi.object({ - path: Joi.string().required(), + path: Joi.string().optional().allow(''), file: Joi.string().required(), }), }), @@ -125,6 +125,7 @@ export default (app: Router) => { celebrate({ body: Joi.object({ filename: Joi.string().required(), + file: Joi.string().optional().allow(''), path: Joi.string().optional().allow(''), content: Joi.string().optional().allow(''), originFilename: Joi.string().optional().allow(''), diff --git a/back/app.ts b/back/app.ts index 8c76ffd1..2b01de26 100644 --- a/back/app.ts +++ b/back/app.ts @@ -27,6 +27,13 @@ class Application { constructor() { this.app = express(); + // 创建一个全局中间件,删除查询参数中的t + this.app.use((req: express.Request, res: express.Response, next: express.NextFunction) => { + if (req.query.t) { + delete req.query.t; + } + next(); + }); } async start() { @@ -54,8 +61,7 @@ class Application { if (metadata) { if (!this.isShuttingDown) { Logger.error( - `${metadata.serviceType} worker ${worker.process.pid} died (${ - signal || code + `${metadata.serviceType} worker ${worker.process.pid} died (${signal || code }). Restarting...`, ); const newWorker = this.forkWorker(metadata.serviceType);