新增 FastAPI 文件服务器核心模块(配置、鉴权、存储、心跳上报),新增 HTTP 路由接口(健康检查、文件上传/下载/删除、管理登录/密码修改/统计),新增 Vue3 管理页面源码;新增 MySQL 元数据存储支持,新增 PyMySQL 依赖;新增 .gitignore 忽略 IDE 与备份文件;新增文件服务器工具脚本;删除旧的 build/ 脚本与 exe 构建产物,优化 Electron 平台登录逻辑为纯接口模式,新增平台账号环境变量注入,优化试用期异常检查逻辑,拆分服务岗转正流程为独立脚本。
123 lines
4.4 KiB
JavaScript
123 lines
4.4 KiB
JavaScript
// 插件注册表:读取 plugins/<id>/plugin.json 元数据(manifest 驱动,与 Python meta.py 语义一致)。
|
|
"use strict";
|
|
|
|
const fs = require("fs");
|
|
const path = require("path");
|
|
const config = require("./config");
|
|
const { makeLogger } = require("./logger");
|
|
|
|
const logger = makeLogger("registry");
|
|
|
|
function pluginRoot() {
|
|
return config.pluginRoot();
|
|
}
|
|
|
|
// 本地已落盘插件条目(目录包含 __init__.py 或 plugin.json,后者兜底下载中断的残缺目录)
|
|
function listLocalPlugins() {
|
|
const root = pluginRoot();
|
|
const out = [];
|
|
if (!fs.existsSync(root)) return out;
|
|
for (const name of fs.readdirSync(root)) {
|
|
if (name.startsWith("_") || name === "__pycache__") continue;
|
|
const full = path.join(root, name);
|
|
let stat;
|
|
try {
|
|
stat = fs.statSync(full);
|
|
} catch (e) {
|
|
continue;
|
|
}
|
|
if (stat.isDirectory()) {
|
|
if (fs.existsSync(path.join(full, "__init__.py")) || fs.existsSync(path.join(full, "plugin.json"))) {
|
|
out.push({ id: name, dir: full });
|
|
}
|
|
}
|
|
}
|
|
return out;
|
|
}
|
|
|
|
// 读取插件 manifest;缺文件/解析失败返回 null(不阻断)
|
|
function readManifest(pluginId) {
|
|
const mf = path.join(pluginRoot(), pluginId, "plugin.json");
|
|
if (!fs.existsSync(mf)) return null;
|
|
try {
|
|
const data = JSON.parse(fs.readFileSync(mf, "utf-8"));
|
|
return data && typeof data === "object" ? data : null;
|
|
} catch (e) {
|
|
logger.warning(`插件 ${pluginId} plugin.json 解析失败:${e.message}`);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
// JSON-Schema(object.properties) → 前端表单 [{key,label,type,default,options,description}]
|
|
function fieldsFromSchema(schema) {
|
|
if (!schema || schema.type !== "object" || !schema.properties) return null;
|
|
const out = [];
|
|
for (const [key, prop] of Object.entries(schema.properties)) {
|
|
const item = { key, label: prop.title || key, default: prop.default ?? "" };
|
|
const t = prop.type || "string";
|
|
if (t === "integer" || t === "number") item.type = "int";
|
|
else if (t === "string" && Array.isArray(prop.enum)) {
|
|
item.type = "select";
|
|
item.options = prop.enum;
|
|
} else if (t === "string" && prop.format === "password") item.type = "password";
|
|
else if (t === "array") {
|
|
item.type = "multiselect";
|
|
if (prop.items && Array.isArray(prop.items.enum)) item.options = prop.items.enum;
|
|
} else item.type = "text";
|
|
if (prop.description) item.description = prop.description;
|
|
out.push(item);
|
|
}
|
|
return out;
|
|
}
|
|
|
|
// 组装插件元数据(manifest 驱动,与 Python meta._plugin_schema 一致)
|
|
function pluginSchema(pluginId) {
|
|
const manifest = readManifest(pluginId);
|
|
const base = {
|
|
id: pluginId,
|
|
name: pluginId,
|
|
version: "0",
|
|
description: "",
|
|
uses_month: false,
|
|
ui: false,
|
|
capabilities: [],
|
|
permissions: {},
|
|
fields: [],
|
|
};
|
|
if (!manifest) return base;
|
|
const fields = fieldsFromSchema(manifest.fields);
|
|
return {
|
|
id: manifest.id || pluginId,
|
|
name: manifest.name || pluginId,
|
|
version: manifest.version || "0",
|
|
description: manifest.description || "",
|
|
uses_month: !!manifest.uses_month,
|
|
ui: !!manifest.ui,
|
|
platform: manifest.platform || "", // hr / oa / ""(前端平台徽章 + 运行并发闸按(账号,平台)隔离)
|
|
platforms: Array.isArray(manifest.platforms) && manifest.platforms.length
|
|
? manifest.platforms // 插件声明的全部平台依赖(运行前登录态预检按此逐个检查)
|
|
: manifest.platform ? [manifest.platform] : [], // 缺省回退单 platform 字段
|
|
min_runtime_version: manifest.minRuntimeVersion || "", // 版本兼容校验声明(安装时强校验,此处透传前端展示)
|
|
capabilities: manifest.capabilities || [],
|
|
permissions: manifest.permissions || {},
|
|
fields: fields || [],
|
|
};
|
|
}
|
|
|
|
function find(pluginId) {
|
|
const dir = path.join(pluginRoot(), pluginId);
|
|
if (!fs.existsSync(dir) || !fs.statSync(dir).isDirectory()) throw new Error(`插件不存在: ${pluginId}`);
|
|
const manifest = readManifest(pluginId);
|
|
if (!manifest && !fs.existsSync(path.join(dir, "__init__.py"))) {
|
|
throw new Error(`插件不存在: ${pluginId}`);
|
|
}
|
|
return { id: pluginId, dir, manifest, ...pluginSchema(pluginId) };
|
|
}
|
|
|
|
function findByName(name) {
|
|
// 供 /api/runs 以插件名查找(与 PLUGINS.find 语义对齐)
|
|
return find(name);
|
|
}
|
|
|
|
module.exports = { pluginRoot, listLocalPlugins, readManifest, fieldsFromSchema, pluginSchema, find };
|