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);
|
const qrPath = await loginInstance.login(qq, nickname);
|
||||||
|
if (qrPath) {
|
||||||
e.reply(segment.image(qrPath), true);
|
e.reply(segment.image(qrPath), true);
|
||||||
const timerKey = `login:timer:${qq}`;
|
const timerKey = `login:timer:${qq}`;
|
||||||
await redis.set(timerKey, 120, 'pending');
|
await redis.set(timerKey, 120, 'pending');
|
||||||
|
|
||||||
const check = setInterval(async () => {
|
const check = setInterval(async () => {
|
||||||
const status = await loginInstance.checkStatus();
|
const status = await loginInstance.checkStatus(qq);
|
||||||
if (status) {
|
if (status) {
|
||||||
clearInterval(check);
|
clearInterval(check);
|
||||||
await redis.del(timerKey);
|
await redis.del(timerKey);
|
||||||
@ -243,6 +244,14 @@ export default class LoginService extends plugin {
|
|||||||
return e.reply(`QQ[${qq}] 登录超时,已断开,请重新发起登录..`, true);
|
return e.reply(`QQ[${qq}] 登录超时,已断开,请重新发起登录..`, true);
|
||||||
}
|
}
|
||||||
}, 5000);
|
}, 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) {
|
} catch (err) {
|
||||||
logger.error('[crystelf-admin]登录流程出现错误', err);
|
logger.error('[crystelf-admin]登录流程出现错误', err);
|
||||||
return e.reply(`出了点小问题,过会儿再来试试吧..`);
|
return e.reply(`出了点小问题,过会儿再来试试吧..`);
|
||||||
|
|||||||
@ -55,33 +55,38 @@ export default class LgrService {
|
|||||||
/**
|
/**
|
||||||
* 等待qr图片更新
|
* 等待qr图片更新
|
||||||
* @param targetDir 目标文件夹
|
* @param targetDir 目标文件夹
|
||||||
* @param timeout
|
* @param timeout 最大等待时间 (默认 30s)
|
||||||
* @returns {Promise<unknown>}
|
* @returns {Promise<string|undefined>}
|
||||||
*/
|
*/
|
||||||
async waitForQrUpdate(targetDir, timeout = 10000) {
|
async waitForQrUpdate(targetDir, timeout = 30000) {
|
||||||
const qrPath = path.join(targetDir, 'qr-0.png');
|
const qrPath = path.join(targetDir, 'qr-0.png');
|
||||||
if (!fs.existsSync(qrPath)) {
|
if (!fs.existsSync(qrPath)) {
|
||||||
return 'none';
|
return 'none';
|
||||||
}
|
}
|
||||||
|
|
||||||
let lastMtime = fs.statSync(qrPath).mtimeMs;
|
let lastMtime = fs.statSync(qrPath).mtimeMs;
|
||||||
|
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
const timer = setTimeout(() => {
|
let resolved = false;
|
||||||
watcher.close();
|
|
||||||
resolve('none');
|
|
||||||
}, timeout);
|
|
||||||
|
|
||||||
|
const timer = setTimeout(() => {
|
||||||
|
if (!resolved) {
|
||||||
|
resolved = true;
|
||||||
|
watcher.close();
|
||||||
|
resolve(undefined);
|
||||||
|
}
|
||||||
|
}, timeout);
|
||||||
const watcher = fs.watch(qrPath, (eventType) => {
|
const watcher = fs.watch(qrPath, (eventType) => {
|
||||||
if (eventType === 'change') {
|
if (eventType === 'change') {
|
||||||
const stat = fs.statSync(qrPath);
|
const stat = fs.statSync(qrPath);
|
||||||
if (stat.mtimeMs !== lastMtime) {
|
if (stat.mtimeMs !== lastMtime) {
|
||||||
lastMtime = stat.mtimeMs;
|
lastMtime = stat.mtimeMs;
|
||||||
|
if (!resolved) {
|
||||||
|
resolved = true;
|
||||||
clearTimeout(timer);
|
clearTimeout(timer);
|
||||||
watcher.close();
|
watcher.close();
|
||||||
resolve(qrPath);
|
resolve(qrPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@ -64,29 +64,33 @@ export default class NapcatService {
|
|||||||
* @param timeout
|
* @param timeout
|
||||||
* @returns {Promise<unknown>}
|
* @returns {Promise<unknown>}
|
||||||
*/
|
*/
|
||||||
async waitForQrUpdate(timeout = 10000) {
|
async waitForQrUpdate(timeout = 30000) {
|
||||||
if (!fs.existsSync(this.qrPath)) {
|
if (!fs.existsSync(this.qrPath)) {
|
||||||
return 'none';
|
return 'none';
|
||||||
}
|
}
|
||||||
|
|
||||||
let lastMtime = fs.statSync(this.qrPath).mtimeMs;
|
let lastMtime = fs.statSync(this.qrPath).mtimeMs;
|
||||||
|
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
|
let resolved = false;
|
||||||
const timer = setTimeout(() => {
|
const timer = setTimeout(() => {
|
||||||
|
if (!resolved) {
|
||||||
|
resolved = true;
|
||||||
watcher.close();
|
watcher.close();
|
||||||
resolve('none');
|
resolve(undefined);
|
||||||
|
}
|
||||||
}, timeout);
|
}, timeout);
|
||||||
|
|
||||||
const watcher = fs.watch(this.qrPath, (eventType) => {
|
const watcher = fs.watch(this.qrPath, (eventType) => {
|
||||||
if (eventType === 'change') {
|
if (eventType === 'change') {
|
||||||
const stat = fs.statSync(this.qrPath);
|
const stat = fs.statSync(this.qrPath);
|
||||||
if (stat.mtimeMs !== lastMtime) {
|
if (stat.mtimeMs !== lastMtime) {
|
||||||
lastMtime = stat.mtimeMs;
|
lastMtime = stat.mtimeMs;
|
||||||
|
if (!resolved) {
|
||||||
|
resolved = true;
|
||||||
clearTimeout(timer);
|
clearTimeout(timer);
|
||||||
watcher.close();
|
watcher.close();
|
||||||
resolve(this.qrPath);
|
resolve(this.qrPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user