diff --git a/src/index.ts b/src/index.ts index 49f51b13..21ebc460 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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 ', '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) => { diff --git a/src/webui/src/api/QQLogin.ts b/src/webui/src/api/QQLogin.ts index 5d96af00..2f1d15f7 100644 --- a/src/webui/src/api/QQLogin.ts +++ b/src/webui/src/api/QQLogin.ts @@ -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({ diff --git a/src/webui/src/helper/Data.ts b/src/webui/src/helper/Data.ts index ea2de564..1423b21f 100644 --- a/src/webui/src/helper/Data.ts +++ b/src/webui/src/helper/Data.ts @@ -24,4 +24,12 @@ export const DataRuntime = { setQQLoginStatus: async function (status: boolean): Promise { LoginRuntime.QQLoginStatus = status; } + , + setQQLoginQrcodeURL: async function (url: string): Promise { + LoginRuntime.QQQRCodeURL = url; + } + , + getQQLoginQrcodeURL: async function (): Promise { + return LoginRuntime.QQQRCodeURL; + } } \ No newline at end of file