refactor: 重构执行机架构为 Electron 壳内置 Python 运行时子集
将原 webhost 底座的后端、前端、工具等代码迁移至 electron-shell 目录,构建自包含的 Python 环境包,移除冗余的前端代码、旧的后端模块及相关依赖,更新版本号至 1.0.6,优化平台登录态预检逻辑,统一代码结构为单一真源,避免多副本维护问题。
This commit is contained in:
@@ -13,6 +13,7 @@ const state = require("./state");
|
||||
const scheduler = require("./scheduler");
|
||||
const licensing = require("./licensing");
|
||||
const runHistory = require("./run-history");
|
||||
const platformAuth = require("./platform-auth");
|
||||
const { HUB } = require("./hub");
|
||||
const { makeLogger } = require("./logger");
|
||||
|
||||
@@ -66,6 +67,28 @@ function nsKey(account, platform) {
|
||||
return `${account || "anon"}:${platform || "local"}`;
|
||||
}
|
||||
|
||||
// 平台登录态预检(HR/OA):插件执行前检测该账号的平台登录态,
|
||||
// 失效时自动拉起自动登录(platform-auth.login,Python 子进程滑块自动化;
|
||||
// cookies 实际有效时不会弹浏览器)。登录成功继续执行,失败则本次运行报错,
|
||||
// 提示用户去个人中心手动登录(手动登录入口保留,不冲突)。
|
||||
// 在(账号, 平台)命名空间锁内调用,天然避免并发双开登录浏览器。
|
||||
const PLATFORM_LABELS = { hr: "HR 系统", oa: "OA 系统" };
|
||||
async function ensurePlatformSession(plugin, runId, account) {
|
||||
const pid = plugin.platform;
|
||||
if (!pid || !PLATFORM_LABELS[pid]) return; // 无平台要求(或未知平台)直接执行
|
||||
if (await platformAuth.isOnline(pid, account)) return; // 登录态有效,直接执行
|
||||
if (isUserStopped(runId)) throw new Error("用户已取消该排队任务");
|
||||
const label = PLATFORM_LABELS[pid];
|
||||
emitLog(runId, plugin.id, "INFO", `检测到${label}登录态失效,正在自动登录…(如需人工介入请观察弹出的浏览器窗口)`);
|
||||
const r = await platformAuth.login(pid, account);
|
||||
if (isUserStopped(runId)) throw new Error("用户已取消该排队任务"); // 登录期间用户点了停止
|
||||
if (!r || !r.online) {
|
||||
const msg = (r && r.message) || "登录未生效";
|
||||
throw new Error(`${label}自动登录失败:${msg}。请在「个人中心 → 平台账号」手动登录后重试`);
|
||||
}
|
||||
emitLog(runId, plugin.id, "INFO", `${label}自动登录成功,开始执行插件`);
|
||||
}
|
||||
|
||||
// 发布日志事件,并同步累积到"这一次运行"的记录里(结束后随运行历史落盘,供点击回放)
|
||||
function emitLog(runId, pluginId, level, msg) {
|
||||
const text = String(msg === undefined || msg === null ? "" : msg);
|
||||
@@ -206,6 +229,8 @@ async function runQueued(plugin, fields, runId, account) {
|
||||
// 排队期间用户已点停止:不真正拉起插件
|
||||
throw new Error("用户已取消该排队任务");
|
||||
}
|
||||
// 平台登录态预检:HR/OA 失效时自动登录(手动登录入口保留)
|
||||
await ensurePlatformSession(plugin, runId, account);
|
||||
await startChild(plugin, fields, runId, account);
|
||||
return runId;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user