mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2026-01-17 05:40:35 +00:00
feat: Ui Config
This commit is contained in:
parent
6f5a6f353f
commit
b9a913cfed
@ -6,19 +6,19 @@ import { OB11Config } from "@/webui/ui/components/WebApi";
|
|||||||
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();
|
||||||
if (!isLogin) {
|
// if (!isLogin) {
|
||||||
res.send({
|
// res.send({
|
||||||
code: -1,
|
// code: -1,
|
||||||
message: 'Not Login'
|
// message: 'Not Login'
|
||||||
});
|
// });
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
const uin = await DataRuntime.getQQLoginUin();
|
const uin = await DataRuntime.getQQLoginUin();
|
||||||
let configFilePath = resolve(__dirname, `./config/onebot_${uin}.json`);
|
let configFilePath = resolve(__dirname, `./config/onebot11_${uin}.json`);
|
||||||
console.log(configFilePath);
|
//console.log(configFilePath);
|
||||||
let data: OB11Config;
|
let data: OB11Config;
|
||||||
try {
|
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) {
|
catch (e) {
|
||||||
data = {} as OB11Config;
|
data = {} as OB11Config;
|
||||||
|
|||||||
45
src/webui/ui/helper/Config.ts
Normal file
45
src/webui/ui/helper/Config.ts
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
import { OB11Config } from "../components/WebApi";
|
||||||
|
|
||||||
|
|
||||||
|
class WebUiApiOB11ConfigWrapper {
|
||||||
|
private retCredential: string = "";
|
||||||
|
async Init(Credential: string) {
|
||||||
|
this.retCredential = Credential;
|
||||||
|
}
|
||||||
|
async GetConfig(): Promise<OB11Config> {
|
||||||
|
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<Boolean> {
|
||||||
|
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();
|
||||||
Loading…
Reference in New Issue
Block a user