Skip to content

Commit

Permalink
fix(server): add the user quota setting during initialization. (labri…
Browse files Browse the repository at this point in the history
…ng#1528)

* add necessary settings

* chore
  • Loading branch information
HUAHUAI23 authored Sep 12, 2023
1 parent b00225f commit 18be379
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 19 deletions.
45 changes: 27 additions & 18 deletions server/src/initializer/initializer.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export class InitializerService {
await this.createDefaultResourceOptions()
await this.createDefaultResourceBundles()
await this.createDefaultSettings()
await this.createNecessarySettings()
}

async createDefaultRegion() {
Expand Down Expand Up @@ -346,32 +347,16 @@ export class InitializerService {
return
}

await this.db.collection<Setting>('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>('Setting').insertOne({
public: true,
key: 'invitation_profit',
key: SettingKey.InvitationProfit,
value: '0',
desc: 'Set up invitation rebate',
})

await this.db.collection<Setting>('Setting').insertOne({
public: true,
key: 'id_verify',
key: SettingKey.IdVerify,
value: 'off', // on | off
desc: 'real name authentication',
metadata: {
Expand Down Expand Up @@ -422,4 +407,28 @@ export class InitializerService {

this.logger.verbose('Created default settings')
}

async createNecessarySettings() {
const find = await this.db
.collection<Setting>('Setting')
.findOne({ key: SettingKey.DefaultUserQuota })

if (!find) {
await this.db.collection<Setting>('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,
},
},
})
}
}
}
1 change: 1 addition & 0 deletions server/src/setting/entities/setting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
3 changes: 2 additions & 1 deletion server/src/user/quota.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -87,7 +88,7 @@ export class QuotaService {

async getUserQuota(uid: ObjectId) {
const defaultUserQuotaSetting = await this.settingService.findOne(
'resource_limit',
SettingKey.DefaultUserQuota,
)

if (!defaultUserQuotaSetting) {
Expand Down

0 comments on commit 18be379

Please sign in to comment.