From 18be379d7f66e4f2c5daa728bc67cdec5db34ed7 Mon Sep 17 00:00:00 2001 From: limbo <43649186+HUAHUAI23@users.noreply.github.com> Date: Tue, 12 Sep 2023 17:16:18 +0800 Subject: [PATCH] fix(server): add the user quota setting during initialization. (#1528) * add necessary settings * chore --- server/src/initializer/initializer.service.ts | 45 +++++++++++-------- server/src/setting/entities/setting.ts | 1 + server/src/user/quota.service.ts | 3 +- 3 files changed, 30 insertions(+), 19 deletions(-) diff --git a/server/src/initializer/initializer.service.ts b/server/src/initializer/initializer.service.ts index 6862b0a473..cddd78bf72 100644 --- a/server/src/initializer/initializer.service.ts +++ b/server/src/initializer/initializer.service.ts @@ -26,6 +26,7 @@ export class InitializerService { await this.createDefaultResourceOptions() await this.createDefaultResourceBundles() await this.createDefaultSettings() + await this.createNecessarySettings() } async createDefaultRegion() { @@ -346,32 +347,16 @@ export class InitializerService { return } - await this.db.collection('Setting').insertOne({ - public: false, - key: 'resource_limit', - value: 'default', - desc: 'resource limit of user', - metadata: { - limitOfCPU: 20000, - limitOfMemory: 20480, - limitCountOfApplication: 20, - limitOfDatabaseSyncCount: { - countLimit: 10, - timePeriodInSeconds: 86400, - }, - }, - }) - await this.db.collection('Setting').insertOne({ public: true, - key: 'invitation_profit', + key: SettingKey.InvitationProfit, value: '0', desc: 'Set up invitation rebate', }) await this.db.collection('Setting').insertOne({ public: true, - key: 'id_verify', + key: SettingKey.IdVerify, value: 'off', // on | off desc: 'real name authentication', metadata: { @@ -422,4 +407,28 @@ export class InitializerService { this.logger.verbose('Created default settings') } + + async createNecessarySettings() { + const find = await this.db + .collection('Setting') + .findOne({ key: SettingKey.DefaultUserQuota }) + + if (!find) { + await this.db.collection('Setting').insertOne({ + public: false, + key: SettingKey.DefaultUserQuota, + value: 'default', + desc: 'resource limit of user', + metadata: { + limitOfCPU: 20000, + limitOfMemory: 20480, + limitCountOfApplication: 20, + limitOfDatabaseSyncCount: { + countLimit: 10, + timePeriodInSeconds: 86400, + }, + }, + }) + } + } } diff --git a/server/src/setting/entities/setting.ts b/server/src/setting/entities/setting.ts index e16abee4fe..739557300d 100644 --- a/server/src/setting/entities/setting.ts +++ b/server/src/setting/entities/setting.ts @@ -12,6 +12,7 @@ export enum SettingKey { SiteFooter = 'site_footer', InvitationProfit = 'invitation_profit', IdVerify = 'id_verify', + DefaultUserQuota = 'default_user_quota', AiPilotUrl = 'ai_pilot_url', LafForumUrl = 'laf_forum_url', diff --git a/server/src/user/quota.service.ts b/server/src/user/quota.service.ts index 741624783e..54b85cd9e6 100644 --- a/server/src/user/quota.service.ts +++ b/server/src/user/quota.service.ts @@ -6,6 +6,7 @@ import { SystemDatabase } from 'src/system-database' import { UserQuota } from './entities/user-quota' import { SettingService } from 'src/setting/setting.service' import { DatabaseSyncRecord } from 'src/database/entities/database-sync-record' +import { SettingKey } from 'src/setting/entities/setting' @Injectable() export class QuotaService { @@ -87,7 +88,7 @@ export class QuotaService { async getUserQuota(uid: ObjectId) { const defaultUserQuotaSetting = await this.settingService.findOne( - 'resource_limit', + SettingKey.DefaultUserQuota, ) if (!defaultUserQuotaSetting) {