mirror of
https://github.com/whyour/qinglong.git
synced 2025-05-22 22:36:06 +08:00
添加log查询api
This commit is contained in:
parent
b2c22327f9
commit
c0f09ec5bb
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -20,4 +20,5 @@
|
||||||
/src/.umi-test
|
/src/.umi-test
|
||||||
/.env.local
|
/.env.local
|
||||||
/config
|
/config
|
||||||
|
/log
|
||||||
.env
|
.env
|
|
@ -2,11 +2,13 @@ import { Router } from 'express';
|
||||||
import auth from './auth';
|
import auth from './auth';
|
||||||
import cookie from './cookie';
|
import cookie from './cookie';
|
||||||
import config from './config';
|
import config from './config';
|
||||||
|
import log from './log';
|
||||||
|
|
||||||
export default () => {
|
export default () => {
|
||||||
const app = Router();
|
const app = Router();
|
||||||
auth(app);
|
auth(app);
|
||||||
cookie(app);
|
cookie(app);
|
||||||
config(app);
|
config(app);
|
||||||
|
log(app);
|
||||||
return app;
|
return app;
|
||||||
};
|
};
|
||||||
|
|
77
back/api/log.ts
Normal file
77
back/api/log.ts
Normal file
|
@ -0,0 +1,77 @@
|
||||||
|
import { Router, Request, Response, NextFunction } from 'express';
|
||||||
|
import { Container } from 'typedi';
|
||||||
|
import { Logger } from 'winston';
|
||||||
|
import * as fs from 'fs';
|
||||||
|
import config from '../config';
|
||||||
|
import { getFileContentByName } from '../config/util';
|
||||||
|
const route = Router();
|
||||||
|
|
||||||
|
export default (app: Router) => {
|
||||||
|
app.use('/', route);
|
||||||
|
route.get(
|
||||||
|
'/logs',
|
||||||
|
async (req: Request, res: Response, next: NextFunction) => {
|
||||||
|
const logger: Logger = Container.get('logger');
|
||||||
|
try {
|
||||||
|
const fileList = fs.readdirSync(config.logPath, 'utf-8');
|
||||||
|
const dirs = [];
|
||||||
|
for (let i = 0; i < fileList.length; i++) {
|
||||||
|
const stat = fs.lstatSync(config.logPath + fileList[i]);
|
||||||
|
if (stat.isDirectory()) {
|
||||||
|
const fileListTmp = fs.readdirSync(
|
||||||
|
`${config.logPath}/${fileList[i]}`,
|
||||||
|
'utf-8',
|
||||||
|
);
|
||||||
|
dirs.push({
|
||||||
|
name: fileList[i],
|
||||||
|
isDir: true,
|
||||||
|
files: fileListTmp.reverse(),
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
dirs.push({
|
||||||
|
name: fileList[i],
|
||||||
|
isDir: false,
|
||||||
|
files: [],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
res.send({ code: 200, dirs });
|
||||||
|
} catch (e) {
|
||||||
|
logger.error('🔥 error: %o', e);
|
||||||
|
return next(e);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
route.get(
|
||||||
|
'/logs/:dir/:file',
|
||||||
|
async (req: Request, res: Response, next: NextFunction) => {
|
||||||
|
const logger: Logger = Container.get('logger');
|
||||||
|
try {
|
||||||
|
const { dir, file } = req.params;
|
||||||
|
const content = getFileContentByName(
|
||||||
|
`${config.logPath}/${dir}/${file}`,
|
||||||
|
);
|
||||||
|
res.send({ code: 200, data: content });
|
||||||
|
} catch (e) {
|
||||||
|
logger.error('🔥 error: %o', e);
|
||||||
|
return next(e);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
route.get(
|
||||||
|
'/logs/:file',
|
||||||
|
async (req: Request, res: Response, next: NextFunction) => {
|
||||||
|
const logger: Logger = Container.get('logger');
|
||||||
|
try {
|
||||||
|
const { file } = req.params;
|
||||||
|
const content = getFileContentByName(`${config.logPath}/${file}`);
|
||||||
|
res.send({ code: 200, data: content });
|
||||||
|
} catch (e) {
|
||||||
|
logger.error('🔥 error: %o', e);
|
||||||
|
return next(e);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
};
|
|
@ -39,7 +39,6 @@ const Crontab = () => {
|
||||||
<PageContainer
|
<PageContainer
|
||||||
className="code-mirror-wrapper"
|
className="code-mirror-wrapper"
|
||||||
title="互助码"
|
title="互助码"
|
||||||
loading={loading}
|
|
||||||
header={{
|
header={{
|
||||||
style: {
|
style: {
|
||||||
padding: '4px 16px 4px 15px',
|
padding: '4px 16px 4px 15px',
|
||||||
|
|
|
@ -35,63 +35,6 @@ const Config = () => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
function sleep(time: number) {
|
|
||||||
return new Promise((resolve) => setTimeout(resolve, time));
|
|
||||||
}
|
|
||||||
|
|
||||||
const showQrCode = () => {
|
|
||||||
request.get(`${config.apiPrefix}qrcode`).then(async (data) => {
|
|
||||||
const modal = Modal.info({
|
|
||||||
title: '二维码',
|
|
||||||
content: (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
display: 'flex',
|
|
||||||
flexDirection: 'column',
|
|
||||||
alignItems: 'center',
|
|
||||||
marginLeft: -38,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<QRCode
|
|
||||||
style={{
|
|
||||||
width: 200,
|
|
||||||
height: 200,
|
|
||||||
marginBottom: 10,
|
|
||||||
marginTop: 20,
|
|
||||||
}}
|
|
||||||
value={data.qrcode}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
),
|
|
||||||
});
|
|
||||||
getCookie(modal);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const getCookie = async (modal: { destroy: () => void }) => {
|
|
||||||
for (let i = 0; i < 50; i++) {
|
|
||||||
const {
|
|
||||||
data: { cookie, errcode, message },
|
|
||||||
} = await request.get(`${config.apiPrefix}cookie`);
|
|
||||||
if (cookie) {
|
|
||||||
notification.success({
|
|
||||||
message: 'Cookie获取成功',
|
|
||||||
});
|
|
||||||
modal.destroy();
|
|
||||||
Modal.success({
|
|
||||||
title: '获取Cookie成功',
|
|
||||||
content: <div>{cookie}</div>,
|
|
||||||
});
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (errcode !== 176) {
|
|
||||||
notification.error({ message });
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
await sleep(2000);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (document.body.clientWidth < 768) {
|
if (document.body.clientWidth < 768) {
|
||||||
setWdith('auto');
|
setWdith('auto');
|
||||||
|
@ -109,7 +52,6 @@ const Config = () => {
|
||||||
<PageContainer
|
<PageContainer
|
||||||
className="code-mirror-wrapper"
|
className="code-mirror-wrapper"
|
||||||
title="config.sh"
|
title="config.sh"
|
||||||
loading={loading}
|
|
||||||
extra={[
|
extra={[
|
||||||
<Button key="1" type="primary" onClick={updateConfig}>
|
<Button key="1" type="primary" onClick={updateConfig}>
|
||||||
保存
|
保存
|
||||||
|
|
|
@ -51,7 +51,6 @@ const Crontab = () => {
|
||||||
<PageContainer
|
<PageContainer
|
||||||
className="code-mirror-wrapper"
|
className="code-mirror-wrapper"
|
||||||
title="crontab.list"
|
title="crontab.list"
|
||||||
loading={loading}
|
|
||||||
extra={[
|
extra={[
|
||||||
<Button key="1" type="primary" onClick={updateConfig}>
|
<Button key="1" type="primary" onClick={updateConfig}>
|
||||||
保存
|
保存
|
||||||
|
|
|
@ -51,7 +51,6 @@ const Crontab = () => {
|
||||||
<PageContainer
|
<PageContainer
|
||||||
className="code-mirror-wrapper"
|
className="code-mirror-wrapper"
|
||||||
title="diy.sh"
|
title="diy.sh"
|
||||||
loading={loading}
|
|
||||||
extra={[
|
extra={[
|
||||||
<Button key="1" type="primary" onClick={updateConfig}>
|
<Button key="1" type="primary" onClick={updateConfig}>
|
||||||
保存
|
保存
|
||||||
|
|
|
@ -21,20 +21,32 @@ const Log = () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const formatData = (tree: any[]) => {
|
const formatData = (tree: any[]) => {
|
||||||
return tree.map(x => {
|
return tree.map((x) => {
|
||||||
x.title = x.dirName;
|
x.title = x.name;
|
||||||
x.value = x.dirName;
|
x.value = x.name;
|
||||||
x.disabled = true;
|
x.disabled = x.isDir;
|
||||||
x.children = x.files.map((y: string) => ({ title: y, key: y, value: y, parent: x.dirName }));
|
x.children = x.files.map((y: string) => ({
|
||||||
|
title: y,
|
||||||
|
key: y,
|
||||||
|
value: y,
|
||||||
|
parent: x.name,
|
||||||
|
}));
|
||||||
return x;
|
return x;
|
||||||
})
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
const getLog = (node: any) => {
|
const getLog = (node: any) => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
request.get(`${config.apiPrefix}logs/${node.parent}/${node.value}`).then((data) => {
|
let url = `${node.parent}/${node.value}`;
|
||||||
setValue(data);
|
if (!node.isDir) {
|
||||||
}).finally(() => setLoading(false));
|
url = node.value;
|
||||||
|
}
|
||||||
|
request
|
||||||
|
.get(`${config.apiPrefix}logs/${url}`)
|
||||||
|
.then((data) => {
|
||||||
|
setValue(data.data);
|
||||||
|
})
|
||||||
|
.finally(() => setLoading(false));
|
||||||
};
|
};
|
||||||
|
|
||||||
const onSelect = (value: any, node: any) => {
|
const onSelect = (value: any, node: any) => {
|
||||||
|
@ -60,7 +72,6 @@ const Log = () => {
|
||||||
<PageContainer
|
<PageContainer
|
||||||
className="code-mirror-wrapper"
|
className="code-mirror-wrapper"
|
||||||
title={title}
|
title={title}
|
||||||
loading={loading}
|
|
||||||
extra={[
|
extra={[
|
||||||
<TreeSelect
|
<TreeSelect
|
||||||
style={{ width: 280 }}
|
style={{ width: 280 }}
|
||||||
|
@ -71,7 +82,7 @@ const Log = () => {
|
||||||
showSearch
|
showSearch
|
||||||
key="title"
|
key="title"
|
||||||
onSelect={onSelect}
|
onSelect={onSelect}
|
||||||
/>
|
/>,
|
||||||
]}
|
]}
|
||||||
header={{
|
header={{
|
||||||
style: {
|
style: {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user