Skip to content

Commit

Permalink
feat: webui api (/QQVersion & /GetSysStatusRealTime)
Browse files Browse the repository at this point in the history
  • Loading branch information
pk5ls20 committed Dec 22, 2024
1 parent d4488e4 commit 871b568
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/core/helper/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface SystemStatus {
qq: string
}
},
arch: string
}

export class StatusHelper {
Expand Down Expand Up @@ -95,6 +96,7 @@ export class StatusHelper {
qq: qqUsage.memory
}
},
arch: `${os.platform()} ${os.arch()} ${os.release()}`
};
}
}
Expand Down
1 change: 1 addition & 0 deletions src/onebot/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ export class NapCatOneBot11Adapter {
this.initBuddyListener();
this.initGroupListener();

WebUiDataRuntime.setQQVersion(this.core.context.basicInfoWrapper.getFullQQVesion());
WebUiDataRuntime.setQQLoginInfo(selfInfo);
WebUiDataRuntime.setQQLoginStatus(true);
WebUiDataRuntime.setOnOB11ConfigChanged(async (newConfig) => {
Expand Down
6 changes: 6 additions & 0 deletions src/webui/src/api/BaseInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,9 @@ export const PackageInfoHandler: RequestHandler = (_, res) => {
const data = WebUiDataRuntime.getPackageJson();
sendSuccess(res, data);
};


export const QQVersionHandler: RequestHandler = (_, res) => {
const data = WebUiDataRuntime.getQQVersion();
sendSuccess(res, data);
};
9 changes: 9 additions & 0 deletions src/webui/src/helper/Data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const LoginRuntime: LoginRuntimeType = {
uin: '',
nick: '',
},
QQVersion: 'unknown',
NapCatHelper: {
onOB11ConfigChanged: async () => {
return;
Expand Down Expand Up @@ -100,4 +101,12 @@ export const WebUiDataRuntime = {
getPackageJson() {
return LoginRuntime.packageJson;
},

setQQVersion(version: string) {
LoginRuntime.QQVersion = version;
},

getQQVersion() {
return LoginRuntime.QQVersion;
}
};
3 changes: 2 additions & 1 deletion src/webui/src/router/Base.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Router } from 'express';
import { PackageInfoHandler } from '../api/BaseInfo';
import { PackageInfoHandler, QQVersionHandler } from '../api/BaseInfo';
import { StatusRealTimeHandler } from "@webapi/api/Status";

const router = Router();
// router: 获取nc的package.json信息
router.get('/QQVersion', QQVersionHandler);
router.get('/PackageInfo', PackageInfoHandler);
router.get('/GetSysStatusRealTime', StatusRealTimeHandler);

Expand Down
1 change: 1 addition & 0 deletions src/webui/src/types/data.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ interface LoginRuntimeType {
QQQRCodeURL: string;
QQLoginUin: string;
QQLoginInfo: SelfInfo;
QQVersion: string;
NapCatHelper: {
onQuickLoginRequested: (uin: string) => Promise<{ result: boolean; message: string }>;
onOB11ConfigChanged: (ob11: OneBotConfig) => Promise<void>;
Expand Down

0 comments on commit 871b568

Please sign in to comment.