feat: 优化webui快速登录&优化代码整体逻辑

This commit is contained in:
手瓜一十雪
2025-04-01 20:43:46 +08:00
parent 291e2fd8fd
commit 53a7ce2e46
4 changed files with 29 additions and 12 deletions

View File

@@ -222,6 +222,11 @@ async function handleLoginInner(context: { isLogined: boolean }, logger: LogWrap
}`);
}
loginService.getQRCodePicture();
try {
await WebUiDataRuntime.runWebUiConfigQuickFunction();
} catch (error) {
logger.logError('WebUi 快速登录失败 执行失败', error);
}
}
loginService.getLoginList().then((res) => {

View File

@@ -50,20 +50,21 @@ export async function InitWebUi(logger: LogWrapper, pathWrapper: NapCatPathWrapp
logger.log('[NapCat] [WebUi] Current WebUi is not run.');
return;
}
setTimeout(async () => {
let autoLoginAccount = process.env['NAPCAT_QUICK_ACCOUNT'] || WebUiConfig.getAutoLoginAccount();
if (autoLoginAccount) {
try {
const { result, message } = await WebUiDataRuntime.requestQuickLogin(autoLoginAccount);
if (!result) {
throw new Error(message);
WebUiDataRuntime.setWebUiConfigQuickFunction(
async () => {
let autoLoginAccount = process.env['NAPCAT_QUICK_ACCOUNT'] || WebUiConfig.getAutoLoginAccount();
if (autoLoginAccount) {
try {
const { result, message } = await WebUiDataRuntime.requestQuickLogin(autoLoginAccount);
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中间件
app.use(express.json());

View File

@@ -25,6 +25,9 @@ const LoginRuntime: LoginRuntimeType = {
NewQQLoginList: [],
},
packageJson: packageJson,
WebUiConfigQuickFunction: async () => {
return;
}
};
export const WebUiDataRuntime = {
@@ -118,4 +121,11 @@ export const WebUiDataRuntime = {
getQQVersion() {
return LoginRuntime.QQVersion;
},
setWebUiConfigQuickFunction(func: LoginRuntimeType['WebUiConfigQuickFunction']): void {
LoginRuntime.WebUiConfigQuickFunction = func;
},
runWebUiConfigQuickFunction: async function () {
await LoginRuntime.WebUiConfigQuickFunction();
}
};

View File

@@ -9,6 +9,7 @@ interface LoginRuntimeType {
QQLoginUin: string;
QQLoginInfo: SelfInfo;
QQVersion: string;
WebUiConfigQuickFunction: () => Promise<void>;
NapCatHelper: {
onQuickLoginRequested: (uin: string) => Promise<{ result: boolean; message: string }>;
onOB11ConfigChanged: (ob11: OneBotConfig) => Promise<void>;