mirror of
https://github.com/crystelf/crystelf-admin.git
synced 2025-12-05 13:41:57 +00:00
feat:优化login逻辑
This commit is contained in:
parent
c5abaf132d
commit
e50940631f
@ -1,12 +1,9 @@
|
|||||||
import plugin from '../../../lib/plugins/plugin.js';
|
import plugin from '../../../lib/plugins/plugin.js';
|
||||||
import path from 'path';
|
|
||||||
import ConfigControl from '../lib/config/configControl.js';
|
import ConfigControl from '../lib/config/configControl.js';
|
||||||
import configControl from '../lib/config/configControl.js';
|
import configControl from '../lib/config/configControl.js';
|
||||||
import Meme from '../lib/core/meme.js';
|
import Meme from '../lib/core/meme.js';
|
||||||
import NapcatService from '../lib/login/napcat.js';
|
import NapcatService from '../lib/login/napcat.js';
|
||||||
import LgrService from '../lib/login/lgr.js';
|
import LgrService from '../lib/login/lgr.js';
|
||||||
|
|
||||||
const configPath = path.join(process.cwd(), 'data/crystelf/config');
|
|
||||||
const loginSessions = new Map(); //正在进行的登录会话
|
const loginSessions = new Map(); //正在进行的登录会话
|
||||||
const bindSessions = new Map(); //正在进行的绑定会话
|
const bindSessions = new Map(); //正在进行的绑定会话
|
||||||
const activeLogins = new Map(); //在线登录实例
|
const activeLogins = new Map(); //在线登录实例
|
||||||
@ -270,7 +267,7 @@ export default class LoginService extends plugin {
|
|||||||
async doLogin(e, session) {
|
async doLogin(e, session) {
|
||||||
try {
|
try {
|
||||||
const { qq, method, nickname } = session;
|
const { qq, method, nickname } = session;
|
||||||
e.reply(`开始使用 ${method} 登录 QQ[${qq}]`, true);
|
e.reply(`开始尝试使用 ${method} 登录 QQ[${qq}]`, true);
|
||||||
let loginInstance;
|
let loginInstance;
|
||||||
if (method === 'nc') {
|
if (method === 'nc') {
|
||||||
loginInstance = new NapcatService();
|
loginInstance = new NapcatService();
|
||||||
@ -281,7 +278,14 @@ export default class LoginService extends plugin {
|
|||||||
const qrPath = await loginInstance.login(qq, nickname);
|
const qrPath = await loginInstance.login(qq, nickname);
|
||||||
const loginTimers = new Map();
|
const loginTimers = new Map();
|
||||||
if (qrPath && qrPath !== 'none') {
|
if (qrPath && qrPath !== 'none') {
|
||||||
await e.reply(segment.image(`file:///${qrPath}`), true);
|
await e.reply(
|
||||||
|
[
|
||||||
|
segment.image(`file:///${qrPath}`),
|
||||||
|
'\n请使用手机qq摄像头扫码登录并勾选保存登录状态\n二维码有效期2分钟..',
|
||||||
|
],
|
||||||
|
true,
|
||||||
|
{ recallMsg: 120 }
|
||||||
|
);
|
||||||
const timerKey = `login:timer:${qq}`;
|
const timerKey = `login:timer:${qq}`;
|
||||||
if (loginTimers.has(timerKey)) {
|
if (loginTimers.has(timerKey)) {
|
||||||
clearTimeout(loginTimers.get(timerKey).timeout);
|
clearTimeout(loginTimers.get(timerKey).timeout);
|
||||||
|
|||||||
@ -3,6 +3,7 @@ import path from 'path';
|
|||||||
import { exec } from 'child_process';
|
import { exec } from 'child_process';
|
||||||
import util from 'util';
|
import util from 'util';
|
||||||
import configControl from '../config/configControl.js';
|
import configControl from '../config/configControl.js';
|
||||||
|
import Path from '../../constants/path.js';
|
||||||
|
|
||||||
const execAsync = util.promisify(exec);
|
const execAsync = util.promisify(exec);
|
||||||
|
|
||||||
@ -32,7 +33,7 @@ export default class NapcatService {
|
|||||||
const userConfigFile = path.join(this.configPath, `onebot11_${qq}.json`);
|
const userConfigFile = path.join(this.configPath, `onebot11_${qq}.json`);
|
||||||
if (!fs.existsSync(userConfigFile)) {
|
if (!fs.existsSync(userConfigFile)) {
|
||||||
try {
|
try {
|
||||||
const defaultConfigFile = path.join(configControl.get('config')?.path || '', 'napcat.json');
|
const defaultConfigFile = path.join(Path.config || '', 'napcat.json');
|
||||||
if (!fs.existsSync(defaultConfigFile)) {
|
if (!fs.existsSync(defaultConfigFile)) {
|
||||||
logger.error(`[crystelf-admin] 默认配置文件不存在: ${defaultConfigFile}`);
|
logger.error(`[crystelf-admin] 默认配置文件不存在: ${defaultConfigFile}`);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user