diff --git a/src/webui/src/api/OB11Config.ts b/src/webui/src/api/OB11Config.ts index 85320a82..bfbd3e17 100644 --- a/src/webui/src/api/OB11Config.ts +++ b/src/webui/src/api/OB11Config.ts @@ -6,19 +6,19 @@ import { OB11Config } from "@/webui/ui/components/WebApi"; const isEmpty = (data: any) => data === undefined || data === null || data === ''; export const OB11GetConfigHandler: RequestHandler = async (req, res) => { let isLogin = await DataRuntime.getQQLoginStatus(); - if (!isLogin) { - res.send({ - code: -1, - message: 'Not Login' - }); - return; - } + // if (!isLogin) { + // res.send({ + // code: -1, + // message: 'Not Login' + // }); + // return; + // } const uin = await DataRuntime.getQQLoginUin(); - let configFilePath = resolve(__dirname, `./config/onebot_${uin}.json`); - console.log(configFilePath); + let configFilePath = resolve(__dirname, `./config/onebot11_${uin}.json`); + //console.log(configFilePath); let data: OB11Config; try { - data = JSON.parse(existsSync(configFilePath) ? readFileSync(configFilePath).toString() : readFileSync(resolve(__dirname, `./config/onebot.json`)).toString()); + data = JSON.parse(existsSync(configFilePath) ? readFileSync(configFilePath).toString() : readFileSync(resolve(__dirname, `./config/onebot11.json`)).toString()); } catch (e) { data = {} as OB11Config; diff --git a/src/webui/ui/helper/Config.ts b/src/webui/ui/helper/Config.ts new file mode 100644 index 00000000..62b9d1a6 --- /dev/null +++ b/src/webui/ui/helper/Config.ts @@ -0,0 +1,45 @@ +import { OB11Config } from "../components/WebApi"; + + +class WebUiApiOB11ConfigWrapper { + private retCredential: string = ""; + async Init(Credential: string) { + this.retCredential = Credential; + } + async GetConfig(): Promise { + let ConfigResponse = await fetch('/api/OB11Config/GetConfig', { + method: 'POST', + headers: { + 'Authorization': "Bearer " + this.retCredential, + 'Content-Type': 'application/json' + } + }); + if (ConfigResponse.status == 200) { + let ConfigResponseJson = await ConfigResponse.json(); + if (ConfigResponseJson.code == 0) { + return ConfigResponseJson?.data; + } + } + return {} as OB11Config; + } + async SetConfig(config: OB11Config): Promise { + let ConfigResponse = await fetch('/api/OB11Config/SetConfig', + { + method: 'POST', + headers: { + 'Authorization': "Bearer " + this.retCredential, + 'Content-Type': 'application/json' + }, + body: JSON.stringify(config) + } + ); + if (ConfigResponse.status == 200) { + let ConfigResponseJson = await ConfigResponse.json(); + if (ConfigResponseJson.code == 0) { + return true; + } + } + return false; + } +} +export const OB11ConfigWrapper = new WebUiApiOB11ConfigWrapper(); \ No newline at end of file