release: bump version to 1.1.7, update xq0031_xq0032 plugin to 1.0.8

主要变更:
1. 整体版本升级至1.1.7,更新安装包与shell版本号
2. 新增API与后端能力:
   - 新增停止运行接口,支持强制终止插件进程与浏览器子进程
   - 云端会话令牌与下载票据落库,适配多worker部署
   - 优化Chrome版本读取逻辑,避免弹窗与编码问题
3. xq0031_xq0032插件升级至1.0.8:
   - 新增仓库中文名自动筛选功能,简化用户操作
   - 优化ERP登录与报表导出流程,修复标签页残留问题
   - 新增前端强制停止按钮,支持实时终止运行
   - 修复中文编码与乱码问题,兼容Windows非UTF-8环境
4. 修复授权校验逻辑,确保账号与授权匹配
5. 更新文档与部署脚本,修正发版流程说明
This commit is contained in:
2026-09-17 23:25:33 +08:00
parent b32f8e8fe2
commit a649a938e6
29 changed files with 975 additions and 2015 deletions
+16 -1
View File
@@ -13,7 +13,7 @@ from fastapi import APIRouter, HTTPException, Request, WebSocket
from webhost.backend import licensing
from webhost.backend import scheduler as _scheduler
from webhost.backend import state as _st
from webhost.backend.core.runner import RunReq, _run_target
from webhost.backend.core.runner import RunReq, _run_target, terminate_run
from webhost.backend.core.hub import HUB
from webhost.backend.plugins import PLUGINS
from webhost.backend.core.session import _require_login, _sess_account
@@ -94,6 +94,21 @@ def get_run(run_id: str, request: Request) -> dict:
return run
@router.post("/api/runs/{run_id}/stop")
def stop_run(run_id: str, request: Request) -> dict:
"""手动强制停止指定运行:仅运行属主可操作,整树强杀执行子进程(含浏览器)。"""
account = _require_login(request)
with _st.RUN_LOCK:
run = _st.RUNS.get(run_id)
if not run or run.get("account") != account:
raise HTTPException(404, "运行不存在")
if run.get("status") != "running":
raise HTTPException(409, "运行已结束,无需停止")
if not terminate_run(run_id):
raise HTTPException(409, "任务尚未真正启动(排队中或刚结束),请稍候再试")
return {"ok": True}
@router.websocket("/ws")
async def ws(websocket: WebSocket):
if not _sess_account(websocket): # WS 握手需有效统一账户会话
@@ -116,9 +116,10 @@ def _read_version(exe: Path) -> str:
import subprocess as _sp
try:
out2 = _sp.run(
["powershell", "-NoProfile", "-Command",
["powershell", "-NoProfile", "-NonInteractive", "-Command",
"(Get-Item -LiteralPath '%s').VersionInfo.ProductVersion" % exe],
capture_output=True, text=True, timeout=5)
capture_output=True, text=True, timeout=5,
creationflags=getattr(_sp, "CREATE_NO_WINDOW", 0)) # 不弹 PowerShell 窗口
v = (out2.stdout or "").strip()
return v if _VERSION_RE.match(v) else ""
except Exception: # noqa: BLE001
+14 -5
View File
@@ -145,13 +145,16 @@ def license_status() -> tuple[str, dict | None]:
def ensure_license(account: str) -> tuple[bool, dict | None]:
"""确保本地授权票据可用:ok → (True, payload);否则联网刷新一次后复查。
"""确保本地授权票据可用且属于当前账号:ok → (True, payload);否则联网刷新一次后复查。
票据必须与登录账号一致:票据只按 expiresAt 判过期,换账号登录后旧票仍在有效期内,
沿用旧票会让「个人中心可见插件」与「运行门禁」停留在上一账号的授权快照
(表现为换账号后显示"暂无可用插件"),故账号不匹配一律视为不可用并强制刷新。
刷新失败(离线/控制面不可达)→ (False, None)。这是「可见性/运行/平台登录」的统一授权门禁,
过期且实际在线时会自动刷新恢复(用户无感),离线则拒绝并提示联网刷新。
"""
status, payload = license_status()
if status == "ok":
if status == "ok" and (payload or {}).get("userId") == account:
return True, payload
try:
from webhost.backend.core.cpapi import _sync_licensing # 延迟导入,避免模块环
@@ -159,7 +162,7 @@ def ensure_license(account: str) -> tuple[bool, dict | None]:
except Exception as _exc: # noqa: BLE001 联网刷新失败(离线/控制面不可达)
_LOGGER.warning("授权票据联网刷新失败(离线或控制面不可达):%s", _exc)
status, payload = license_status()
return (status == "ok"), payload
return (status == "ok" and (payload or {}).get("userId") == account), payload
# ==================== 缓存写读 ====================
@@ -285,11 +288,17 @@ def _push_report(rec: dict) -> bool:
def _push_via_tempfile(rec: dict) -> None:
"""向 /api/runtime/report 的同步 POST(requests)。"""
"""向 /api/runtime/report 的同步 POST(requests)。
必须带 X-API-Token 内部凭证:中心机 CONTROLPLANE_TOKEN 非空时该接口强制校验,
无头 POST 一律 401(此前运行上报全部静默失败落离线暂存、补报同样无头永远补不上),
与 cpapi.py 各接口的头注入保持一致。"""
import requests
from webhost.backend.core import config
headers = {"X-API-Token": config.CONTROLPLANE_TOKEN} if config.CONTROLPLANE_TOKEN else {}
r = requests.post(f"{_CONTROLPLANE_URL}/api/runtime/report",
json=rec, timeout=5)
json=rec, headers=headers, timeout=5)
r.raise_for_status()
+3 -1
View File
@@ -32,7 +32,9 @@ def _plugin_schema(p) -> dict:
fields = p.fields
caps = (manifest or {}).get("capabilities") or p.capabilities
perms = (manifest or {}).get("permissions") or p.permissions
return {"id": p.id, "name": name, "version": p.version,
return {"id": p.id, "name": name,
# 版本优先取 plugin.json 的 version(与发布包一致),缺 manifest 时回退类的默认值
"version": (manifest or {}).get("version") or p.version,
"description": description, "uses_month": getattr(p, "uses_month", False),
"ui": bool((manifest or {}).get("ui")),
"capabilities": caps, "permissions": perms, "fields": fields}
+11 -7
View File
@@ -35,10 +35,12 @@ except OSError:
def _emit(obj: dict) -> None:
"""写一行 JSON 到协议通道(原始 stdout)。插件 print 已改道 stderr,不污染协议。"""
"""写一行 JSON 到协议通道(原始 stdout.buffer,显式 UTF-8 字节)。
插件 print 已改道 stderr,不污染协议;不走文本层是避免 Windows GBK 环境下
stdout 按 locale 编码导致中文变 mojibake(父进程按 UTF-8 解码会对不上)。"""
try:
_PROTO.write(json.dumps(obj, ensure_ascii=False) + "\n")
_PROTO.flush()
_PROTO.buffer.write((json.dumps(obj, ensure_ascii=False) + "\n").encode("utf-8"))
_PROTO.buffer.flush()
except Exception: # noqa: BLE001 通道已关则静默
pass
@@ -65,12 +67,14 @@ def _run() -> int:
if "--allowed" in sys.argv else "")
allowed = {s for s in allowed_arg.split(",") if s} if allowed_arg else None
# fields 经 stdin 传入(单行 JSON)
# fields 经 stdin 传入(单行 JSON,UTF-8 字节):显式走 buffer 按 UTF-8 解,
# 不依赖 sys.stdin 的 locale 解码(Windows GBK 环境下中文会被解出乱码/孤立代理字符,
# 导致 fields 值与插件内字符串常量比对失败,如「未知执行模式」)
fields: dict = {}
try:
_line = sys.stdin.readline().strip()
if _line:
fields = json.loads(_line) or {}
_raw = sys.stdin.buffer.readline().strip()
if _raw:
fields = json.loads(_raw) or {}
except Exception as _e: # noqa: BLE001
fields = {}
+45 -1
View File
@@ -32,6 +32,34 @@ class RunReq(BaseModel):
fields: dict = {}
# ==================== 手动强制停止 ====================
# run_id → 执行中 Job 句柄(供 POST /api/runs/{id}/stop 整树强杀,含浏览器孙进程)
_ACTIVE: dict = {}
_ACTIVE_LOCK = threading.Lock()
_USER_STOPPED: set = set()
_STOP_LOCK = threading.Lock()
def terminate_run(run_id: str) -> bool:
"""手动终止运行:登记停止标记并整树强杀 Job。返回是否已找到并触发终止。"""
with _ACTIVE_LOCK:
job = _ACTIVE.get(run_id)
with _STOP_LOCK:
_USER_STOPPED.add(run_id)
if job is None:
return False # 尚未真正拉起执行子进程(排队中)或已结束
try:
job.terminate()
except Exception:
pass
return True
def _is_user_stopped(run_id: str) -> bool:
with _STOP_LOCK:
return run_id in _USER_STOPPED
def _run_target(plugin, fields: dict, run_id: str) -> None:
"""进程级隔离执行插件:拉起独立 python 子进程,stdout JSON 事件转发 /ws,超时强杀。
@@ -55,14 +83,24 @@ def _run_target(plugin, fields: dict, run_id: str) -> None:
# Windows Job Object:整树托管(含浏览器孙进程),超时整树强杀 + 内存上限兜底
job = _winjob.Job(max_mem_mb=max_mem_mb)
# 子进程 stdio 编码统一 UTF-8:默认跟随 Windows locale(GBK) 会导致
# stderr 中文 traceback 变 mojibake、stdin JSON 中文解出孤立代理字符
_child_env = dict(os.environ)
_child_env["PYTHONIOENCODING"] = "utf-8"
_child_env["PYTHONUTF8"] = "1"
try:
proc = subprocess.Popen(
cmd,
cwd=str(root), stdin=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, text=True, encoding="utf-8",
errors="replace",
errors="replace", env=_child_env,
# 抑制宿主进程的控制台窗口(runner.exe 为 console 子系统),
# 同时 stdout/stderr 走 PIPE 捕获不受影响
creationflags=getattr(subprocess, "CREATE_NO_WINDOW", 0),
)
job.assign(proc)
with _ACTIVE_LOCK:
_ACTIVE[run_id] = job # 登记句柄,供手动强制停止整树强杀
except Exception as e: # noqa: BLE001 子进程拉起失败
job.close()
_st._set_run(run_id, status="error", result=None, error=f"拉起执行子进程失败: {e}")
@@ -134,6 +172,10 @@ def _run_target(plugin, fields: dict, run_id: str) -> None:
result=ev.get("result"), error=ev.get("error"))
HUB.publish({"t": "run_done", "run_id": run_id, "ok": ok,
"error": ev.get("error")})
elif _is_user_stopped(run_id):
msg = "用户手动强制停止"
_st._set_run(run_id, status="error", result=None, error=msg)
HUB.publish({"t": "run_done", "run_id": run_id, "ok": False, "error": msg})
elif timed_out:
msg = f"插件执行超时({timeout}s)已强制终止"
_st._set_run(run_id, status="error", result=None, error=msg)
@@ -143,6 +185,8 @@ def _run_target(plugin, fields: dict, run_id: str) -> None:
_st._set_run(run_id, status="error", result=None, error=msg)
HUB.publish({"t": "run_done", "run_id": run_id, "ok": False, "error": msg})
finally:
with _ACTIVE_LOCK:
_ACTIVE.pop(run_id, None)
_scheduler.mark_done(plugin.id, run_id) # 单活槽位回空闲并唤醒排队请求
_report_run(plugin.id, run_id) # 运行上报(联网实时/离线暂存补报)
job.close() # KILL_ON_JOB_CLOSE 兜底清理残留子进程
+9
View File
@@ -383,9 +383,18 @@ async function onShellDownload() {
if (downloading.value) return
downloading.value = true
shellDismissed.value = false
// 点击即进入"下载中"反馈(不等轮询):内网直连下载很快,若靠 15s 轮询拉状态,
// 进度条可能还没显示就已经下载完,用户会以为点了没反应
const v = shellUpdate.value.latest || ''
shellUpdate.value = { ...shellUpdate.value,
dl: { status: 'downloading', version: v, received: 0, total: 0, pct: 0, error: '' } }
lastDlStatus = 'downloading' // 兜底:即使立即下载完成,也能触发"已就绪"一次性提示
try {
await downloadShellUpdate() // 后端后台流式下载,进度经轮询展示
try { shellUpdate.value = await getShellStatus() } catch (_) {} // 抢拉真实进度,避免卡在 0%
} catch (e) {
shellUpdate.value = { ...shellUpdate.value,
dl: { status: 'failed', version: v, received: 0, total: 0, pct: 0, error: (e.message || e) } }
ElMessage.error('开始下载失败:' + (e.message || e))
}
downloading.value = false
+2 -2
View File
@@ -1,11 +1,11 @@
; 37du 自动化工作台 - Inno Setup 安装脚本 (Inno Setup 7)
; 37du 自动化工作台 - Inno Setup 安装脚本 (Inno Setup 7)
; 编译: "C:\Program Files\Inno Setup 7\ISCC.exe" webhost\tools\install.iss
; 打包内容: 主程序 37du-host.exe + 插件执行壳 37du-host-runner.exe + .env 默认配置
; .env 与 webhost/.env 同源(控制面/平台共享配置):仅首次安装写入(onlyifdoesntexist),
; 升级不覆盖机器已有 .env;不含 37du-host-console.exe(调试版)、plugins/(登录后自下载)
#define MyAppName "37du 自动化工作台"
#define MyAppVersion "1.1.3"
#define MyAppVersion "1.1.7"
#define MyAppExeName "37du-host.exe"
[Setup]
+1 -1
View File
@@ -1 +1 @@
1.1.3
1.1.7