Skip to content

Commit

Permalink
为新注册用户设置全局初始次数,并且同步全局次数限制的开关 (#478)
Browse files Browse the repository at this point in the history
* add globalUseAmout & fix uselimit to New User,

* normalize

* fix: formatting

* fix: globalAmount use number type

Signed-off-by: Bob Du <[email protected]>

---------

Signed-off-by: Bob Du <[email protected]>
Co-authored-by: root <[email protected]>
Co-authored-by: Bob Du <[email protected]>
  • Loading branch information
3 people authored Mar 20, 2024
1 parent 7260934 commit 7e195d1
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 6 deletions.
1 change: 1 addition & 0 deletions service/src/storage/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ export class SiteConfig {
public registerMails?: string,
public siteDomain?: string,
public chatModels?: string,
public globalAmount?: number,
public usageCountLimit?: boolean,
) { }
}
Expand Down
10 changes: 8 additions & 2 deletions service/src/storage/mongo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,15 +251,21 @@ export async function deleteChat(roomId: number, uuid: number, inversion: boolea
export async function createUser(email: string, password: string, roles?: UserRole[], status?: Status, remark?: string, useAmount?: number, limit_switch?: boolean): Promise<UserInfo> {
email = email.toLowerCase()
const userInfo = new UserInfo(email, password)
const config = await getCacheConfig()

if (roles && roles.includes(UserRole.Admin))
userInfo.status = Status.Normal
if (status)
userInfo.status = status

userInfo.roles = roles
userInfo.remark = remark
userInfo.useAmount = useAmount
userInfo.limit_switch = limit_switch
if (limit_switch != null)
userInfo.limit_switch = limit_switch
if (useAmount != null)
userInfo.useAmount = useAmount
else
userInfo.useAmount = config?.siteConfig?.globalAmount ?? 10
await userCol.insertOne(userInfo)
return userInfo
}
Expand Down
16 changes: 12 additions & 4 deletions src/components/common/Setting/Site.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang='ts'>
import { onMounted, ref } from 'vue'
import { NButton, NInput, NSpin, NSwitch, useMessage } from 'naive-ui'
import { NButton, NInput, NInputNumber, NSpin, NSwitch, useMessage } from 'naive-ui'
import type { ConfigState } from './model'
import { SiteConfig } from './model'
import { fetchChatConfig, fetchUpdateSite } from '@/api'
Expand All @@ -11,14 +11,13 @@ const ms = useMessage()
const loading = ref(false)
const saving = ref(false)
const config = ref<SiteConfig>()
config.value = new SiteConfig()
const config = ref(new SiteConfig())
async function fetchConfig() {
try {
loading.value = true
const { data } = await fetchChatConfig<ConfigState>()
config.value = data.siteConfig
config.value = data.siteConfig ? data.siteConfig : new SiteConfig()
}
finally {
loading.value = false
Expand Down Expand Up @@ -129,6 +128,15 @@ onMounted(() => {
/>
</div>
</div>
<!-- 增加新注册用户的全局数量设置 -->
<div class="flex items-center space-x-4">
<span class="flex-shrink-0 w-[100px]">{{ $t('setting.globalAmount') }}</span>
<div class="flex-1">
<NInputNumber
v-model:value="config.globalAmount" placeholder=""
/>
</div>
</div>
<div class="flex items-center space-x-4">
<span class="flex-shrink-0 w-[100px]">{{ $t('setting.usageCountLimit') }}</span>
<div class="flex-1">
Expand Down
1 change: 1 addition & 0 deletions src/components/common/Setting/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export class SiteConfig {
registerMails?: string
siteDomain?: string
chatModels?: string
globalAmount?: number
usageCountLimit?: boolean
}

Expand Down
1 change: 1 addition & 0 deletions src/locales/en-US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export default {
disable2FAConfirm: 'Are you sure to disable 2FA for this user?',
},
setting: {
globalAmount: 'Global Usage Amount for New User',
limit_switch: 'Open Usage Limitation',
usageCountLimit: 'Enable Usage Count Limit',
redeemCardNo: 'Redeem CardNo',
Expand Down
1 change: 1 addition & 0 deletions src/locales/ko-KR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export default {
disable2FAConfirm: 'Are you sure to disable 2FA for this user?',
},
setting: {
globalAmount: 'Global Usage Amount for New User',
limit_switch: '오픈 횟수 제한',
redeemCardNo: '질문 허용 횟수',
useAmount: '질문 허용 횟수',
Expand Down
1 change: 1 addition & 0 deletions src/locales/zh-CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export default {
disable2FAConfirm: '您确定要为此用户禁用两步验证吗??',
},
setting: {
globalAmount: '新用户全局次数设置',
limit_switch: '打开次数限制',
usageCountLimit: '使用次数限制',
redeemCardNo: '兑换码卡号',
Expand Down
1 change: 1 addition & 0 deletions src/locales/zh-TW.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export default {
disable2FAConfirm: '您确定要为此用户禁用两步验证吗??',
},
setting: {
globalAmount: '新用户全局次数设置',
limit_switch: '開啟次數限制',
redeemCardNo: '兌換碼卡號',
useAmount: '可提問次數',
Expand Down

0 comments on commit 7e195d1

Please sign in to comment.