修改脚本详情和日志详情接口

This commit is contained in:
whyour 2024-01-29 21:47:03 +08:00
parent 49c441117a
commit 0ae1f284ec
6 changed files with 25 additions and 21 deletions

View File

@ -27,7 +27,7 @@ export default (app: Router) => {
}); });
route.get( route.get(
'/:file', '/detail',
async (req: Request, res: Response, next: NextFunction) => { async (req: Request, res: Response, next: NextFunction) => {
const logger: Logger = Container.get('logger'); const logger: Logger = Container.get('logger');
try { try {
@ -37,7 +37,7 @@ export default (app: Router) => {
const filePath = join( const filePath = join(
config.logPath, config.logPath,
(req.query.path || '') as string, (req.query.path || '') as string,
req.params.file, req.query.file as string,
); );
const content = await getFileContentByName(filePath); const content = await getFileContentByName(filePath);
res.send({ code: 200, data: content }); res.send({ code: 200, data: content });

View File

@ -73,14 +73,14 @@ export default (app: Router) => {
}); });
route.get( route.get(
'/:file', '/detail',
async (req: Request, res: Response, next: NextFunction) => { async (req: Request, res: Response, next: NextFunction) => {
const logger: Logger = Container.get('logger'); const logger: Logger = Container.get('logger');
try { try {
const filePath = join( const filePath = join(
config.scriptPath, config.scriptPath,
req.query.path as string, req.query.path as string,
req.params.file, req.query.file as string,
); );
const content = await getFileContentByName(filePath); const content = await getFileContentByName(filePath);
res.send({ code: 200, data: content }); res.send({ code: 200, data: content });

View File

@ -119,21 +119,17 @@ const CronDetailModal = ({
}; };
const onClickItem = (item: LogItem) => { const onClickItem = (item: LogItem) => {
const url = `${config.apiPrefix}logs/${item.filename}?path=${ const url = `${config.apiPrefix}logs/detail?file=${item.filename}&path=${
item.directory || '' item.directory || ''
}`; }`;
localStorage.setItem('logCron', url); localStorage.setItem('logCron', url);
setLogUrl(url); setLogUrl(url);
request request.get(url).then(({ code, data }) => {
.get( if (code === 200) {
`${config.apiPrefix}logs/${item.filename}?path=${item.directory || ''}`, setLog(data);
) setIsLogModalVisible(true);
.then(({ code, data }) => { }
if (code === 200) { });
setLog(data);
setIsLogModalVisible(true);
}
});
}; };
const onTabChange = (key: string) => { const onTabChange = (key: string) => {
@ -159,7 +155,7 @@ const CronDetailModal = ({
const [s, p] = result; const [s, p] = result;
setScriptInfo({ parent: p, filename: s }); setScriptInfo({ parent: p, filename: s });
request request
.get(`${config.apiPrefix}scripts/${s}?path=${p || ''}`) .get(`${config.apiPrefix}scripts/detail?file=${s}&path=${p || ''}`)
.then(({ code, data }) => { .then(({ code, data }) => {
if (code === 200) { if (code === 200) {
setValue(data); setValue(data);

View File

@ -55,7 +55,11 @@ const Log = () => {
const getLog = (node: any) => { const getLog = (node: any) => {
request request
.get(`${config.apiPrefix}logs/${node.title}?path=${node.parent || ''}`) .get(
`${config.apiPrefix}logs/detail?file=${node.title}&path=${
node.parent || ''
}`,
)
.then(({ code, data }) => { .then(({ code, data }) => {
if (code === 200) { if (code === 200) {
setValue(data); setValue(data);

View File

@ -67,7 +67,11 @@ const EditModal = ({
const getDetail = (node: any) => { const getDetail = (node: any) => {
request request
.get(`${config.apiPrefix}scripts/${node.title}?path=${node.parent || ''}`) .get(
`${config.apiPrefix}scripts/detail?file=${node.title}&path=${
node.parent || ''
}`,
)
.then(({ code, data }) => { .then(({ code, data }) => {
if (code === 200) { if (code === 200) {
setValue(data); setValue(data);

View File

@ -84,9 +84,9 @@ const Script = () => {
const getDetail = (node: any) => { const getDetail = (node: any) => {
request request
.get( .get(
`${config.apiPrefix}scripts/${encodeURIComponent(node.title)}?path=${ `${config.apiPrefix}scripts/detail?file=${encodeURIComponent(
node.parent || '' node.title,
}`, )}&path=${node.parent || ''}`,
) )
.then(({ code, data }) => { .then(({ code, data }) => {
if (code === 200) { if (code === 200) {