fix:config

This commit is contained in:
手瓜一十雪
2024-05-08 18:45:45 +08:00
parent 4545d9285b
commit e5d3a8360c
4 changed files with 11 additions and 9 deletions

View File

@@ -1,5 +1,2 @@
{ # The Path of NapCatQQ
"port": 6099,//端口 Tiny WebUi for NapCatQQ
"token": "123456",//密码
"loginRate": 3//速率
}

View File

@@ -2,7 +2,7 @@ import { RequestHandler } from "express";
import { DataRuntime } from "../helper/Data"; import { DataRuntime } from "../helper/Data";
import { existsSync, readFileSync, writeFileSync } from "node:fs"; import { existsSync, readFileSync, writeFileSync } from "node:fs";
import { resolve } from "node:path"; import { resolve } from "node:path";
import { OB11Config } from "@/webui/ui/components/WebApi"; import { OB11Config } from "@/webui/ui/components/WebUiApiOB11Config";
const isEmpty = (data: any) => data === undefined || data === null || data === ''; const isEmpty = (data: any) => data === undefined || data === null || data === '';
export const OB11GetConfigHandler: RequestHandler = async (req, res) => { export const OB11GetConfigHandler: RequestHandler = async (req, res) => {
let isLogin = await DataRuntime.getQQLoginStatus(); let isLogin = await DataRuntime.getQQLoginStatus();
@@ -53,12 +53,13 @@ export const OB11SetConfigHandler: RequestHandler = async (req, res) => {
} }
let configFilePath = resolve(__dirname, `./config/onebot_${await DataRuntime.getQQLoginUin()}.json`); let configFilePath = resolve(__dirname, `./config/onebot_${await DataRuntime.getQQLoginUin()}.json`);
try { try {
JSON.parse(req.body.config)
readFileSync(configFilePath); readFileSync(configFilePath);
} }
catch (e) { catch (e) {
configFilePath = resolve(__dirname, `./config/onebot.json`); configFilePath = resolve(__dirname, `./config/onebot.json`);
} }
writeFileSync(configFilePath, JSON.stringify(req.body.config, null, 4)); writeFileSync(configFilePath, JSON.stringify(JSON.parse(req.body.config), null, 4));
res.send({ res.send({
code: 0, code: 0,
message: 'success' message: 'success'

View File

@@ -49,7 +49,7 @@ class WebUiApiOB11ConfigWrapper {
'Authorization': "Bearer " + this.retCredential, 'Authorization': "Bearer " + this.retCredential,
'Content-Type': 'application/json' 'Content-Type': 'application/json'
}, },
body: JSON.stringify(config) body: JSON.stringify({ config: JSON.stringify(config) })
} }
); );
if (ConfigResponse.status == 200) { if (ConfigResponse.status == 200) {

View File

@@ -150,7 +150,11 @@ async function onSettingWindowCreated(view) {
const isEmpty = (value) => value === void 0 || value === void 0 || value === ""; const isEmpty = (value) => value === void 0 || value === void 0 || value === "";
let ob11Config = await OB11ConfigWrapper.GetOB11Config(); let ob11Config = await OB11ConfigWrapper.GetOB11Config();
const setOB11Config = (key, value) => { const setOB11Config = (key, value) => {
console.log(key, value); const configKey = key.split(".");
if (configKey.length === 2) {
ob11Config[configKey[1]] = value;
}
OB11ConfigWrapper.SetOB11Config(ob11Config);
}; };
const parser = new DOMParser(); const parser = new DOMParser();
const doc = parser.parseFromString( const doc = parser.parseFromString(