refactor(server): config system (#11081)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { defineRuntimeConfig, ModuleConfig } from '../../base/config';
|
||||
import { defineModuleConfig } from '../../base';
|
||||
|
||||
export interface VersionConfig {
|
||||
versionControl: {
|
||||
@@ -7,9 +7,9 @@ export interface VersionConfig {
|
||||
};
|
||||
}
|
||||
|
||||
declare module '../../base/config' {
|
||||
interface AppConfig {
|
||||
client: ModuleConfig<never, VersionConfig>;
|
||||
declare global {
|
||||
interface AppConfigSchema {
|
||||
client: VersionConfig;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ declare module '../../base/guard' {
|
||||
}
|
||||
}
|
||||
|
||||
defineRuntimeConfig('client', {
|
||||
defineModuleConfig('client', {
|
||||
'versionControl.enabled': {
|
||||
desc: 'Whether check version of client before accessing the server.',
|
||||
default: false,
|
||||
|
||||
@@ -6,9 +6,9 @@ import type {
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
import {
|
||||
Config,
|
||||
getRequestResponseFromContext,
|
||||
GuardProvider,
|
||||
Runtime,
|
||||
} from '../../base';
|
||||
import { VersionService } from './service';
|
||||
|
||||
@@ -20,14 +20,14 @@ export class VersionGuardProvider
|
||||
name = 'version' as const;
|
||||
|
||||
constructor(
|
||||
private readonly runtime: Runtime,
|
||||
private readonly config: Config,
|
||||
private readonly version: VersionService
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
||||
async canActivate(context: ExecutionContext) {
|
||||
if (!(await this.runtime.fetch('client/versionControl.enabled'))) {
|
||||
if (!this.config.client.versionControl.enabled) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,18 +1,16 @@
|
||||
import { Injectable, Logger } from '@nestjs/common';
|
||||
import semver from 'semver';
|
||||
|
||||
import { Runtime, UnsupportedClientVersion } from '../../base';
|
||||
import { Config, UnsupportedClientVersion } from '../../base';
|
||||
|
||||
@Injectable()
|
||||
export class VersionService {
|
||||
private readonly logger = new Logger(VersionService.name);
|
||||
|
||||
constructor(private readonly runtime: Runtime) {}
|
||||
constructor(private readonly config: Config) {}
|
||||
|
||||
async checkVersion(clientVersion?: string) {
|
||||
const requiredVersion = await this.runtime.fetch(
|
||||
'client/versionControl.requiredVersion'
|
||||
);
|
||||
const requiredVersion = this.config.client.versionControl.requiredVersion;
|
||||
|
||||
const range = await this.getVersionRange(requiredVersion);
|
||||
if (!range) {
|
||||
|
||||
Reference in New Issue
Block a user