diff --git a/service/src/index.ts b/service/src/index.ts index c749522e..5fec3044 100644 --- a/service/src/index.ts +++ b/service/src/index.ts @@ -11,7 +11,7 @@ import type { ChatMessage } from './chatgpt' import { abortChatProcess, chatConfig, chatReplyProcess, containsSensitiveWords, initAuditService } from './chatgpt' import { auth, getUserId } from './middleware/auth' import { clearApiKeyCache, clearConfigCache, getApiKeys, getCacheApiKeys, getCacheConfig, getOriginConfig } from './storage/config' -import type { AnnounceConfig, AuditConfig, ChatInfo, ChatOptions, Config, KeyConfig, MailConfig, SiteConfig, UserConfig, UserInfo } from './storage/model' +import type { AnnounceConfig, AuditConfig, ChatInfo, ChatOptions, Config, GiftCard, KeyConfig, MailConfig, SiteConfig, UserConfig, UserInfo } from './storage/model' import { AdvancedConfig, Status, UsageResponse, UserRole } from './storage/model' import { clearChat, @@ -39,6 +39,7 @@ import { updateChat, updateConfig, updateGiftCard, + updateGiftCards, updateRoomChatModel, updateRoomPrompt, updateRoomUsingContext, @@ -888,6 +889,18 @@ router.post('/redeem-card', auth, async (req, res) => { } }) +// update giftcard database +router.post('/giftcard-update', rootAuth, async (req, res) => { + try { + const { data, overRideSwitch } = req.body as { data: GiftCard[];overRideSwitch: boolean } + await updateGiftCards(data, overRideSwitch) + res.send({ status: 'Success', message: '更新成功 | Update successfully' }) + } + catch (error) { + res.send({ status: 'Fail', message: error.message, data: null }) + } +}) + router.post('/user-chat-model', auth, async (req, res) => { try { const { chatModel } = req.body as { chatModel: string } diff --git a/service/src/storage/mongo.ts b/service/src/storage/mongo.ts index 760c2d86..5803ad21 100644 --- a/service/src/storage/mongo.ts +++ b/service/src/storage/mongo.ts @@ -67,6 +67,17 @@ export async function updateAmountMinusOne(userId: string) { return result.modifiedCount > 0 } +// update giftcards database +export async function updateGiftCards(data: GiftCard[], overRide = true) { + if (overRide) { + // i am not sure is there a drop option for the node driver reference https://mongodb.github.io/node-mongodb-native/6.4/ + // await redeemCol.deleteMany({}) + await redeemCol.drop() + } + const insertResult = await redeemCol.insertMany(data) + return insertResult +} + export async function insertChat(uuid: number, text: string, images: string[], roomId: number, options?: ChatOptions) { const chatInfo = new ChatInfo(roomId, uuid, text, images, options) await chatCol.insertOne(chatInfo) diff --git a/src/api/index.ts b/src/api/index.ts index 08c1413f..2a9a2e2c 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -1,6 +1,6 @@ import type { AxiosProgressEvent, GenericAbortSignal } from 'axios' import { get, post } from '@/utils/request' -import type { AnnounceConfig, AuditConfig, ConfigState, KeyConfig, MailConfig, SiteConfig, Status, UserInfo, UserPassword } from '@/components/common/Setting/model' +import type { AnnounceConfig, AuditConfig, ConfigState, GiftCard, KeyConfig, MailConfig, SiteConfig, Status, UserInfo, UserPassword } from '@/components/common/Setting/model' import { useAuthStore, useUserStore } from '@/store' import type { SettingsState } from '@/store/modules/user/helper' @@ -153,6 +153,13 @@ export function decode_redeemcard(redeemCardNo: string) { }) } +export function fetchUpdateGiftCards(data: GiftCard[], overRideSwitch: boolean) { + return post({ + url: '/giftcard-update', + data: { data, overRideSwitch }, + }) +} + export function fetchUpdateUserChatModel(chatModel: string) { return post({ url: '/user-chat-model', diff --git a/src/components/common/Setting/Gift.vue b/src/components/common/Setting/Gift.vue new file mode 100644 index 00000000..fbe79675 --- /dev/null +++ b/src/components/common/Setting/Gift.vue @@ -0,0 +1,163 @@ + + + diff --git a/src/components/common/Setting/index.vue b/src/components/common/Setting/index.vue index 4ea21ebb..6247ebd2 100644 --- a/src/components/common/Setting/index.vue +++ b/src/components/common/Setting/index.vue @@ -8,6 +8,7 @@ import About from './About.vue' import Site from './Site.vue' import Mail from './Mail.vue' import Audit from './Audit.vue' +import Gift from './Gift.vue' import User from './User.vue' import Key from './Keys.vue' import Password from './Password.vue' @@ -141,6 +142,13 @@ const show = computed({ + + + + diff --git a/src/components/common/Setting/model.ts b/src/components/common/Setting/model.ts index 12d0b0df..e8bcd5b1 100644 --- a/src/components/common/Setting/model.ts +++ b/src/components/common/Setting/model.ts @@ -162,3 +162,9 @@ export class TwoFAConfig { this.testCode = '' } } + +export interface GiftCard { + cardno: string + amount: number + redeemed: number +} diff --git a/src/locales/en-US.ts b/src/locales/en-US.ts index bb9255fc..bee0b88c 100644 --- a/src/locales/en-US.ts +++ b/src/locales/en-US.ts @@ -80,6 +80,8 @@ export default { disable2FAConfirm: 'Are you sure to disable 2FA for this user?', }, setting: { + overRide: 'Enable Override', + uploadgifts: 'Upload Redemption Code', announceConfig: 'Announcement', announceEnabled: 'Open Announcement', announceWords: 'Announcement Content', diff --git a/src/locales/ko-KR.ts b/src/locales/ko-KR.ts index 5fc09114..2aaeb4fe 100644 --- a/src/locales/ko-KR.ts +++ b/src/locales/ko-KR.ts @@ -80,6 +80,8 @@ export default { disable2FAConfirm: 'Are you sure to disable 2FA for this user?', }, setting: { + overRide: '덮어쓰기 활성화', + uploadgifts: '교환 코드 업로드', announceConfig: '网站公告', announceEnabled: 'Open Announcement', announceWords: 'Announcement Content', diff --git a/src/locales/zh-CN.ts b/src/locales/zh-CN.ts index c09626af..a7929199 100644 --- a/src/locales/zh-CN.ts +++ b/src/locales/zh-CN.ts @@ -80,6 +80,8 @@ export default { disable2FAConfirm: '您确定要为此用户禁用两步验证吗??', }, setting: { + overRide: '开启覆写', + uploadgifts: '上传兑换码', announceConfig: '网站公告', announceEnabled: '公告开关', announceWords: '公告内容', diff --git a/src/locales/zh-TW.ts b/src/locales/zh-TW.ts index eeae36ca..8947d95b 100644 --- a/src/locales/zh-TW.ts +++ b/src/locales/zh-TW.ts @@ -80,6 +80,8 @@ export default { disable2FAConfirm: '您确定要为此用户禁用两步验证吗??', }, setting: { + overRide: '開啟覆寫', + uploadgifts: '上傳兌換碼', announceConfig: '网站公告', announceEnabled: '打开公告', announceWords: '公告内容',