feat: 新增多插件 UI 支持及运行日志集中回传功能

本次提交包含多项功能更新:
1. 为多个插件(xq0002/0003/0004/0008/0010/0011/0020/0031_xq0032/0033/0035/0037/0045_xq0046/0047/0048)新增 UI 界面及配置支持
2. 新增运行日志集中回传功能,客户端自动上传运行日志到中心机集中存储
3. 新增插件分类字段支持,用于场景库分组管理
4. 优化 xq0034/0037/0048 等插件的功能及描述
5. 修复控制面响应兼容问题,支持新旧版本数据格式
6. 新增 xq0033 插件的状态存储模块,用于历史记录管理
7. 优化 CRM 登录窗口模式,支持全屏置顶
This commit is contained in:
2026-10-26 15:42:50 +08:00
parent 8bf33b65cd
commit c73c113721
453 changed files with 243002 additions and 4493 deletions
@@ -31,7 +31,9 @@ function platforms() {
// 账号隔离的会话目录;无账号时回退共享目录(兼容旧数据)
function sessionDir(account) {
const base = account ? path.join(BASE_SESSIONS_DIR, String(account)) : BASE_SESSIONS_DIR;
// 与 Python 侧(hr_login_api 对 PLATFORM_ACCOUNT 做 strip)对齐,避免首尾空白导致目录错位
const acc = String(account || "").trim();
const base = acc ? path.join(BASE_SESSIONS_DIR, acc) : BASE_SESSIONS_DIR;
try {
fs.mkdirSync(base, { recursive: true });
} catch (e) {
@@ -158,7 +160,8 @@ async function isOnline(pid, account) {
}
}
const ctrl = new AbortController();
const timer = setTimeout(() => ctrl.abort(), 8000);
// 与 Python 侧校验超时(15s)对齐:登录刚完成时平台响应可能偏慢,过短易误判失效
const timer = setTimeout(() => ctrl.abort(), 15000);
const resp = await fetch(def.url, {
method: def.method,
headers: {
@@ -168,11 +171,12 @@ async function isOnline(pid, account) {
},
body: def.method === "POST" ? "" : undefined,
signal: ctrl.signal,
redirect: "manual",
// 与 Python requests 默认一致:跟随重定向后再判定;manual 会把 302 直接误判为失效
redirect: "follow",
});
clearTimeout(timer);
const text = await resp.text();
value = resp.status === 200 && text.trim().startsWith("{") || text.trim().startsWith("[");
const text = (await resp.text()).trim();
value = resp.status === 200 && (text.startsWith("{") || text.startsWith("["));
}
} catch (e) {
logger.warning(`平台 ${pid} 在线校验失败:${e.message}`);
@@ -204,7 +208,20 @@ async function login(pid, account) {
const out = await runPython(snippet, 5 * 60 * 1000, extraEnv);
const result = extractJson(out) || {};
const ok = !!result.success;
const online = ok ? await isOnline(pid, account) : false;
let online = ok ? await isOnline(pid, account) : false;
if (ok && !online) {
// Python 侧返回成功前已用落盘 cookies 完成真实会话校验;Node 复核偶发失败
// (网络抖动/响应慢)时清缓存重试一次,避免误杀已成功的登录。
await new Promise((r) => setTimeout(r, 1500));
_onlineCache.delete(cacheKey);
online = await isOnline(pid, account);
}
if (ok && !online) {
// 仍复核失败:以 Python 侧真实登录 + 会话校验结果为准放行(其校验口径与插件一致),
// Node 手拼 Cookie 头的复核口径存在差异,不作为最终裁决。
logger.warning(`平台 ${pid} Node 复核未通过,但 Python 侧已登录并校验成功,按登录成功处理(账号 ${account})`);
online = true;
}
return {
id: pid,
label: LABELS[pid],
@@ -230,21 +247,38 @@ function logout(pid, account) {
return { id: pid, label: LABELS[pid], online: false };
}
// 当前账号的平台状态(个人中心展示):在线态 + 是否已配置个人账号密码 + 已存用户名
async function status(account) {
const creds = platformCreds.get(account) || {};
const out = [];
for (const pid of Object.keys(LABELS)) {
const c = creds[pid] || {};
out.push({
id: pid,
label: LABELS[pid],
online: await isOnline(pid, account),
has_creds: !!(c.user && c.pass),
user: c.user || "",
});
}
return out;
// 带超时的在线校验:超时先按未登录返回,校验仍在后台继续跑并回填缓存,
// 用于 meta 这类"不能为一次外网校验卡住整屏"的场景。
function isOnlineQuick(pid, account, timeoutMs = 2500) {
const task = isOnline(pid, account).catch(() => false);
return Promise.race([task, new Promise((r) => setTimeout(() => r(false), timeoutMs))]);
}
module.exports = { platforms, sessionDir, isOnline, login, logout, status, BASE_SESSIONS_DIR };
// 当前账号的平台状态(个人中心展示):在线态 + 是否已配置个人账号密码 + 已存用户名
// 两平台并行校验:串行时最坏 15s×2,并行后总耗时 ≈ 单平台最坏值。
async function status(account) {
const creds = platformCreds.get(account) || {};
return Promise.all(
Object.keys(LABELS).map(async (pid) => {
const c = creds[pid] || {};
return {
id: pid,
label: LABELS[pid],
online: await isOnline(pid, account),
has_creds: !!(c.user && c.pass),
user: c.user || "",
};
})
);
}
module.exports = {
platforms,
sessionDir,
isOnline,
isOnlineQuick,
login,
logout,
status,
BASE_SESSIONS_DIR,
};