mirror of
https://github.com/whyour/qinglong.git
synced 2025-09-12 05:52:47 +08:00
Fix missing t
in query parameters, fix missing and error validation in script API
This commit is contained in:
parent
3c1dc68ac9
commit
01a5f2b5aa
|
@ -32,52 +32,52 @@ export default (app: Router) => {
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
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 {
|
||||||
let result: IFile[] = [];
|
let result: IFile[] = [];
|
||||||
const blacklist = [
|
const blacklist = [
|
||||||
'node_modules',
|
'node_modules',
|
||||||
'.git',
|
'.git',
|
||||||
'.pnpm',
|
'.pnpm',
|
||||||
'pnpm-lock.yaml',
|
'pnpm-lock.yaml',
|
||||||
'yarn.lock',
|
'yarn.lock',
|
||||||
'package-lock.json',
|
'package-lock.json',
|
||||||
];
|
];
|
||||||
if (req.query.path) {
|
if (req.query.path) {
|
||||||
result = await readDir(
|
result = await readDir(
|
||||||
req.query.path as string,
|
req.query.path as string,
|
||||||
config.scriptPath,
|
config.scriptPath,
|
||||||
blacklist,
|
blacklist,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
result = await readDirs(
|
result = await readDirs(
|
||||||
config.scriptPath,
|
config.scriptPath,
|
||||||
config.scriptPath,
|
config.scriptPath,
|
||||||
blacklist,
|
blacklist,
|
||||||
(a, b) => {
|
(a, b) => {
|
||||||
if (a.type === b.type) {
|
if (a.type === b.type) {
|
||||||
return a.title.localeCompare(b.title);
|
return a.title.localeCompare(b.title);
|
||||||
} else {
|
} else {
|
||||||
return a.type === 'directory' ? -1 : 1;
|
return a.type === 'directory' ? -1 : 1;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
res.send({
|
||||||
|
code: 200,
|
||||||
|
data: result,
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
logger.error('🔥 error: %o', e);
|
||||||
|
return next(e);
|
||||||
}
|
}
|
||||||
res.send({
|
});
|
||||||
code: 200,
|
|
||||||
data: result,
|
|
||||||
});
|
|
||||||
} catch (e) {
|
|
||||||
logger.error('🔥 error: %o', e);
|
|
||||||
return next(e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
route.get(
|
route.get(
|
||||||
'/detail',
|
'/detail',
|
||||||
celebrate({
|
celebrate({
|
||||||
query: Joi.object({
|
query: Joi.object({
|
||||||
path: Joi.string().required(),
|
path: Joi.string().optional().allow(''),
|
||||||
file: Joi.string().required(),
|
file: Joi.string().required(),
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
|
@ -125,6 +125,7 @@ export default (app: Router) => {
|
||||||
celebrate({
|
celebrate({
|
||||||
body: Joi.object({
|
body: Joi.object({
|
||||||
filename: Joi.string().required(),
|
filename: Joi.string().required(),
|
||||||
|
file: Joi.string().optional().allow(''),
|
||||||
path: Joi.string().optional().allow(''),
|
path: Joi.string().optional().allow(''),
|
||||||
content: Joi.string().optional().allow(''),
|
content: Joi.string().optional().allow(''),
|
||||||
originFilename: Joi.string().optional().allow(''),
|
originFilename: Joi.string().optional().allow(''),
|
||||||
|
|
10
back/app.ts
10
back/app.ts
|
@ -27,6 +27,13 @@ class Application {
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.app = express();
|
this.app = express();
|
||||||
|
// 创建一个全局中间件,删除查询参数中的t
|
||||||
|
this.app.use((req: express.Request, res: express.Response, next: express.NextFunction) => {
|
||||||
|
if (req.query.t) {
|
||||||
|
delete req.query.t;
|
||||||
|
}
|
||||||
|
next();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async start() {
|
async start() {
|
||||||
|
@ -54,8 +61,7 @@ class Application {
|
||||||
if (metadata) {
|
if (metadata) {
|
||||||
if (!this.isShuttingDown) {
|
if (!this.isShuttingDown) {
|
||||||
Logger.error(
|
Logger.error(
|
||||||
`${metadata.serviceType} worker ${worker.process.pid} died (${
|
`${metadata.serviceType} worker ${worker.process.pid} died (${signal || code
|
||||||
signal || code
|
|
||||||
}). Restarting...`,
|
}). Restarting...`,
|
||||||
);
|
);
|
||||||
const newWorker = this.forkWorker(metadata.serviceType);
|
const newWorker = this.forkWorker(metadata.serviceType);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user