mirror of
https://github.com/crystelf/crystelf-admin.git
synced 2025-12-05 13:41:57 +00:00
fix:修复某些登录问题
This commit is contained in:
parent
78379f1c94
commit
61cec10da1
@ -225,12 +225,13 @@ export default class LoginService extends plugin {
|
||||
}
|
||||
|
||||
const qrPath = await loginInstance.login(qq, nickname);
|
||||
if (qrPath) {
|
||||
e.reply(segment.image(qrPath), true);
|
||||
const timerKey = `login:timer:${qq}`;
|
||||
await redis.set(timerKey, 120, 'pending');
|
||||
|
||||
const check = setInterval(async () => {
|
||||
const status = await loginInstance.checkStatus();
|
||||
const status = await loginInstance.checkStatus(qq);
|
||||
if (status) {
|
||||
clearInterval(check);
|
||||
await redis.del(timerKey);
|
||||
@ -243,6 +244,14 @@ export default class LoginService extends plugin {
|
||||
return e.reply(`QQ[${qq}] 登录超时,已断开,请重新发起登录..`, true);
|
||||
}
|
||||
}, 5000);
|
||||
} else {
|
||||
const status = await loginInstance.checkStatus(qq);
|
||||
if (status) {
|
||||
return e.reply(`QQ[${qq}] 使用上次登录缓存登录成功!`, true);
|
||||
} else {
|
||||
return e.reply(`QQ[${qq}] 登录出现未知错误,请联系管理员操作..`, true);
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
logger.error('[crystelf-admin]登录流程出现错误', err);
|
||||
return e.reply(`出了点小问题,过会儿再来试试吧..`);
|
||||
|
||||
@ -55,33 +55,38 @@ export default class LgrService {
|
||||
/**
|
||||
* 等待qr图片更新
|
||||
* @param targetDir 目标文件夹
|
||||
* @param timeout
|
||||
* @returns {Promise<unknown>}
|
||||
* @param timeout 最大等待时间 (默认 30s)
|
||||
* @returns {Promise<string|undefined>}
|
||||
*/
|
||||
async waitForQrUpdate(targetDir, timeout = 10000) {
|
||||
async waitForQrUpdate(targetDir, timeout = 30000) {
|
||||
const qrPath = path.join(targetDir, 'qr-0.png');
|
||||
if (!fs.existsSync(qrPath)) {
|
||||
return 'none';
|
||||
}
|
||||
|
||||
let lastMtime = fs.statSync(qrPath).mtimeMs;
|
||||
|
||||
return new Promise((resolve) => {
|
||||
const timer = setTimeout(() => {
|
||||
watcher.close();
|
||||
resolve('none');
|
||||
}, timeout);
|
||||
let resolved = false;
|
||||
|
||||
const timer = setTimeout(() => {
|
||||
if (!resolved) {
|
||||
resolved = true;
|
||||
watcher.close();
|
||||
resolve(undefined);
|
||||
}
|
||||
}, timeout);
|
||||
const watcher = fs.watch(qrPath, (eventType) => {
|
||||
if (eventType === 'change') {
|
||||
const stat = fs.statSync(qrPath);
|
||||
if (stat.mtimeMs !== lastMtime) {
|
||||
lastMtime = stat.mtimeMs;
|
||||
if (!resolved) {
|
||||
resolved = true;
|
||||
clearTimeout(timer);
|
||||
watcher.close();
|
||||
resolve(qrPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@ -64,29 +64,33 @@ export default class NapcatService {
|
||||
* @param timeout
|
||||
* @returns {Promise<unknown>}
|
||||
*/
|
||||
async waitForQrUpdate(timeout = 10000) {
|
||||
async waitForQrUpdate(timeout = 30000) {
|
||||
if (!fs.existsSync(this.qrPath)) {
|
||||
return 'none';
|
||||
}
|
||||
|
||||
let lastMtime = fs.statSync(this.qrPath).mtimeMs;
|
||||
|
||||
return new Promise((resolve) => {
|
||||
let resolved = false;
|
||||
const timer = setTimeout(() => {
|
||||
if (!resolved) {
|
||||
resolved = true;
|
||||
watcher.close();
|
||||
resolve('none');
|
||||
resolve(undefined);
|
||||
}
|
||||
}, timeout);
|
||||
|
||||
const watcher = fs.watch(this.qrPath, (eventType) => {
|
||||
if (eventType === 'change') {
|
||||
const stat = fs.statSync(this.qrPath);
|
||||
if (stat.mtimeMs !== lastMtime) {
|
||||
lastMtime = stat.mtimeMs;
|
||||
if (!resolved) {
|
||||
resolved = true;
|
||||
clearTimeout(timer);
|
||||
watcher.close();
|
||||
resolve(this.qrPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user