From 53a96462b2827ceb49e5b82f32658458bf90e184 Mon Sep 17 00:00:00 2001 From: taozhiyu <49258735+taozhiyu@users.noreply.github.com> Date: Sun, 10 Aug 2025 18:35:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=84=9A=E6=9C=AC=20API=20?= =?UTF-8?q?=E8=B7=AF=E7=94=B1=E7=9A=84=E9=94=99=E8=AF=AF=E5=A4=84=E7=90=86?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- back/api/script.ts | 82 +++++++++++++++++++++++----------------------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/back/api/script.ts b/back/api/script.ts index 071026d1..ea682c63 100644 --- a/back/api/script.ts +++ b/back/api/script.ts @@ -32,46 +32,46 @@ 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', @@ -109,8 +109,8 @@ export default (app: Router) => { try { const scriptService = Container.get(ScriptService); const content = await scriptService.getFile( - req.query.path as string, - req.params?.file || '', + req.query?.path as string || '', + req.params.file, ); res.send({ code: 200, data: content }); } catch (e) {