From 1d31a80b9f9ffda2a65f5b5df97c6345e684dd49 Mon Sep 17 00:00:00 2001 From: xream Date: Fri, 15 Sep 2023 10:08:36 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=92=8C=E6=A8=A1=E5=9D=97=E5=91=BD=E5=90=8D/=E9=87=8D?= =?UTF-8?q?=E5=A4=8D=E6=B7=BB=E5=8A=A0=E7=9A=84=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/package.json | 2 +- backend/src/restful/file.js | 7 +++++-- backend/src/restful/module.js | 8 +++++--- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/backend/package.json b/backend/package.json index 75802b2..ce9f91e 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "sub-store", - "version": "2.14.55", + "version": "2.14.56", "description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.", "main": "src/main.js", "scripts": { diff --git a/backend/src/restful/file.js b/backend/src/restful/file.js index 64ea95f..80357c9 100644 --- a/backend/src/restful/file.js +++ b/backend/src/restful/file.js @@ -18,14 +18,17 @@ export default function register($app) { // file API function createFile(req, res) { const file = req.body; + file.name = `${file.name ?? Date.now()}`; $.info(`正在创建文件:${file.name}`); const allFiles = $.read(FILES_KEY); if (findByName(allFiles, file.name)) { - failed( + return failed( res, new RequestInvalidError( 'DUPLICATE_KEY', - `File ${file.name} already exists.`, + req.body.name + ? `已存在 name 为 ${file.name} 的文件` + : `无法同时创建相同的文件 可稍后重试`, ), ); } diff --git a/backend/src/restful/module.js b/backend/src/restful/module.js index cd64c25..2df6648 100644 --- a/backend/src/restful/module.js +++ b/backend/src/restful/module.js @@ -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} 的模块` + : `已存在相同的模块 请勿重复添加`, ), ); }