mirror of
https://github.com/whyour/qinglong.git
synced 2026-07-01 04:40:38 +08:00
兼容脚本、日志、配置文件详情接口
This commit is contained in:
+15
-18
@@ -7,7 +7,7 @@ import * as fs from 'fs/promises';
|
||||
import { celebrate, Joi } from 'celebrate';
|
||||
import { join } from 'path';
|
||||
import { SAMPLE_FILES } from '../config/const';
|
||||
import got from 'got';
|
||||
import ConfigService from '../services/config';
|
||||
const route = Router();
|
||||
|
||||
export default (app: Router) => {
|
||||
@@ -50,24 +50,9 @@ export default (app: Router) => {
|
||||
route.get(
|
||||
'/detail',
|
||||
async (req: Request, res: Response, next: NextFunction) => {
|
||||
const logger: Logger = Container.get('logger');
|
||||
try {
|
||||
let content = '';
|
||||
const _path = req.query.path as string;
|
||||
if (config.blackFileList.includes(_path) || !_path) {
|
||||
res.send({ code: 403, message: '文件无法访问' });
|
||||
}
|
||||
if (_path.startsWith('sample/')) {
|
||||
const res = await got.get(
|
||||
`https://gitlab.com/whyour/qinglong/-/raw/master/${_path}`,
|
||||
);
|
||||
content = res.body;
|
||||
} else if (_path.startsWith('data/scripts/')) {
|
||||
content = await getFileContentByName(join(config.rootPath, _path));
|
||||
} else {
|
||||
content = await getFileContentByName(join(config.configPath, _path));
|
||||
}
|
||||
res.send({ code: 200, data: content });
|
||||
const configService = Container.get(ConfigService);
|
||||
await configService.getFile(req.query.path as string, res);
|
||||
} catch (e) {
|
||||
return next(e);
|
||||
}
|
||||
@@ -100,4 +85,16 @@ export default (app: Router) => {
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
route.get(
|
||||
'/:file',
|
||||
async (req: Request, res: Response, next: NextFunction) => {
|
||||
try {
|
||||
const configService = Container.get(ConfigService);
|
||||
await configService.getFile(req.params.file, res);
|
||||
} catch (e) {
|
||||
return next(e);
|
||||
}
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
+20
-1
@@ -29,7 +29,6 @@ export default (app: Router) => {
|
||||
route.get(
|
||||
'/detail',
|
||||
async (req: Request, res: Response, next: NextFunction) => {
|
||||
const logger: Logger = Container.get('logger');
|
||||
try {
|
||||
if (blacklist.includes(req.path)) {
|
||||
return res.send({ code: 403, message: '暂无权限' });
|
||||
@@ -47,6 +46,26 @@ export default (app: Router) => {
|
||||
},
|
||||
);
|
||||
|
||||
route.get(
|
||||
'/:file',
|
||||
async (req: Request, res: Response, next: NextFunction) => {
|
||||
try {
|
||||
if (blacklist.includes(req.path)) {
|
||||
return res.send({ code: 403, message: '暂无权限' });
|
||||
}
|
||||
const filePath = join(
|
||||
config.logPath,
|
||||
(req.query.path || '') as string,
|
||||
req.params.file,
|
||||
);
|
||||
const content = await getFileContentByName(filePath);
|
||||
res.send({ code: 200, data: content });
|
||||
} catch (e) {
|
||||
return next(e);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
route.delete(
|
||||
'/',
|
||||
celebrate({
|
||||
|
||||
+18
-4
@@ -75,14 +75,28 @@ export default (app: Router) => {
|
||||
route.get(
|
||||
'/detail',
|
||||
async (req: Request, res: Response, next: NextFunction) => {
|
||||
const logger: Logger = Container.get('logger');
|
||||
try {
|
||||
const filePath = join(
|
||||
config.scriptPath,
|
||||
const scriptService = Container.get(ScriptService);
|
||||
const content = await scriptService.getFile(
|
||||
req.query.path as string,
|
||||
req.query.file as string,
|
||||
);
|
||||
const content = await getFileContentByName(filePath);
|
||||
res.send({ code: 200, data: content });
|
||||
} catch (e) {
|
||||
return next(e);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
route.get(
|
||||
'/:file',
|
||||
async (req: Request, res: Response, next: NextFunction) => {
|
||||
try {
|
||||
const scriptService = Container.get(ScriptService);
|
||||
const content = await scriptService.getFile(
|
||||
req.query.path as string,
|
||||
req.params.file,
|
||||
);
|
||||
res.send({ code: 200, data: content });
|
||||
} catch (e) {
|
||||
return next(e);
|
||||
|
||||
Reference in New Issue
Block a user