From ef4dee88869253fa5db49606eabd6198bd36642d Mon Sep 17 00:00:00 2001 From: "Wesley F. Young" Date: Mon, 12 Aug 2024 00:26:44 +0800 Subject: [PATCH] refactor: make ConfigBase abstract --- src/common/utils/ConfigBase.ts | 9 ++------- src/core/helper/config.ts | 4 +--- src/onebot/helper/config.ts | 4 +--- src/webui/src/helper/Data.ts | 4 ++-- 4 files changed, 6 insertions(+), 15 deletions(-) diff --git a/src/common/utils/ConfigBase.ts b/src/common/utils/ConfigBase.ts index 3e02fe99..a20bcf8e 100644 --- a/src/common/utils/ConfigBase.ts +++ b/src/common/utils/ConfigBase.ts @@ -2,17 +2,13 @@ import path from 'node:path'; import fs from 'node:fs'; import type { NapCatCore } from '@/core'; -export class ConfigBase { - name: string = this.getConfigName(); +export abstract class ConfigBase { + abstract name: string; pathName: string | null = null; // 本次读取的文件路径 coreContext: NapCatCore; configPath: string; configData: T = {} as T; - getConfigName() { - return this.constructor.name - } - constructor(coreContext: NapCatCore, configPath: string) { this.coreContext = coreContext; this.configPath = configPath; @@ -25,7 +21,6 @@ export class ConfigBase { return null; } - getConfigPath(pathName: string | undefined): string { const suffix = pathName ? `_${pathName}` : ''; const filename = `${this.name}${suffix}.json`; diff --git a/src/core/helper/config.ts b/src/core/helper/config.ts index 0468a015..8a36456c 100644 --- a/src/core/helper/config.ts +++ b/src/core/helper/config.ts @@ -11,7 +11,5 @@ export interface NapCatConfig { // eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging export class NapCatConfig extends ConfigBase { - getConfigName() { - return 'napcat'; - } + name = 'napcat'; } diff --git a/src/onebot/helper/config.ts b/src/onebot/helper/config.ts index a200c940..79a0c722 100644 --- a/src/onebot/helper/config.ts +++ b/src/onebot/helper/config.ts @@ -36,7 +36,5 @@ export interface OB11Config { // eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging export class OB11Config extends ConfigBase { - getConfigName() { - return 'onebot11'; - } + name = 'onebot11'; } diff --git a/src/webui/src/helper/Data.ts b/src/webui/src/helper/Data.ts index ae9d093e..e4becf01 100644 --- a/src/webui/src/helper/Data.ts +++ b/src/webui/src/helper/Data.ts @@ -1,5 +1,4 @@ -import { OB11Config } from "@/onebot/helper/config"; - +import { OB11Config } from '@/onebot/helper/config'; interface LoginRuntimeType { LoginCurrentTime: number; @@ -30,6 +29,7 @@ const LoginRuntime: LoginRuntimeType = { QQLoginList: [], }, }; + export const WebUiDataRuntime = { checkLoginRate: async function(RateLimit: number): Promise { LoginRuntime.LoginCurrentRate++;