From f1501a25c399f695dbc57948e59687c13386c45e Mon Sep 17 00:00:00 2001 From: CounterFire2023 <136581895+CounterFire2023@users.noreply.github.com> Date: Thu, 11 Apr 2024 20:23:29 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9D=E7=AE=B1=E5=8A=A9=E5=8A=9B=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E6=9F=A5=E8=AF=A2=E5=A2=9E=E5=8A=A0=E5=AE=9D=E7=AE=B1?= =?UTF-8?q?=E6=89=80=E6=9C=89=E8=80=85=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/uaw.md | 17 +++++++++--- initdatas/activity_info.json | 18 +++++++++++++ src/controllers/chest.controller.ts | 42 +++++++++++++++++++++-------- src/plugins/apiauth.ts | 2 +- 4 files changed, 63 insertions(+), 16 deletions(-) diff --git a/docs/uaw.md b/docs/uaw.md index 0ac4f82..3a4ee09 100644 --- a/docs/uaw.md +++ b/docs/uaw.md @@ -34,6 +34,13 @@ 1. 增加接口:我的助力记录(27) 2. 所有带用户信息的接口增加返回avatar(头像)字段 + + +#### 20240411 + +1. 宝箱助力状态查询(26) 增加返回宝箱所有者信息 +2. + ### 1. 钱包预登录 #### Request @@ -734,7 +741,7 @@ body: ``` -### 26.\* 宝箱助力状态查询 +### 26.\ 宝箱助力状态查询 #### Request @@ -757,11 +764,13 @@ body: ```js { - userCurrent: 1, // 用户当日已助力次数 - userMax: 10, // 用户当日最大可助力次数 + userCurrent: 1, // 用户当日已助力次数, 未登录用户可能为空 + userMax: 10, // 用户当日最大可助力次数, 未登录用户可能为空 + enhanced: 0, // 用户是否已经为当前宝箱助力, 未登录用户可能为空 chestCurrent: 1, // 宝箱当前助力次数 chestMax: 10, // 宝箱最大可助力次数 - enhanced: 0, // 用户是否已经为当前宝箱助力 + nickname: '11', // 宝箱所有者昵称 + avatar: '', // 宝箱所有者头像, 可能为空 } ``` diff --git a/initdatas/activity_info.json b/initdatas/activity_info.json index 7d709ea..fead580 100644 --- a/initdatas/activity_info.json +++ b/initdatas/activity_info.json @@ -17,6 +17,7 @@ "start": "2024-01-01 00:00", "end": "2025-01-01 00:00", "checkChain": true, + "base": true, "params": {} }, { "id": "e2fclylj30vwcpe0szl", @@ -32,6 +33,23 @@ "start": "2024-01-01 00:00", "end": "2025-01-01 00:00", "checkChain": true, + "base": true, + "params": {"time": 6, "failRate": 0} + },{ + "id": "e2far3lj30vwcpe0mf8", + "task": "DiscordJoin", + "title": "Join Discord", + "type": 1, + "desc": "Join Counter Fire’s official Discord server", + "category": "Social Tasks", + "score": 100, + "autoclaim": false, + "pretasks": [], + "cfg": {"icon": "discord"}, + "start": "2024-01-01 00:00", + "end": "2025-01-01 00:00", + "checkChain": true, + "base": true, "params": {"time": 6, "failRate": 0} }, { "id": "e2feyflj30vwcpe0sjy", diff --git a/src/controllers/chest.controller.ts b/src/controllers/chest.controller.ts index 268e3dd..5c2cc97 100644 --- a/src/controllers/chest.controller.ts +++ b/src/controllers/chest.controller.ts @@ -124,6 +124,7 @@ class BoxController extends BaseController { /** * 宝箱助力状态查询 */ + @role(ROLE_ANON) @router('post /api/chest/enhance/state') async enhanceState(req) { const { code, chestId } = req.params @@ -141,7 +142,7 @@ class BoxController extends BaseController { if (chestId) { chest = await ActivityChest.findById(chestId) } else { - chest = await ActivityChest.findOne({ shareCode: code, activity: user.activity }) + chest = await ActivityChest.findOne({ shareCode: code }) } if (!chest) { throw new ZError(12, 'chest not found') @@ -152,17 +153,36 @@ class BoxController extends BaseController { if (chest.status === ChestStatusEnum.LOCKED) { throw new ZError(15, 'chest is locked') } - const enhanced = chest.bonusUsers.includes(user.id) ? 1 : 0 - const userMax = user.twitterId && user.discordId ? MAX_ENHANCE_COUNT_ADV : MAX_ENHANCE_COUNT_BASE - const dateTag = formatDate(new Date()) - const userCurrent = await ChestEnhanceRecord.countDocuments({ user: user.id, activity: user.activity, dateTag }) + const chestOwner = await ActivityUser.findById(chest.user) - return { - userCurrent, - userMax, - enhanced, - chestCurrent: chest.bonusUsers.length, - chestMax: chest.maxBounsCount, + if (user) { + const enhanced = chest.bonusUsers.includes(user.id) ? 1 : 0 + const userMax = user.twitterId && user.discordId ? MAX_ENHANCE_COUNT_ADV : MAX_ENHANCE_COUNT_BASE + const dateTag = formatDate(new Date()) + const userCurrent = await ChestEnhanceRecord.countDocuments({ user: user.id, activity: user.activity, dateTag }) + + return { + userCurrent, + userMax, + enhanced, + nickname: + chestOwner?.twitterName || chestOwner?.discordName || chestOwner?.address + ? formatAddress(chestOwner.address) + : 'unknown', + avatar: chestOwner?.twitterAvatar || '', + chestCurrent: chest.bonusUsers.length, + chestMax: chest.maxBounsCount, + } + } else { + return { + chestCurrent: chest.bonusUsers.length, + chestMax: chest.maxBounsCount, + nickname: + chestOwner?.twitterName || chestOwner?.discordName || chestOwner?.address + ? formatAddress(chestOwner.address) + : 'unknown', + avatar: chestOwner?.twitterAvatar || '', + } } } /** diff --git a/src/plugins/apiauth.ts b/src/plugins/apiauth.ts index 2acf45a..2292864 100644 --- a/src/plugins/apiauth.ts +++ b/src/plugins/apiauth.ts @@ -29,7 +29,7 @@ const apiAuthPlugin: FastifyPluginAsync = async function (fastif }) // 只有路由配置的role为anon才不需要过滤 fastify.decorate('apiAuth', async function (request: FastifyRequest, reply: FastifyReply) { - if (!request.roles || request.roles.indexOf(ROLE_ANON) == -1) { + if (!request.roles || request.roles.indexOf(ROLE_ANON) == -1 || request.token) { try { if (!request.token) { return reply.send({ errcode: 11, errmsg: 'need login' })