Skip to content

Commit 18be379

Browse files
authored
fix(server): add the user quota setting during initialization. (#1528)
* add necessary settings * chore
1 parent b00225f commit 18be379

File tree

3 files changed

+30
-19
lines changed

3 files changed

+30
-19
lines changed

server/src/initializer/initializer.service.ts

+27-18
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export class InitializerService {
2626
await this.createDefaultResourceOptions()
2727
await this.createDefaultResourceBundles()
2828
await this.createDefaultSettings()
29+
await this.createNecessarySettings()
2930
}
3031

3132
async createDefaultRegion() {
@@ -346,32 +347,16 @@ export class InitializerService {
346347
return
347348
}
348349

349-
await this.db.collection<Setting>('Setting').insertOne({
350-
public: false,
351-
key: 'resource_limit',
352-
value: 'default',
353-
desc: 'resource limit of user',
354-
metadata: {
355-
limitOfCPU: 20000,
356-
limitOfMemory: 20480,
357-
limitCountOfApplication: 20,
358-
limitOfDatabaseSyncCount: {
359-
countLimit: 10,
360-
timePeriodInSeconds: 86400,
361-
},
362-
},
363-
})
364-
365350
await this.db.collection<Setting>('Setting').insertOne({
366351
public: true,
367-
key: 'invitation_profit',
352+
key: SettingKey.InvitationProfit,
368353
value: '0',
369354
desc: 'Set up invitation rebate',
370355
})
371356

372357
await this.db.collection<Setting>('Setting').insertOne({
373358
public: true,
374-
key: 'id_verify',
359+
key: SettingKey.IdVerify,
375360
value: 'off', // on | off
376361
desc: 'real name authentication',
377362
metadata: {
@@ -422,4 +407,28 @@ export class InitializerService {
422407

423408
this.logger.verbose('Created default settings')
424409
}
410+
411+
async createNecessarySettings() {
412+
const find = await this.db
413+
.collection<Setting>('Setting')
414+
.findOne({ key: SettingKey.DefaultUserQuota })
415+
416+
if (!find) {
417+
await this.db.collection<Setting>('Setting').insertOne({
418+
public: false,
419+
key: SettingKey.DefaultUserQuota,
420+
value: 'default',
421+
desc: 'resource limit of user',
422+
metadata: {
423+
limitOfCPU: 20000,
424+
limitOfMemory: 20480,
425+
limitCountOfApplication: 20,
426+
limitOfDatabaseSyncCount: {
427+
countLimit: 10,
428+
timePeriodInSeconds: 86400,
429+
},
430+
},
431+
})
432+
}
433+
}
425434
}

server/src/setting/entities/setting.ts

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export enum SettingKey {
1212
SiteFooter = 'site_footer',
1313
InvitationProfit = 'invitation_profit',
1414
IdVerify = 'id_verify',
15+
DefaultUserQuota = 'default_user_quota',
1516

1617
AiPilotUrl = 'ai_pilot_url',
1718
LafForumUrl = 'laf_forum_url',

server/src/user/quota.service.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { SystemDatabase } from 'src/system-database'
66
import { UserQuota } from './entities/user-quota'
77
import { SettingService } from 'src/setting/setting.service'
88
import { DatabaseSyncRecord } from 'src/database/entities/database-sync-record'
9+
import { SettingKey } from 'src/setting/entities/setting'
910

1011
@Injectable()
1112
export class QuotaService {
@@ -87,7 +88,7 @@ export class QuotaService {
8788

8889
async getUserQuota(uid: ObjectId) {
8990
const defaultUserQuotaSetting = await this.settingService.findOne(
90-
'resource_limit',
91+
SettingKey.DefaultUserQuota,
9192
)
9293

9394
if (!defaultUserQuotaSetting) {

0 commit comments

Comments
 (0)