// 宿主插件元数据 / 平台权限解析(/api/meta 聚合)。 // 对齐 Python core/meta.py:插件可见性 = 本地授权票据快照;平台白名单来自中心机。 "use strict"; const cp = require("./cpclient"); const config = require("./config"); const licensing = require("./licensing"); const registry = require("./registry"); const platformAuth = require("./platform-auth"); const state = require("./state"); const envSync = require("./env-sync"); const { makeLogger } = require("./logger"); const logger = makeLogger("meta"); // 调中心机获取账号可登录平台白名单;控制面不可达返回 null(调用方决定拒绝) async function accountAllowedPlatforms(account) { if (!config.CONTROLPLANE_URL) return null; try { const r = await cp.request("GET", "/api/platforms/allowed", { headers: cp.machineHeaders(), params: { account }, timeout: 5, }); return new Set(r.allowed || []); } catch (e) { return null; } } // /api/meta 聚合响应 async function buildMeta(account) { let authExpired = false; let plugins = []; if (account) { const lic = await licensing.ensureLicense(account); if (lic.ok) { const allowed = new Set((lic.payload || {}).plugins.map((p) => p.pluginId)); for (const entry of registry.listLocalPlugins()) { if (allowed.has(entry.id)) plugins.push(registry.pluginSchema(entry.id)); } } else { authExpired = true; } } const allowedPlats = account ? await accountAllowedPlatforms(account) : null; const platforms = []; for (const [pid, m] of Object.entries(state.PLATFORMS)) { platforms.push({ id: pid, label: m.label, online: await platformAuth.isOnline(pid, account), // 按当前账号的会话校验 allowed: allowedPlats === null ? true : allowedPlats.has(pid), }); } return { appName: "37du 自动化工作台", dingtalkScan: !!config.CONTROLPLANE_URL, authExpired, // 授权票据概要:常驻态进状态栏 / 票据卡(剩余天数),异常态才升级为横幅 license: licensing.licenseInfo(), platforms, plugins, // 环境包(便携 Python 运行时)概要:设置页/状态栏展示,空 = 未安装 env: { version: envSync.readCurrent() || "", installed: !!envSync.readCurrent(), }, }; } module.exports = { buildMeta, accountAllowedPlatforms };