mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2024-11-21 09:36: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 === '';
|
||||
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;
|
||||
|
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…
x
Reference in New Issue
Block a user