feat: 新增xq0031_xq0032 ERP报表导出插件,完成功能与基建更新

1. 新增xq0031_xq0032插件:包含前后端源码、打包脚本、配置文件与插件元数据
2. 新增内网文件服务器组件:exe、启停脚本、打包脚本与配置
3. 新增敏感凭证RSA加密下发能力与存储结构
4. 新增大文件源管理表与相关API
5. 优化登录流程与会话管理,新增Chrome自动化安装工具链
6. 清理废弃插件与示例代码
7. 更新版本号至1.1.3,完善安装包与.gitignore配置
This commit is contained in:
2026-09-17 12:42:44 +08:00
parent 6d2dd93628
commit f30ab9cc29
105 changed files with 7819 additions and 4276 deletions
+69 -40
View File
@@ -12,8 +12,10 @@ from __future__ import annotations
import asyncio
import logging
import socket
import sys
import threading
from contextlib import asynccontextmanager
from pathlib import Path
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
@@ -29,6 +31,7 @@ from webhost.backend.plugins import load_plugins
from webhost.backend.apis import admin as api_admin
from webhost.backend.apis import dingtalk as api_dingtalk
from webhost.backend.apis import meta as api_meta
from webhost.backend.apis import plugin_ui as api_plugin_ui
from webhost.backend.apis import runs as api_runs
_LOGGER = logging.getLogger(__name__)
@@ -36,48 +39,73 @@ _LOGGER = logging.getLogger(__name__)
@asynccontextmanager
async def lifespan(app: FastAPI):
HUB.bind(asyncio.get_running_loop())
# 显式加载插件:默认全量;配置 controlplane 源则按账号权限白名单加载
_st.set_allowed(_resolve_allowed())
load_plugins(_st.ALLOWED)
# 产品化初始化:授权缓存 + 单活调度 + 启动即同步离线票据
licensing.init(config.CONTROLPLANE_URL, threading.Lock())
_scheduler.init_active()
if config.CONTROLPLANE_URL:
try:
_sync_licensing(config.CONTROLPLANE_ACCOUNT)
_LOGGER.info("启动同步离线授权票据成功(账号 %s)", config.CONTROLPLANE_ACCOUNT)
except Exception as _exc: # noqa: BLE001 首启/断网时同步失败不阻断,离线用缓存兜底
_LOGGER.warning("启动同步离线授权票据失败:%s", _exc)
# 启动即检查插件更新:有恢复的会话账号时后台同步(每次启动确定是否更新,不阻塞启动)
try:
from webhost.backend.core.session import _SESS
_accts = {_a for _, (_a, _t) in _SESS.items()}
except Exception: # noqa: BLE001
_accts = set()
if _accts:
_acct = next(iter(_accts))
def _boot_sync() -> None:
try:
from webhost.backend.core.plugin_sync import sync_plugins
sync_plugins(_acct)
load_plugins(_st.ALLOWED, reload=True)
_LOGGER.info("启动插件更新完成(账号 %s)", _acct)
except Exception as _exc: # noqa: BLE001 更新失败不阻断启动
_LOGGER.warning("启动插件更新失败:%s", _exc)
threading.Thread(target=_boot_sync, daemon=True).start()
# 启动即检查壳子(主程序)更新:有新版本自动下载,前端提示后由用户点击重启升级
def _boot_shell_check() -> None:
try:
HUB.bind(asyncio.get_running_loop())
# 显式加载插件:默认全量;配置 controlplane 源则按账号权限白名单加载
_st.set_allowed(_resolve_allowed())
load_plugins(_st.ALLOWED)
# 产品化初始化:授权缓存 + 单活调度 + 启动即同步离线票据
licensing.init(config.CONTROLPLANE_URL, threading.Lock())
_scheduler.init_active()
if config.CONTROLPLANE_URL:
# 敏感凭证中心化下发:优先服务端在线拉取(RSA 解密),否则用本地缓存密文解密;
# 失败不阻断启动(.env 回退 / 等待下次登录后刷新)
try:
from webhost.backend.core.shell_updater import check_and_download
check_and_download()
except Exception as _exc: # noqa: BLE001 检查失败不阻断启动
_LOGGER.warning("启动壳子更新检查失败:%s", _exc)
from webhost.backend.core import creds_sync
_creds = creds_sync.load()
if _creds:
config.apply_creds(_creds)
_LOGGER.info("中心机敏感凭证下发完成(%s 个键)", len(_creds))
except Exception as _exc: # noqa: BLE001 下发失败不影响启动
_LOGGER.warning("加载中心机敏感凭证失败:%s", _exc)
# 账号:.env 不再配置 CONTROLPLANE_ACCOUNT,取最近活跃的本机会话账号(重启恢复)
from webhost.backend.core.session import _sess_active_account
_acct = config.CONTROLPLANE_ACCOUNT or _sess_active_account()
if _acct:
try:
_sync_licensing(_acct)
_LOGGER.info("启动同步离线授权票据成功(账号 %s)", _acct)
except Exception as _exc: # noqa: BLE001 首启/断网时同步失败不阻断,离线用缓存兜底
_LOGGER.warning("启动同步离线授权票据失败:%s", _exc)
# 启动即检查插件更新:有恢复的会话账号时后台同步(每次启动确定是否更新,不阻塞启动)
try:
from webhost.backend.core.session import _SESS
_accts = {_a for _, (_a, _t) in _SESS.items()}
except Exception: # noqa: BLE001
_accts = set()
if _accts:
_acct = next(iter(_accts))
threading.Thread(target=_boot_shell_check, daemon=True).start()
yield
def _boot_sync() -> None:
try:
from webhost.backend.core.plugin_sync import sync_plugins, SYNC_LOCK
with SYNC_LOCK:
sync_plugins(_acct)
load_plugins(_st.ALLOWED, reload=True)
_LOGGER.info("启动插件更新完成(账号 %s)", _acct)
except Exception as _exc: # noqa: BLE001 更新失败不阻断启动
_LOGGER.warning("启动插件更新失败:%s", _exc)
threading.Thread(target=_boot_sync, daemon=True).start()
# 启动即检查壳子(主程序)更新:有新版本自动下载,前端提示后由用户点击重启升级;
# 并常驻周期检查(默认 30 分钟),壳子长开时也能自动发现新版本
from webhost.backend.core import shell_updater as _shell_updater
_shell_updater.start_check()
_shell_updater.start_periodic_check()
yield
except BaseException:
# lifespan 失败会被 uvicorn 吞成 SystemExit(3);frozen 下 stderr 已重定向 devnull,
# 报错无处可看:崩溃现场记入 webhost.log,frozen 时并追加到 exe 同级 crash.log
import traceback
_tb = traceback.format_exc()
_LOGGER.error("启动初始化失败:\n%s", _tb)
if getattr(sys, "frozen", False):
try:
with open(Path(sys.executable).parent / "crash.log", "a", encoding="utf-8") as _f:
_f.write("\n[lifespan]\n" + _tb)
except OSError:
pass
raise
app = FastAPI(title="37du Web Host", lifespan=lifespan)
@@ -87,6 +115,7 @@ app.include_router(api_admin.router)
app.include_router(api_dingtalk.router)
app.include_router(api_meta.router)
app.include_router(api_runs.router)
app.include_router(api_plugin_ui.router)
if config.DIST.exists():