refactor(server): config system (#11081)

This commit is contained in:
forehalo
2025-03-27 12:32:28 +00:00
parent 7091111f85
commit 0ea38680fa
274 changed files with 7583 additions and 5841 deletions

View File

@@ -1,6 +1,6 @@
import { Injectable, Logger } from '@nestjs/common';
import { Runtime } from '../../base';
import { Config } from '../../base';
import { Models } from '../../models';
const STAFF = ['@toeverything.info', '@affine.pro'];
@@ -15,8 +15,8 @@ export class FeatureService {
protected logger = new Logger(FeatureService.name);
constructor(
private readonly models: Models,
private readonly runtime: Runtime
private readonly config: Config,
private readonly models: Models
) {}
// ======== Admin ========
@@ -73,9 +73,7 @@ export class FeatureService {
email: string,
type: EarlyAccessType = EarlyAccessType.App
) {
const earlyAccessControlEnabled = await this.runtime.fetch(
'flags/earlyAccessControl'
);
const earlyAccessControlEnabled = this.config.flags.earlyAccessControl;
if (earlyAccessControlEnabled && !this.isStaff(email)) {
const user = await this.models.user.getUserByEmail(email);

View File

@@ -1,12 +1,9 @@
import { Inject, Injectable } from '@nestjs/common';
import { Injectable } from '@nestjs/common';
import { Config } from '../../base';
import { Feature, UserFeatureName } from '../../models';
@Injectable()
export class AvailableUserFeatureConfig {
@Inject(Config) private readonly config!: Config;
availableUserFeatures(): Set<UserFeatureName> {
return new Set([
Feature.Admin,
@@ -18,7 +15,7 @@ export class AvailableUserFeatureConfig {
configurableUserFeatures(): Set<UserFeatureName> {
return new Set(
this.config.isSelfhosted
env.selfhosted
? [Feature.Admin, Feature.UnlimitedCopilot]
: [
Feature.EarlyAccess,