Files
37duAutomation/desktop/webhost/backend/core/meta.py
T
puddy a649a938e6 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. 更新文档与部署脚本,修正发版流程说明
2026-09-17 23:25:33 +08:00

98 lines
4.0 KiB
Python

# -*- coding: utf-8 -*-
"""webhost 宿主插件元数据 / 平台权限解析。
- 插件元数据由 plugin.json(manifest) 驱动,离线与旧插件兼容
- 平台/插件白名单来自中心机,按账号过滤(三态降级:授权集 / 空集防越权 / None 离线兜底全量)
"""
from __future__ import annotations
import json
import logging
import sys
from pathlib import Path
from webhost.backend.core import config
_LOGGER = logging.getLogger(__name__)
def _plugin_schema(p) -> dict:
"""组装插件元数据(manifest 驱动)。
plugin.json(与插件代码同目录)为权威:存在则其字段/能力/权限优先,仅当缺失时才
回退到 ScenePlugin 类上的 fields/capabilities,保证离线与旧插件兼容。
"""
manifest = _read_own_manifest(p)
name = (manifest or {}).get("name") or p.name
description = (manifest or {}).get("description")
if description is None:
description = p.description
fields = _fields_from_schema((manifest or {}).get("fields")) if manifest else None
if fields is None:
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,
# 版本优先取 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}
def _read_own_manifest(p) -> dict | None:
"""读取与插件注册模块同目录的 plugin.json;缺文件或解析失败返回 None(不阻断)。"""
try:
mod = sys.modules.get(type(p).__module__)
jar = (mod and Path(mod.__file__).resolve().parent / "plugin.json")
if not jar or not jar.is_file():
return None
return json.loads(jar.read_text(encoding="utf-8"))
except Exception: # noqa: BLE001
return None
def _fields_from_schema(schema: dict) -> list | None:
"""JSON-Schema(object.properties) → 前端表单 [{key,label,type,default,options}]。"""
if not schema or schema.get("type") != "object" or not schema.get("properties"):
return None
out = []
for key, prop in schema["properties"].items():
item = {"key": key, "label": prop.get("title", key),
"default": prop.get("default", "")}
t = prop.get("type", "string")
if t == "integer" or t == "number":
item["type"] = "int"
elif t == "string" and "enum" in prop:
item["type"] = "select"
item["options"] = prop["enum"]
elif t == "string" and prop.get("format") == "password":
item["type"] = "password"
elif t == "array":
# 多选:items.enum 为预设选项;无 enum 则纯自由输入(前端 tags 可自建条目)
item["type"] = "multiselect"
if isinstance(prop.get("items"), dict) and "enum" in prop["items"]:
item["options"] = prop["items"]["enum"]
else:
item["type"] = "text"
d = prop.get("description")
if d:
item["description"] = d
out.append(item)
return out
def _account_allowed_platforms(account: str) -> set | None:
"""调中心机获取账号可登录平台白名单;控制面不可达返回 None(调用方决定拒绝)。"""
if not config.CONTROLPLANE_URL:
return None
import requests
headers = {"X-API-Token": config.CONTROLPLANE_TOKEN} if config.CONTROLPLANE_TOKEN else {}
try:
r = requests.get(f"{config.CONTROLPLANE_URL}/api/platforms/allowed",
params={"account": account}, headers=headers, timeout=5)
r.raise_for_status()
return set(r.json().get("allowed", []))
except Exception: # noqa: BLE001
return None