feat(electron-shell): 新增插件目录选择接口并将版本升至 1.10.0
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user