diff --git a/back/api/log.ts b/back/api/log.ts index 97c435e4..edb6cf63 100644 --- a/back/api/log.ts +++ b/back/api/log.ts @@ -27,7 +27,7 @@ export default (app: Router) => { }); route.get( - '/:file', + '/detail', async (req: Request, res: Response, next: NextFunction) => { const logger: Logger = Container.get('logger'); try { @@ -37,7 +37,7 @@ export default (app: Router) => { const filePath = join( config.logPath, (req.query.path || '') as string, - req.params.file, + req.query.file as string, ); const content = await getFileContentByName(filePath); res.send({ code: 200, data: content }); diff --git a/back/api/script.ts b/back/api/script.ts index ed22ef4f..98639e52 100644 --- a/back/api/script.ts +++ b/back/api/script.ts @@ -73,14 +73,14 @@ export default (app: Router) => { }); route.get( - '/:file', + '/detail', async (req: Request, res: Response, next: NextFunction) => { const logger: Logger = Container.get('logger'); try { const filePath = join( config.scriptPath, req.query.path as string, - req.params.file, + req.query.file as string, ); const content = await getFileContentByName(filePath); res.send({ code: 200, data: content }); diff --git a/src/pages/crontab/detail.tsx b/src/pages/crontab/detail.tsx index e5bb0866..a5720c2c 100644 --- a/src/pages/crontab/detail.tsx +++ b/src/pages/crontab/detail.tsx @@ -119,21 +119,17 @@ const CronDetailModal = ({ }; const onClickItem = (item: LogItem) => { - const url = `${config.apiPrefix}logs/${item.filename}?path=${ + const url = `${config.apiPrefix}logs/detail?file=${item.filename}&path=${ item.directory || '' }`; localStorage.setItem('logCron', url); setLogUrl(url); - request - .get( - `${config.apiPrefix}logs/${item.filename}?path=${item.directory || ''}`, - ) - .then(({ code, data }) => { - if (code === 200) { - setLog(data); - setIsLogModalVisible(true); - } - }); + request.get(url).then(({ code, data }) => { + if (code === 200) { + setLog(data); + setIsLogModalVisible(true); + } + }); }; const onTabChange = (key: string) => { @@ -159,7 +155,7 @@ const CronDetailModal = ({ const [s, p] = result; setScriptInfo({ parent: p, filename: s }); request - .get(`${config.apiPrefix}scripts/${s}?path=${p || ''}`) + .get(`${config.apiPrefix}scripts/detail?file=${s}&path=${p || ''}`) .then(({ code, data }) => { if (code === 200) { setValue(data); diff --git a/src/pages/log/index.tsx b/src/pages/log/index.tsx index eb2d1eb8..f2fc232a 100644 --- a/src/pages/log/index.tsx +++ b/src/pages/log/index.tsx @@ -55,7 +55,11 @@ const Log = () => { const getLog = (node: any) => { request - .get(`${config.apiPrefix}logs/${node.title}?path=${node.parent || ''}`) + .get( + `${config.apiPrefix}logs/detail?file=${node.title}&path=${ + node.parent || '' + }`, + ) .then(({ code, data }) => { if (code === 200) { setValue(data); diff --git a/src/pages/script/editModal.tsx b/src/pages/script/editModal.tsx index 1a63f938..c69e8f1f 100644 --- a/src/pages/script/editModal.tsx +++ b/src/pages/script/editModal.tsx @@ -67,7 +67,11 @@ const EditModal = ({ const getDetail = (node: any) => { request - .get(`${config.apiPrefix}scripts/${node.title}?path=${node.parent || ''}`) + .get( + `${config.apiPrefix}scripts/detail?file=${node.title}&path=${ + node.parent || '' + }`, + ) .then(({ code, data }) => { if (code === 200) { setValue(data); diff --git a/src/pages/script/index.tsx b/src/pages/script/index.tsx index ec9daeb5..dd882b15 100644 --- a/src/pages/script/index.tsx +++ b/src/pages/script/index.tsx @@ -84,9 +84,9 @@ const Script = () => { const getDetail = (node: any) => { request .get( - `${config.apiPrefix}scripts/${encodeURIComponent(node.title)}?path=${ - node.parent || '' - }`, + `${config.apiPrefix}scripts/detail?file=${encodeURIComponent( + node.title, + )}&path=${node.parent || ''}`, ) .then(({ code, data }) => { if (code === 200) {