feat(fileserver): 新增内网文件服务器服务与管理页面

新增 FastAPI 文件服务器核心模块(配置、鉴权、存储、心跳上报),新增 HTTP 路由接口(健康检查、文件上传/下载/删除、管理登录/密码修改/统计),新增 Vue3 管理页面源码;新增 MySQL 元数据存储支持,新增 PyMySQL 依赖;新增 .gitignore 忽略 IDE 与备份文件;新增文件服务器工具脚本;删除旧的 build/ 脚本与 exe 构建产物,优化 Electron 平台登录逻辑为纯接口模式,新增平台账号环境变量注入,优化试用期异常检查逻辑,拆分服务岗转正流程为独立脚本。
This commit is contained in:
2026-10-12 09:45:04 +08:00
parent 68f29d0a14
commit eeb951f9f6
56 changed files with 6499 additions and 39922 deletions
@@ -63,8 +63,10 @@ if (!app.requestSingleInstanceLock()) {
app.quit();
} else {
app.on("second-instance", () => {
if (mainWindow) {
if (mainWindow && !mainWindow.isDestroyed()) {
if (mainWindow.isMinimized()) mainWindow.restore();
// 收托盘走的是 hide():隐藏窗口不是 minimized,focus() 也唤不回,必须先 show()
mainWindow.show();
mainWindow.focus();
}
});
@@ -1,7 +1,7 @@
// 平台登录态(HR/OA):真实登录/登出/在线校验。
// 保持 Python 子进程执行登录自动化(壳内置 python/webhost/backend/shared 下的
// hr_login、oa_login,DrissionPage 滑块;自包含 vendor,不依赖老 webhost 底座),
// Node 壳只负责拉起子进程与解析结果。
// 保持 Python 子进程执行登录(壳内置 python/webhost/backend/shared 下的
// hr_login_api、oa_login_api,纯 requests 接口登录无浏览器;自包含 vendor,
// 不依赖老 webhost 底座),Node 壳只负责拉起子进程与解析结果。
// ★ 按账号隔离:每个登录账号拥有独立的会话目录(.sessions/<账号>/)与独立 HR/OA 账号密码,
// 子进程通过 PLATFORM_ACCOUNT 环境变量 + hr_login_username/password 注入各自身份。
"use strict";
@@ -182,7 +182,7 @@ async function isOnline(pid, account) {
return value;
}
// 真实登录:cookies 有效则复用(不弹浏览器),失效则浏览器自动化登录。
// 真实登录:cookies 有效则复用(不弹浏览器),失效则纯接口登录(无浏览器)。
// account:当前登录账号;其个人 HR/OA 账号密码通过环境变量注入登录子进程。
async function login(pid, account) {
if (!LABELS[pid]) throw Object.assign(new Error(`未知平台: ${pid}`), { status: 404 });
@@ -199,8 +199,8 @@ async function login(pid, account) {
try {
const snippet =
pid === "hr"
? `from webhost.backend.shared import hr_login; import json; print(json.dumps(hr_login.main({"force": False}), ensure_ascii=False))`
: `from webhost.backend.shared import oa_login; import json; print(json.dumps(oa_login.main(force=False), ensure_ascii=False))`;
? `from webhost.backend.shared import hr_login_api; import json; print(json.dumps(hr_login_api.main({"force": False}), ensure_ascii=False))`
: `from webhost.backend.shared import oa_login_api; import json; print(json.dumps(oa_login_api.main(force=False), ensure_ascii=False))`;
const out = await runPython(snippet, 5 * 60 * 1000, extraEnv);
const result = extractJson(out) || {};
const ok = !!result.success;
@@ -94,6 +94,9 @@ function pluginSchema(pluginId) {
uses_month: !!manifest.uses_month,
ui: !!manifest.ui,
platform: manifest.platform || "", // hr / oa / ""(前端平台徽章 + 运行并发闸按(账号,平台)隔离)
platforms: Array.isArray(manifest.platforms) && manifest.platforms.length
? manifest.platforms // 插件声明的全部平台依赖(运行前登录态预检按此逐个检查)
: manifest.platform ? [manifest.platform] : [], // 缺省回退单 platform 字段
min_runtime_version: manifest.minRuntimeVersion || "", // 版本兼容校验声明(安装时强校验,此处透传前端展示)
capabilities: manifest.capabilities || [],
permissions: manifest.permissions || {},
+29 -17
View File
@@ -14,6 +14,7 @@ const scheduler = require("./scheduler");
const licensing = require("./licensing");
const runHistory = require("./run-history");
const platformAuth = require("./platform-auth");
const platformCreds = require("./platform-creds");
const { HUB } = require("./hub");
const { makeLogger } = require("./logger");
@@ -67,26 +68,33 @@ function nsKey(account, platform) {
return `${account || "anon"}:${platform || "local"}`;
}
// 平台登录态预检(HR/OA):插件执行前检测该账号的平台登录态,
// 失效时自动拉起自动登录(platform-auth.login,Python 子进程滑块自动化;
// cookies 实际有效时不会弹浏览器)。登录成功继续执行,失败则本次运行报错,
// 提示用户去个人中心手动登录(手动登录入口保留,不冲突)。
// 在(账号, 平台)命名空间锁内调用,天然避免并发双开登录浏览器。
// 平台登录态预检(HR/OA):点击执行后、拉起插件前,按插件声明(plugin.json 的 platforms
// 数组,缺省回退 platform 单字段)逐个校验登录态(真实轻量 API 探测),失效时自动调
// platform-auth.login 纯接口补登(无浏览器,凭据来自平台账号配置)。任一平台补登失败
// 则本次运行直接报错中止,不进入插件执行。在(账号, 平台)命名空间锁内调用,天然避免
// 并发双开登录。
const PLATFORM_LABELS = { hr: "HR 系统", oa: "OA 系统" };
function pluginPlatforms(plugin) {
if (Array.isArray(plugin.platforms) && plugin.platforms.length) {
return plugin.platforms.filter((p) => PLATFORM_LABELS[p]);
}
const pid = plugin.platform;
return pid && PLATFORM_LABELS[pid] ? [pid] : [];
}
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}。请在「个人中心 → 平台账号」手动登录后重试`);
for (const pid of pluginPlatforms(plugin)) {
if (await platformAuth.isOnline(pid, account)) continue; // 登录态有效,无需处理
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}自动登录成功,开始执行插件`);
}
emitLog(runId, plugin.id, "INFO", `${label}自动登录成功,开始执行插件`);
}
// 发布日志事件,并同步累积到"这一次运行"的记录里(结束后随运行历史落盘,供点击回放)
@@ -287,6 +295,10 @@ function startChild(plugin, fields, runId, account) {
PYTHONIOENCODING: "utf-8",
PYTHONUTF8: "1",
PLATFORM_ACCOUNT: account || "",
// 平台凭据:供插件内登录态失效时自动补登录(未配置的平台/账号不注入,
// 此时登录模块回退读共享 .env)
...(platformCreds.envFor(account, "hr") || {}),
...(platformCreds.envFor(account, "oa") || {}),
// 环境包插件加载器据此定位插件根(dev 直拉模式传了也无害)
PLUGINS_ROOT: config.pluginRoot(),
},