From 37d03547514d1eed10e4e5606d2ae0e2b0eb61e3 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: Tue, 7 May 2024 19:48:25 +0800 Subject: [PATCH] feat: webui OB11Config --- src/webui/src/api/OB11Config.ts | 23 +++++++++++++++++++++++ src/webui/src/helper/Data.ts | 11 ++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/webui/src/api/OB11Config.ts b/src/webui/src/api/OB11Config.ts index 9c60a395..d1f371b9 100644 --- a/src/webui/src/api/OB11Config.ts +++ b/src/webui/src/api/OB11Config.ts @@ -1,7 +1,30 @@ import { RequestHandler } from "express"; import { DataRuntime } from "../helper/Data"; +import { existsSync } from "node:fs"; +import { resolve } from "node:path"; +import { OB11Config } from "@/webui/ui/components/WebApi"; const isEmpty = (data: any) => data === undefined || data === null || data === ''; export const OB11GetConfigHandler: RequestHandler = async (req, res) => { + const uin = await DataRuntime.getQQLoginUin(); + let configFilePath = resolve(__dirname, `./config/onebot_${uin}.json`); + let data: OB11Config; + try { + data = existsSync(configFilePath) ? require(configFilePath) : require(resolve(__dirname, `./config/onebot.json`)); + } + catch (e) { + data = {} as OB11Config; + res.send({ + code: -1, + message: 'QRCode Get Error' + }); + return; + } + res.send({ + code: 0, + message: 'success', + data: data + }); + return; } export const OB11SetConfigHandler: RequestHandler = async (req, res) => { } \ No newline at end of file diff --git a/src/webui/src/helper/Data.ts b/src/webui/src/helper/Data.ts index 1423b21f..5b1bdd13 100644 --- a/src/webui/src/helper/Data.ts +++ b/src/webui/src/helper/Data.ts @@ -2,7 +2,8 @@ let LoginRuntime = { LoginCurrentTime: Date.now(), LoginCurrentRate: 0, QQLoginStatus: false, //得去那边注册个回调刷新 - QQQRCodeURL: "" + QQQRCodeURL: "", + QQLoginUin: 0 } export const DataRuntime = { checkLoginRate: async function (RateLimit: number): Promise { @@ -32,4 +33,12 @@ export const DataRuntime = { getQQLoginQrcodeURL: async function (): Promise { return LoginRuntime.QQQRCodeURL; } + , + setQQLoginUin: async function (uin: number): Promise { + LoginRuntime.QQLoginUin = uin; + } + , + getQQLoginUin: async function (): Promise { + return LoginRuntime.QQLoginUin; + } } \ No newline at end of file