- libs: 新增 hr_sdk / hotel_report / dingtalk,更新 desktopauto - controlplane-next: SDK 管理模块(controller/entity/migrations)与前端视图 - electron-shell: 插件同步、注册表、runner 调整 - plugins: XQ0035/XQ0041/XQ0042/XQ0045_XQ0046/XQ0048/XQ0076/XQ0078 等版本更新 - tests/tools: 新增 SDK 兼容性检查与打包工具(sdk_pack.py、sdk_compat_check.py)
128 lines
4.8 KiB
JavaScript
128 lines
4.8 KiB
JavaScript
// 宿主插件元数据 / 平台权限解析(/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 sdkSync = require("./sdk-sync");
|
|
const { versionLt } = require("./crypto");
|
|
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;
|
|
}
|
|
}
|
|
|
|
// 调中心机获取插件云端信息(后台分类 / 按账号下发版本 / 通道 test|prod);
|
|
// 控制面不可达返回 null(调用方回退本地 plugin.json,且不显示通道徽章)
|
|
async function accountPluginCloud(account) {
|
|
if (!config.CONTROLPLANE_URL) return null;
|
|
try {
|
|
const r = await cp.request("GET", "/api/plugins", {
|
|
headers: cp.machineHeaders(),
|
|
params: { account },
|
|
timeout: 5,
|
|
});
|
|
const map = new Map();
|
|
for (const p of r.plugins || []) {
|
|
map.set(p.id, {
|
|
category: String(p.category || "").trim(),
|
|
version: String(p.version || p.latest_version || "").trim(),
|
|
// 服务端按账号判定:管理员且在测 → test,其余 prod(老版本服务端无此字段则留空)
|
|
channel: p.channel === "test" ? "test" : p.channel === "prod" ? "prod" : "",
|
|
status: String(p.status || ""),
|
|
});
|
|
}
|
|
return map;
|
|
} 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 [cloud, allowedPlats] = account
|
|
? await Promise.all([
|
|
plugins.length ? accountPluginCloud(account) : Promise.resolve(null),
|
|
accountAllowedPlatforms(account),
|
|
])
|
|
: [null, null];
|
|
// 云端信息回填:后台分类优先(未配置则保留插件包内 plugin.json 的分类);
|
|
// 同时下发通道(正式版/测试版)与云端版本,供前端标出「这是测试版还是正式版」
|
|
if (cloud) {
|
|
plugins = plugins.map((p) => {
|
|
const c = cloud.get(p.id);
|
|
if (!c) return p;
|
|
const localVer = String(p.version || "");
|
|
const cloudVer = c.version || "";
|
|
return {
|
|
...p,
|
|
category: c.category || p.category,
|
|
channel: c.channel, // test | prod | ""(服务端未下发)
|
|
cloud_version: cloudVer, // 按本账号权限应装的云端版本
|
|
update_available: !!cloudVer && !!localVer && cloudVer !== localVer && versionLt(localVer, cloudVer),
|
|
};
|
|
});
|
|
}
|
|
// 平台在线态:并行 + 单平台 2.5s 兜底,避免外网校验慢时整屏元数据被拖住
|
|
// (超时先按未登录展示,后台校验完成后会回填缓存,平台账号页再读即为最新)
|
|
const platforms = await Promise.all(
|
|
Object.entries(state.PLATFORMS).map(async ([pid, m]) => ({
|
|
id: pid,
|
|
label: m.label,
|
|
online: await platformAuth.isOnlineQuick(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(),
|
|
},
|
|
// SDK 概要:本地已装版本(id → versions)+ 上次同步结果,供设置页排查"插件跑不起来"
|
|
sdks: sdkSync.status(),
|
|
sdk_last_sync: sdkSync.lastResult(),
|
|
sdk_allow: sdkSync.allowInfo(),
|
|
};
|
|
}
|
|
|
|
module.exports = { buildMeta, accountAllowedPlatforms };
|