feat(electron-shell): 新增插件目录选择接口并将版本升至 1.10.0

This commit is contained in:
2026-10-30 10:00:18 +08:00
parent 526116af83
commit 210de5b68b
337 changed files with 3254 additions and 49349 deletions
@@ -18,6 +18,18 @@ function versionKey(v: string): number[] {
return String(v || '').split('.').map(s => parseInt(s, 10) || 0);
}
/** 版本号按数值语义比较(数组直接比大小会退化成字符串比较,"1.1.10" 会被判成小于 "1.1.9") */
function versionGt(a: string, b: string): boolean {
const ka = versionKey(a);
const kb = versionKey(b);
for (let i = 0; i < Math.max(ka.length, kb.length); i++) {
const x = ka[i] || 0;
const y = kb[i] || 0;
if (x !== y) return x > y;
}
return false;
}
/**
* 插件管理(对齐旧 FastAPI apis/admin.py 插件部分)
* - GET /api/admin/plugins:插件列表(分页 + 搜索 + 版本历史 + 授权账号)
@@ -164,7 +176,7 @@ export class AdminPluginController extends BaseController {
);
// 更新 latest_version(若更高)
const cur = await this.pluginRepo.findOneBy({ id: pluginId });
if (cur && versionKey(cur.latestVersion) < versionKey(version)) {
if (cur && versionGt(version, cur.latestVersion)) {
await this.pluginRepo.update({ id: pluginId }, { latestVersion: version });
}
// 仅保留最近 3 个版本(DB + 磁盘)
@@ -55,7 +55,7 @@ export class ApiMiscController extends BaseController {
.getMany();
if (!rows.length) return { available: false, category: (category || '').trim() };
// 版本号按数值语义取最新("1.10" > "1.9")
const r = rows.reduce((a, b) => (versionKey(b.version) > versionKey(a.version) ? b : a));
const r = rows.reduce((a, b) => (versionGt(b.version, a.version) ? b : a));
return {
available: true,
category: r.category,
@@ -236,6 +236,18 @@ function versionKey(v: string): number[] {
.map(s => parseInt(s, 10) || 0);
}
/** 逐段数值比较(数组直接比大小会退化成字符串比较,"1.10" 会被判成小于 "1.9") */
function versionGt(a: string, b: string): boolean {
const ka = versionKey(a);
const kb = versionKey(b);
for (let i = 0; i < Math.max(ka.length, kb.length); i++) {
const x = ka[i] || 0;
const y = kb[i] || 0;
if (x !== y) return x > y;
}
return false;
}
/** 时间格式化为 'YYYY-MM-DD HH:mm:ss'(null 返回 null) */
function fmtDt(d: Date | null): string | null {
if (!d) return null;
+8
View File
@@ -1,5 +1,13 @@
# 更新日志
## 1.10.0(2026-10-29)
### 新增
- 本机接口 `POST /api/dialog/directory`:插件 UI 可调起原生「选择文件夹」对话框并拿到绝对路径
(仅登录态可用,只返回路径、不读文件),插件里的目录类参数不再只能手输
- 首个接入:CRM数据导出(xq0048)「保存目录」旁新增「选择」按钮
## 1.9.3(2026-10-29)
### 改进
+16
View File
@@ -455,6 +455,22 @@ async function route(req, res, url) {
return sendJson(res, 200, data);
}
// ---------- 本机目录选择(插件 UI 用:原生「选择文件夹」对话框,仅返回路径) ----------
if (p === "/api/dialog/directory" && method === "POST") {
session.requireLogin(cookies);
const body = await readJsonBody(req);
const { dialog, BrowserWindow } = require("electron");
const win = BrowserWindow.getAllWindows().find((w) => !w.isDestroyed()) || null;
const opts = {
title: String(body.title || "选择文件夹"),
properties: ["openDirectory", "createDirectory"],
defaultPath: String(body.current || "") || undefined,
};
const r = win ? await dialog.showOpenDialog(win, opts) : await dialog.showOpenDialog(opts);
const picked = (r.filePaths || [])[0] || "";
return sendJson(res, 200, { ok: true, canceled: !!r.canceled || !picked, path: picked });
}
if (p === "/api/plugins/sync" && method === "POST") {
const account = session.requireLogin(cookies);
const result = await pluginSync.withSyncLock(async () => {
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "37du-electron-shell",
"productName": "37du 自动化工作台",
"version": "1.9.3",
"version": "1.10.0",
"description": "37du 执行机 Node/Electron 客户端(替代 Python webhost 底座,插件保持 Python 子进程执行)",
"main": "electron/main.js",
"private": true,