feat: webui getQrcode

This commit is contained in:
手瓜一十雪 2024-05-07 12:23:58 +08:00
parent aa037cc3d9
commit caab998212
3 changed files with 30 additions and 2 deletions

View File

@ -9,6 +9,7 @@ import { log, logDebug, logError, LogLevel, setLogLevel } from '@/common/utils/l
import { NapCatOnebot11 } from '@/onebot11/main';
import { hookApi } from '@/core/external/hook';
import { InitWebUi } from './webui/index';
import { DataRuntime } from './webui/src/helper/Data';
program
.option('-q, --qq <type>', 'QQ号')
.parse(process.argv);
@ -43,9 +44,11 @@ checkVersion().then((remoteVersion: string) => {
new NapCatOnebot11();
napCatCore.onLoginSuccess(() => {
console.log('登录成功!');
DataRuntime.setQQLoginStatus(true);
postLoginStatus();
});
const showQRCode = (qrCodeData: { url: string, base64: string, buffer: Buffer }) => {
const showQRCode = async (qrCodeData: { url: string, base64: string, buffer: Buffer }) => {
await DataRuntime.setQQLoginQrcodeURL(qrCodeData.url);
console.log('请扫描下面的二维码然后在手Q上授权登录');
const qrcodePath = path.join(__dirname, 'qrcode.png');
qrcode.generate(qrCodeData.url, { small: true }, (res) => {

View File

@ -1,13 +1,30 @@
import { RequestHandler } from "express";
import { DataRuntime } from "../helper/Data";
const isEmpty = (data: any) => data === undefined || data === null || data === '';
export const QQGetQRcodeHandler: RequestHandler = async (req, res) => {
if (await DataRuntime.getQQLoginStatus()) {
res.send({
code: -1,
message: 'QQ Is Logined'
});
return;
}
let qrcodeUrl = await DataRuntime.getQQLoginQrcodeURL();
if (isEmpty(qrcodeUrl)) {
res.send({
code: -1,
message: 'QRCode Get Error'
});
return;
}
res.send({
code: 0,
message: 'success',
data: {
qrcode: qrcodeUrl
}
});
return;
};
export const QQCheckLoginStatusHandler: RequestHandler = (req, res) => {
res.send({

View File

@ -24,4 +24,12 @@ export const DataRuntime = {
setQQLoginStatus: async function (status: boolean): Promise<void> {
LoginRuntime.QQLoginStatus = status;
}
,
setQQLoginQrcodeURL: async function (url: string): Promise<void> {
LoginRuntime.QQQRCodeURL = url;
}
,
getQQLoginQrcodeURL: async function (): Promise<string> {
return LoginRuntime.QQQRCodeURL;
}
}