mirror of
https://github.com/whyour/qinglong.git
synced 2026-07-01 04:40:38 +08:00
修改对比工具数据源,修复编辑器语言
This commit is contained in:
+23
-2
@@ -6,11 +6,27 @@ import config from '../config';
|
||||
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';
|
||||
const route = Router();
|
||||
|
||||
export default (app: Router) => {
|
||||
app.use('/configs', route);
|
||||
|
||||
route.get(
|
||||
'/sample',
|
||||
async (req: Request, res: Response, next: NextFunction) => {
|
||||
try {
|
||||
res.send({
|
||||
code: 200,
|
||||
data: SAMPLE_FILES,
|
||||
});
|
||||
} catch (e) {
|
||||
return next(e);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
route.get(
|
||||
'/files',
|
||||
async (req: Request, res: Response, next: NextFunction) => {
|
||||
@@ -40,9 +56,14 @@ export default (app: Router) => {
|
||||
if (config.blackFileList.includes(req.params.file)) {
|
||||
res.send({ code: 403, message: '文件无法访问' });
|
||||
}
|
||||
if (req.params.file.includes('sample')) {
|
||||
if (req.params.file.startsWith('sample/')) {
|
||||
const res = await got.get(
|
||||
`https://gitlab.com/whyour/qinglong/-/raw/master/${req.params.file}`,
|
||||
);
|
||||
content = res.body;
|
||||
} else if (req.params.file.startsWith('data/scripts/')) {
|
||||
content = await getFileContentByName(
|
||||
join(config.samplePath, req.params.file),
|
||||
join(config.rootPath, req.params.file),
|
||||
);
|
||||
} else {
|
||||
content = await getFileContentByName(
|
||||
|
||||
@@ -5,3 +5,21 @@ export const QL_COMMAND = 'ql';
|
||||
|
||||
export const TASK_PREFIX = `${TASK_COMMAND} `;
|
||||
export const QL_PREFIX = `${QL_COMMAND} `;
|
||||
|
||||
export const SAMPLE_FILES = [
|
||||
{
|
||||
title: 'config.sample.sh',
|
||||
value: 'sample/config.sample.sh',
|
||||
target: 'config.sh',
|
||||
},
|
||||
{
|
||||
title: 'notify.js',
|
||||
value: 'sample/notify.js',
|
||||
target: 'data/scripts/sendNotify.js',
|
||||
},
|
||||
{
|
||||
title: 'notify.py',
|
||||
value: 'sample/notify.py',
|
||||
target: 'data/scripts/notify.py',
|
||||
},
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user