脚本管理支持重命名文件/文件夹

This commit is contained in:
whyour
2022-12-27 16:02:15 +08:00
parent 0c6a214e55
commit a2d9f1a5db
4 changed files with 145 additions and 4 deletions
+27
View File
@@ -274,4 +274,31 @@ export default (app: Router) => {
}
},
);
route.put(
'/rename',
celebrate({
body: Joi.object({
filename: Joi.string().required(),
path: Joi.string().allow(''),
newFilename: Joi.string().required(),
}),
}),
async (req: Request, res: Response, next: NextFunction) => {
try {
let { filename, path, type, newFilename } = req.body as {
filename: string;
path: string;
type: string;
newFilename: string;
};
const filePath = join(config.scriptPath, path, filename);
const newPath = join(config.scriptPath, path, newFilename);
fs.renameSync(filePath, newPath);
res.send({ code: 200 });
} catch (e) {
return next(e);
}
},
);
};