修复调试功能

This commit is contained in:
whyour
2021-11-20 00:58:23 +08:00
parent 5e94be21aa
commit 40b0e90c0d
6 changed files with 113 additions and 9 deletions
+27
View File
@@ -10,6 +10,7 @@ import config from '../config';
import * as fs from 'fs';
import { celebrate, Joi } from 'celebrate';
import path from 'path';
import ScriptService from '../services/script';
const route = Router();
export default (app: Router) => {
@@ -237,4 +238,30 @@ export default (app: Router) => {
}
},
);
route.put(
'/scripts/run',
celebrate({
body: Joi.object({
filename: Joi.string().required(),
path: Joi.string().optional().allow(''),
}),
}),
async (req: Request, res: Response, next: NextFunction) => {
const logger: Logger = Container.get('logger');
try {
let { filename, path } = req.body as {
filename: string;
path: string;
};
const filePath = `${path}/${filename}`;
const scriptService = Container.get(ScriptService);
const result = await scriptService.runScript(filePath);
res.send(result);
} catch (e) {
logger.error('🔥 error: %o', e);
return next(e);
}
},
);
};