fix: 修复文件和模块命名/重复添加的逻辑

This commit is contained in:
xream
2023-09-15 10:08:36 +08:00
parent b2d0276836
commit 1d31a80b9f
3 changed files with 11 additions and 6 deletions

View File

@@ -22,15 +22,17 @@ export default function register($app) {
// module API
function createModule(req, res) {
const module = req.body;
module.name = module.name ?? hex_md5(JSON.stringify(module));
module.name = `${module.name ?? hex_md5(JSON.stringify(module))}`;
$.info(`正在创建模块:${module.name}`);
const allModules = $.read(MODULES_KEY);
if (findByName(allModules, module.name)) {
failed(
return failed(
res,
new RequestInvalidError(
'DUPLICATE_KEY',
`已存在相同的模块 请勿重复添加`,
req.body.name
? `已存在 name 为 ${module.name} 的模块`
: `已存在相同的模块 请勿重复添加`,
),
);
}