From dce75b563bcd3bc2a5b9d8ff62244a0ed329fb63 Mon Sep 17 00:00:00 2001 From: CounterFire2023 <136581895+CounterFire2023@users.noreply.github.com> Date: Tue, 16 Apr 2024 21:45:59 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A9=E5=8A=9B=E8=AE=B0=E5=BD=95=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E6=8C=89code=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/chest.controller.ts | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/controllers/chest.controller.ts b/src/controllers/chest.controller.ts index d00856a..db76ee6 100644 --- a/src/controllers/chest.controller.ts +++ b/src/controllers/chest.controller.ts @@ -66,12 +66,23 @@ class BoxController extends BaseController { @role(ROLE_ANON) @router('post /api/chest/enhance/list') async enhanceList(req) { - let { chestId, chestid } = req.params + let { chestId, chestid, code } = req.params chestid = chestId || chestid - if (!isObjectIdString(chestid)) { - throw new ZError(11, 'must provide valid chestid') + if (code && !isValidShareCode(code)) { + throw new ZError(11, 'invalid share code') + } + if (chestid && !isObjectIdString(chestid)) { + throw new ZError(11, 'invalid chest id') + } + if (!code && !chestId) { + throw new ZError(11, 'must provide share code or chest id') + } + let chest: any + if (chestId) { + chest = await ActivityChest.findById(chestId) + } else { + chest = await ActivityChest.findOne({ shareCode: code }) } - const chest = await ActivityChest.findById(chestid) if (!chest) { throw new ZError(12, 'chest not found') }