From a0d780558ed3ea6de6097218cb466d3b8d89904a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=89=8B=E7=93=9C=E4=B8=80=E5=8D=81=E9=9B=AA?= Date: Wed, 5 Feb 2025 19:01:14 +0800 Subject: [PATCH] fix --- src/framework/napcat.cjs | 1 - src/onebot/config/index.ts | 2 +- src/webui/src/api/OB11Config.ts | 26 ++++++++++++++------------ 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/framework/napcat.cjs b/src/framework/napcat.cjs index e5f2424a..eee4a8e4 100644 --- a/src/framework/napcat.cjs +++ b/src/framework/napcat.cjs @@ -15,7 +15,6 @@ let napCatInitialized = false; // 添加一个标志 function createServiceProxy(ServiceName) { return new Proxy(() => { }, { get: (target, FunctionName) => { - console.log(ServiceName, FunctionName); if (ServiceName === 'NodeIQQNTWrapperSession' && FunctionName === 'create') { return () => new Proxy({}, { get: function (target, ClassFunName, receiver) { diff --git a/src/onebot/config/index.ts b/src/onebot/config/index.ts index db81dcdb..2c1f8221 100644 --- a/src/onebot/config/index.ts +++ b/src/onebot/config/index.ts @@ -1,5 +1,5 @@ import { ConfigBase } from '@/common/config-base'; -import { NapCatCore } from '@/core'; +import type { NapCatCore } from '@/core'; import { OneBotConfig } from './config'; import { AnySchema } from 'ajv'; diff --git a/src/webui/src/api/OB11Config.ts b/src/webui/src/api/OB11Config.ts index f1b8985a..1670761d 100644 --- a/src/webui/src/api/OB11Config.ts +++ b/src/webui/src/api/OB11Config.ts @@ -1,13 +1,12 @@ import { RequestHandler } from 'express'; import { existsSync, readFileSync } from 'node:fs'; import { resolve } from 'node:path'; - -import { OneBotConfig } from '@/onebot/config/config'; - +import { loadConfig, OneBotConfig } from '@/onebot/config/config'; import { webUiPathWrapper } from '@/webui'; import { WebUiDataRuntime } from '@webapi/helper/Data'; import { sendError, sendSuccess } from '@webapi/utils/response'; import { isEmpty } from '@webapi/utils/check'; +import json5 from 'json5'; // 获取OneBot11配置 export const OB11GetConfigHandler: RequestHandler = (_, res) => { @@ -19,16 +18,16 @@ export const OB11GetConfigHandler: RequestHandler = (_, res) => { } // 获取登录的QQ号 const uin = WebUiDataRuntime.getQQLoginUin(); - // 读取配置文件 + // 读取配置文件路径 const configFilePath = resolve(webUiPathWrapper.configPath, `./onebot11_${uin}.json`); // 尝试解析配置文件 try { - // 读取配置文件 - const data = JSON.parse( - existsSync(configFilePath) - ? readFileSync(configFilePath).toString() - : readFileSync(resolve(webUiPathWrapper.configPath, './onebot11.json')).toString() - ) as OneBotConfig; + // 读取配置文件内容 + const configFileContent = existsSync(configFilePath) + ? readFileSync(configFilePath).toString() + : readFileSync(resolve(webUiPathWrapper.configPath, './onebot11.json')).toString(); + // 解析配置文件并加载配置 + const data = loadConfig(json5.parse(configFileContent)) as OneBotConfig; // 返回配置文件 return sendSuccess(res, data); } catch (e) { @@ -50,9 +49,12 @@ export const OB11SetConfigHandler: RequestHandler = async (req, res) => { } // 写入配置 try { - await WebUiDataRuntime.setOB11Config(JSON.parse(req.body.config)); + // 解析并加载配置 + const config = loadConfig(json5.parse(req.body.config)) as OneBotConfig; + // 写入配置 + await WebUiDataRuntime.setOB11Config(config); return sendSuccess(res, null); } catch (e) { return sendError(res, 'Error: ' + e); } -}; +}; \ No newline at end of file