mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2025-07-19 12:03:37 +00:00
feat: 优化webui快速登录&优化代码整体逻辑
This commit is contained in:
@@ -222,6 +222,11 @@ async function handleLoginInner(context: { isLogined: boolean }, logger: LogWrap
|
|||||||
}`);
|
}`);
|
||||||
}
|
}
|
||||||
loginService.getQRCodePicture();
|
loginService.getQRCodePicture();
|
||||||
|
try {
|
||||||
|
await WebUiDataRuntime.runWebUiConfigQuickFunction();
|
||||||
|
} catch (error) {
|
||||||
|
logger.logError('WebUi 快速登录失败 执行失败', error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
loginService.getLoginList().then((res) => {
|
loginService.getLoginList().then((res) => {
|
||||||
|
@@ -50,20 +50,21 @@ export async function InitWebUi(logger: LogWrapper, pathWrapper: NapCatPathWrapp
|
|||||||
logger.log('[NapCat] [WebUi] Current WebUi is not run.');
|
logger.log('[NapCat] [WebUi] Current WebUi is not run.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setTimeout(async () => {
|
WebUiDataRuntime.setWebUiConfigQuickFunction(
|
||||||
let autoLoginAccount = process.env['NAPCAT_QUICK_ACCOUNT'] || WebUiConfig.getAutoLoginAccount();
|
async () => {
|
||||||
if (autoLoginAccount) {
|
let autoLoginAccount = process.env['NAPCAT_QUICK_ACCOUNT'] || WebUiConfig.getAutoLoginAccount();
|
||||||
try {
|
if (autoLoginAccount) {
|
||||||
const { result, message } = await WebUiDataRuntime.requestQuickLogin(autoLoginAccount);
|
try {
|
||||||
if (!result) {
|
const { result, message } = await WebUiDataRuntime.requestQuickLogin(autoLoginAccount);
|
||||||
throw new Error(message);
|
if (!result) {
|
||||||
|
throw new Error(message);
|
||||||
|
}
|
||||||
|
console.log(`[NapCat] [WebUi] Auto login account: ${autoLoginAccount}`);
|
||||||
|
} catch (error) {
|
||||||
|
console.log(`[NapCat] [WebUi] Auto login account failed.` + error);
|
||||||
}
|
}
|
||||||
console.log(`[NapCat] [WebUi] Auto login account: ${autoLoginAccount}`);
|
|
||||||
} catch (error) {
|
|
||||||
console.log(`[NapCat] [WebUi] Auto login account failed.` + error);
|
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
}, 30000);
|
|
||||||
// ------------注册中间件------------
|
// ------------注册中间件------------
|
||||||
// 使用express的json中间件
|
// 使用express的json中间件
|
||||||
app.use(express.json());
|
app.use(express.json());
|
||||||
|
@@ -25,6 +25,9 @@ const LoginRuntime: LoginRuntimeType = {
|
|||||||
NewQQLoginList: [],
|
NewQQLoginList: [],
|
||||||
},
|
},
|
||||||
packageJson: packageJson,
|
packageJson: packageJson,
|
||||||
|
WebUiConfigQuickFunction: async () => {
|
||||||
|
return;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const WebUiDataRuntime = {
|
export const WebUiDataRuntime = {
|
||||||
@@ -118,4 +121,11 @@ export const WebUiDataRuntime = {
|
|||||||
getQQVersion() {
|
getQQVersion() {
|
||||||
return LoginRuntime.QQVersion;
|
return LoginRuntime.QQVersion;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
setWebUiConfigQuickFunction(func: LoginRuntimeType['WebUiConfigQuickFunction']): void {
|
||||||
|
LoginRuntime.WebUiConfigQuickFunction = func;
|
||||||
|
},
|
||||||
|
runWebUiConfigQuickFunction: async function () {
|
||||||
|
await LoginRuntime.WebUiConfigQuickFunction();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
1
src/webui/src/types/data.d.ts
vendored
1
src/webui/src/types/data.d.ts
vendored
@@ -9,6 +9,7 @@ interface LoginRuntimeType {
|
|||||||
QQLoginUin: string;
|
QQLoginUin: string;
|
||||||
QQLoginInfo: SelfInfo;
|
QQLoginInfo: SelfInfo;
|
||||||
QQVersion: string;
|
QQVersion: string;
|
||||||
|
WebUiConfigQuickFunction: () => Promise<void>;
|
||||||
NapCatHelper: {
|
NapCatHelper: {
|
||||||
onQuickLoginRequested: (uin: string) => Promise<{ result: boolean; message: string }>;
|
onQuickLoginRequested: (uin: string) => Promise<{ result: boolean; message: string }>;
|
||||||
onOB11ConfigChanged: (ob11: OneBotConfig) => Promise<void>;
|
onOB11ConfigChanged: (ob11: OneBotConfig) => Promise<void>;
|
||||||
|
Reference in New Issue
Block a user