diff --git a/initdatas/activity_info.json b/initdatas/activity_info.json index f5d2336..496bad4 100644 --- a/initdatas/activity_info.json +++ b/initdatas/activity_info.json @@ -51,7 +51,7 @@ },{ "id": "e2far3lj30vwcpe0mf8", "task": "DiscordJoin", - "title": "Join Discord", + "title": "Join Counter Fire Discord", "type": 1, "desc": "Join Counter Fire’s official Discord server", "category": "Social Tasks", @@ -66,7 +66,7 @@ }, { "id": "e2fuah0j30vwcpe0my7", "task": "TwitterRetweet", - "title": "Retweet on X", + "title": "Retweet a tweet", "type": 1, "desc": "Retweet specific tweets", "category": "Social Tasks", @@ -81,7 +81,7 @@ }, { "id": "e2fuah0j30vwcpe0my9", "task": "TwitterLike", - "title": "Like the tweets on X", + "title": "Like a tweet", "type": 1, "desc": "Like specific tweets", "category": "Social Tasks", diff --git a/package.json b/package.json index 19902a5..c114ba2 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ "fastify-xml-body-parser": "^2.2.0", "mongodb-extended-json": "^1.11.1", "mongoose": "8.2.3", - "nanoid": "^5.0.7", + "nanoid": "^3.1.23", "node-schedule": "^2.0.0", "siwe": "^2.1.4", "tracer": "^1.1.6", diff --git a/src/controllers/voucher.controller.ts b/src/controllers/voucher.controller.ts index 4cf12c4..f6c2d9b 100644 --- a/src/controllers/voucher.controller.ts +++ b/src/controllers/voucher.controller.ts @@ -1,9 +1,9 @@ -import { isValidShareCode, isValidVoucherCode } from 'common/Utils' +import { isValidVoucherCode } from 'common/Utils' import logger from 'logger/logger' import { ChestStatusEnum } from 'models/ActivityChest' import { SourceEnum, VoucherRecord, VoucherStatusEnum } from 'models/VoucherRecord' import { generateNewChest } from 'services/game.svr' -import { SyncLocker, BaseController, router, role, ROLE_ANON, ZError } from 'zutils' +import { SyncLocker, BaseController, router, ZError } from 'zutils' import { customAlphabet } from 'nanoid' import { BASE52_ALPHABET } from 'common/Constants' /** @@ -13,7 +13,7 @@ class VoucherController extends BaseController { @router('post /api/voucher/generate') async generateTestVoucher(req) { logger.db('generate_test_voucher', req) - if (process.env.NODE_ENV !== 'development') { + if (process.env.NODE_ENV === 'production') { throw new ZError(10, 'only support in development') } const user = req.user @@ -25,6 +25,12 @@ class VoucherController extends BaseController { const nanoid = customAlphabet(BASE52_ALPHABET, 8) for (let i = 0; i < num; i++) { let code = 'test' + nanoid() + // check if code exists + let record = await VoucherRecord.findOne({ code }) + if (record) { + i-- + continue + } let voucher = new VoucherRecord({ batch: 'test', code, @@ -38,7 +44,7 @@ class VoucherController extends BaseController { creator: user.id, }) await voucher.save() - results.push(voucher.id) + results.push(voucher.code) } return results } diff --git a/src/models/VoucherRecord.ts b/src/models/VoucherRecord.ts index 5d93d3b..af89cba 100644 --- a/src/models/VoucherRecord.ts +++ b/src/models/VoucherRecord.ts @@ -23,12 +23,12 @@ export enum SourceEnum { @index({ user: 1, activity: 1 }, { unique: false }) @index({ code: 1, activity: 1 }, { unique: true }) @modelOptions({ - schemaOptions: { collection: 'activity_box', timestamps: true }, + schemaOptions: { collection: 'voucher_record', timestamps: true }, options: { allowMixed: Severity.ALLOW }, }) export class VoucherRecordClass extends BaseModule { @prop() - public batch: number + public batch: string @prop() public code: string // 0 锁定, 1 未发放 2 已发放,待使用 9 已兑换 diff --git a/yarn.lock b/yarn.lock index b4f3f51..a98f07f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3317,10 +3317,10 @@ nano-json-stream-parser@^0.1.2: resolved "https://registry.npmjs.org/nano-json-stream-parser/-/nano-json-stream-parser-0.1.2.tgz" integrity sha512-9MqxMH/BSJC7dnLsEMPyfN5Dvoo49IsPFYMcHw3Bcfc2kN0lpHRBSzlMSVx4HGyJ7s9B31CyBTVehWJoQ8Ctew== -nanoid@^5.0.7: - version "5.0.7" - resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-5.0.7.tgz#6452e8c5a816861fd9d2b898399f7e5fd6944cc6" - integrity sha512-oLxFY2gd2IqnjcYyOXD8XGCftpGtZP2AbHbOkthDkvRywH5ayNtPVy9YlOPcHckXzbLTCHpkb7FB+yuxKV13pQ== +nanoid@^3.1.23: + version "3.3.7" + resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.3.7.tgz#d0c301a691bc8d54efa0a2226ccf3fe2fd656bd8" + integrity sha512-eSRppjcPIatRIMC1U6UngP8XFcz8MQWGQdt1MTBQ7NaAmvXDfvNxbvWV3x2y6CdEUciCSsDHDQZbhYaB8QEo2g== natural-compare@^1.4.0: version "1.4.0"