@ququ-jiaxk/dsh-plugin-center 0.1.44 → 0.1.46
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/client.js +127 -29
- package/lib/index.js +72 -3
- package/package.json +1 -1
package/lib/client.js
CHANGED
|
@@ -36,7 +36,7 @@ var logo_default = 'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" v
|
|
|
36
36
|
|
|
37
37
|
// src/client.tsx
|
|
38
38
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
39
|
-
var PLUGIN_VERSION = true ? "0.1.
|
|
39
|
+
var PLUGIN_VERSION = true ? "0.1.46" : "0.0.0";
|
|
40
40
|
var PANEL_ID = "plugin-center";
|
|
41
41
|
var inject = ["slots", "remote", "remote.pluginManager"];
|
|
42
42
|
var hostCtx = null;
|
|
@@ -50,6 +50,16 @@ var CATEGORIES = [
|
|
|
50
50
|
{ id: "design", label: "\u8BBE\u8BA1" },
|
|
51
51
|
{ id: "other", label: "\u5176\u4ED6" }
|
|
52
52
|
];
|
|
53
|
+
function isExperimentalBundle(bundle) {
|
|
54
|
+
return bundle.name.includes("experimental");
|
|
55
|
+
}
|
|
56
|
+
function localCategory(bundle) {
|
|
57
|
+
if (bundle.availability === "missing") return "offered";
|
|
58
|
+
if (isExperimentalBundle(bundle)) return "experimental";
|
|
59
|
+
if (bundle.optional) return "optional";
|
|
60
|
+
if (bundle.availability === "installation") return "builtin";
|
|
61
|
+
return "third";
|
|
62
|
+
}
|
|
53
63
|
var panelSnapshot = null;
|
|
54
64
|
var selfUpdateTarget = null;
|
|
55
65
|
var selfUpdatePolling = false;
|
|
@@ -369,45 +379,69 @@ function InstalledList({
|
|
|
369
379
|
bundles,
|
|
370
380
|
centerItems,
|
|
371
381
|
query,
|
|
382
|
+
filter,
|
|
372
383
|
onOpen,
|
|
373
|
-
onUninstall
|
|
384
|
+
onUninstall,
|
|
385
|
+
onToggle,
|
|
386
|
+
onInstall
|
|
374
387
|
}) {
|
|
375
388
|
const center = new Map(centerItems.map((item) => [item.packageName, item]));
|
|
376
389
|
const keyword = query.trim().toLowerCase();
|
|
377
|
-
const list = bundles.filter((bundle) => {
|
|
390
|
+
const list = bundles.filter((bundle) => bundle.listedByDefault !== false || bundle.enabled).filter((bundle) => {
|
|
391
|
+
if (filter === "all") return true;
|
|
392
|
+
if (filter === "disabled") return !bundle.enabled;
|
|
393
|
+
return localCategory(bundle) === filter;
|
|
394
|
+
}).filter((bundle) => {
|
|
378
395
|
if (!keyword) return true;
|
|
379
396
|
const display = center.get(bundle.name)?.displayName ?? "";
|
|
380
397
|
return bundle.name.toLowerCase().includes(keyword) || display.toLowerCase().includes(keyword);
|
|
381
|
-
});
|
|
398
|
+
}).sort((left, right) => Number(right.enabled) - Number(left.enabled) || left.name.localeCompare(right.name));
|
|
382
399
|
if (list.length === 0) {
|
|
383
400
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "pcx-empty", children: [
|
|
384
401
|
keyword ? "\u6CA1\u6709\u5339\u914D\u7684\u672C\u673A\u63D2\u4EF6" : "\u672C\u673A\u8FD8\u6CA1\u6709\u5B89\u88C5\u63D2\u4EF6",
|
|
385
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "pcx-empty-hint", children: "\u8FD9\u91CC\u5217\u51FA DSH \u63D2\u4EF6\u7BA1\u7406\u5668\u626B\u63CF\u5230\u7684\u672C\u673A\u63D2\u4EF6\uFF0C\u5305\u542B\u672A\u5728\u4E2D\u5FC3\u4E0A\u67B6\u7684" })
|
|
402
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "pcx-empty-hint", children: "\u8FD9\u91CC\u5217\u51FA DSH \u63D2\u4EF6\u7BA1\u7406\u5668\u626B\u63CF\u5230\u7684\u672C\u673A\u63D2\u4EF6\uFF0C\u5305\u542B\u5185\u7F6E\u3001\u5B9E\u9A8C\u6027\u548C\u672A\u5728\u4E2D\u5FC3\u4E0A\u67B6\u7684" })
|
|
386
403
|
] });
|
|
387
404
|
}
|
|
388
405
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "pcx-grid", children: list.map((bundle) => {
|
|
389
406
|
const item = center.get(bundle.name);
|
|
407
|
+
const missing = bundle.availability === "missing";
|
|
390
408
|
const localInstall = !bundle.source || /(?:^|[^a-z0-9])(?:file|link):/iu.test(bundle.source);
|
|
409
|
+
const experimental = bundle.name.includes("experimental") || Boolean(bundle.optional);
|
|
391
410
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("article", { className: "pcx-card", children: [
|
|
392
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
411
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
412
|
+
"div",
|
|
413
|
+
{
|
|
414
|
+
className: "pcx-card-main",
|
|
415
|
+
style: missing ? { cursor: "default" } : void 0,
|
|
416
|
+
onClick: missing ? void 0 : () => onOpen(bundle.name),
|
|
417
|
+
children: [
|
|
418
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "pcx-card-top", children: [
|
|
419
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "pcx-icon", children: iconLetter(item?.displayName ?? bundle.name) }),
|
|
420
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "pcx-card-titles", children: [
|
|
421
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "pcx-row", children: [
|
|
422
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "pcx-name", children: item?.displayName ?? bundle.name }),
|
|
423
|
+
missing ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "pcx-badge", children: "\u672A\u5B89\u88C5" }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: `pcx-badge ${bundle.enabled ? "pcx-badge-ok" : "pcx-badge-warn"}`, children: bundle.enabled ? "\u5DF2\u542F\u7528" : "\u5DF2\u505C\u7528" }),
|
|
424
|
+
bundle.availability === "installation" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "pcx-badge", children: "\u5185\u7F6E" }) : null,
|
|
425
|
+
experimental ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "pcx-badge", children: "\u5B9E\u9A8C\u6027" }) : null,
|
|
426
|
+
bundle.optional ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "pcx-badge", children: "\u53EF\u9009" }) : null,
|
|
427
|
+
bundle.error ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "pcx-badge pcx-badge-danger", children: "\u8BFB\u53D6\u5F02\u5E38" }) : null,
|
|
428
|
+
item ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "pcx-badge", children: "\u672A\u4E0A\u67B6" })
|
|
429
|
+
] }),
|
|
430
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "pcx-pkg", children: bundle.name })
|
|
431
|
+
] })
|
|
401
432
|
] }),
|
|
402
|
-
/* @__PURE__ */ (0, import_jsx_runtime.
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
433
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "pcx-foot", children: [
|
|
434
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "pcx-foot-owner", children: missing ? "DSH \u81EA\u5E26\uFF0C\u53EF\u5B89\u88C5" : bundle.official ? "\u968F DSH \u5B89\u88C5" : localInstall ? "\u672C\u5730\u5305\u5B89\u88C5" : "registry \u5B89\u88C5" }),
|
|
435
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "pcx-foot-meta", children: bundle.version ? `v${bundle.version}` : bundle.installTarget?.version ? `v${bundle.installTarget.version}` : "\u7248\u672C\u672A\u77E5" })
|
|
436
|
+
] })
|
|
437
|
+
]
|
|
438
|
+
}
|
|
439
|
+
),
|
|
440
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "pcx-card-actions", children: [
|
|
441
|
+
missing && bundle.installTarget ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { className: "pcx-btn pcx-btn-primary pcx-btn-sm", onClick: () => onInstall(bundle.name), children: "\u5B89\u88C5" }) : null,
|
|
442
|
+
!missing && bundle.name !== "@ququ-jiaxk/dsh-plugin-center" && (bundle.optional || bundle.installed) ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { className: "pcx-btn pcx-btn-sm", onClick: () => onToggle(bundle.name, !bundle.enabled), children: bundle.enabled ? "\u505C\u7528" : "\u542F\u7528" }) : null,
|
|
443
|
+
bundle.removable ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { className: "pcx-btn pcx-btn-sm pcx-btn-danger", onClick: () => onUninstall(bundle.name), children: "\u5378\u8F7D" }) : null
|
|
444
|
+
] })
|
|
411
445
|
] }, bundle.name);
|
|
412
446
|
}) });
|
|
413
447
|
}
|
|
@@ -463,6 +497,7 @@ function Panel() {
|
|
|
463
497
|
const [items, setItems] = (0, import_react.useState)(cached?.items ?? []);
|
|
464
498
|
const [total, setTotal] = (0, import_react.useState)(cached?.total ?? 0);
|
|
465
499
|
const [scope, setScope] = (0, import_react.useState)(cached?.scope ?? "public");
|
|
500
|
+
const [localFilter, setLocalFilter] = (0, import_react.useState)("all");
|
|
466
501
|
const [category, setCategory] = (0, import_react.useState)(cached?.category ?? "");
|
|
467
502
|
const [query, setQuery] = (0, import_react.useState)(cached?.query ?? "");
|
|
468
503
|
const [draft, setDraft] = (0, import_react.useState)(cached?.draft ?? "");
|
|
@@ -782,6 +817,27 @@ function Panel() {
|
|
|
782
817
|
}
|
|
783
818
|
});
|
|
784
819
|
}
|
|
820
|
+
async function toggleBundle(packageName, enabled) {
|
|
821
|
+
setError("");
|
|
822
|
+
try {
|
|
823
|
+
await api("/bundle-enabled", { method: "POST", body: { name: packageName, enabled } });
|
|
824
|
+
setNotice(`${enabled ? "\u5DF2\u542F\u7528" : "\u5DF2\u505C\u7528"} ${packageName}`);
|
|
825
|
+
await load(scope, category, query);
|
|
826
|
+
} catch (err) {
|
|
827
|
+
setError(err.message);
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
async function installDshBundle(packageName) {
|
|
831
|
+
setError("");
|
|
832
|
+
setNotice(`\u6B63\u5728\u5B89\u88C5 ${packageName}\u2026`);
|
|
833
|
+
try {
|
|
834
|
+
await api("/bundle-install", { method: "POST", body: { name: packageName } });
|
|
835
|
+
setNotice(`\u5DF2\u5B89\u88C5 ${packageName}`);
|
|
836
|
+
await load(scope, category, query);
|
|
837
|
+
} catch (err) {
|
|
838
|
+
setError(err.message);
|
|
839
|
+
}
|
|
840
|
+
}
|
|
785
841
|
async function install(packageName, version) {
|
|
786
842
|
setNotice(`\u6B63\u5728\u5B89\u88C5 ${packageName}${version ? `@${version}` : ""}\u2026`);
|
|
787
843
|
setError("");
|
|
@@ -1244,11 +1300,11 @@ function Panel() {
|
|
|
1244
1300
|
"button",
|
|
1245
1301
|
{
|
|
1246
1302
|
className: `pcx-tab ${scope === "installed" ? "pcx-tab-active" : ""}`,
|
|
1247
|
-
title: "\u626B\u63CF\u672C\u673A DSH \
|
|
1303
|
+
title: "\u626B\u63CF\u672C\u673A DSH \u7684\u63D2\u4EF6\uFF1A\u5185\u7F6E\u3001\u5B9E\u9A8C\u6027\u3001\u53EF\u9009\u4E0E\u5DF2\u5B89\u88C5\u7684\u7B2C\u4E09\u65B9\u63D2\u4EF6",
|
|
1248
1304
|
onClick: () => applyFilters({ scope: "installed" }),
|
|
1249
1305
|
children: [
|
|
1250
|
-
"\
|
|
1251
|
-
state?.
|
|
1306
|
+
"\u672C\u673A",
|
|
1307
|
+
state?.bundles?.length ? ` \xB7 ${state.bundles.length}` : ""
|
|
1252
1308
|
]
|
|
1253
1309
|
}
|
|
1254
1310
|
)
|
|
@@ -1276,7 +1332,46 @@ function Panel() {
|
|
|
1276
1332
|
}
|
|
1277
1333
|
)
|
|
1278
1334
|
] }),
|
|
1279
|
-
scope === "installed" ?
|
|
1335
|
+
scope === "installed" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "pcx-chips", children: (() => {
|
|
1336
|
+
const bundles = state?.bundles ?? [];
|
|
1337
|
+
const counts = {
|
|
1338
|
+
all: bundles.length,
|
|
1339
|
+
third: 0,
|
|
1340
|
+
builtin: 0,
|
|
1341
|
+
experimental: 0,
|
|
1342
|
+
optional: 0,
|
|
1343
|
+
offered: 0,
|
|
1344
|
+
disabled: 0
|
|
1345
|
+
};
|
|
1346
|
+
for (const bundle of bundles) {
|
|
1347
|
+
counts[localCategory(bundle)] += 1;
|
|
1348
|
+
if (!bundle.enabled) counts.disabled += 1;
|
|
1349
|
+
}
|
|
1350
|
+
const chips = [
|
|
1351
|
+
["all", "\u5168\u90E8"],
|
|
1352
|
+
["third", "\u7B2C\u4E09\u65B9"],
|
|
1353
|
+
["builtin", "\u5185\u7F6E"],
|
|
1354
|
+
["experimental", "\u5B9E\u9A8C\u6027"],
|
|
1355
|
+
["optional", "\u53EF\u9009"],
|
|
1356
|
+
["offered", "\u53EF\u5B89\u88C5"],
|
|
1357
|
+
["disabled", "\u5DF2\u505C\u7528"]
|
|
1358
|
+
];
|
|
1359
|
+
return chips.map(
|
|
1360
|
+
([key, label]) => counts[key] ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
1361
|
+
"button",
|
|
1362
|
+
{
|
|
1363
|
+
className: `pcx-chip ${localFilter === key ? "pcx-chip-active" : ""}`,
|
|
1364
|
+
onClick: () => setLocalFilter(key),
|
|
1365
|
+
children: [
|
|
1366
|
+
label,
|
|
1367
|
+
" \xB7 ",
|
|
1368
|
+
counts[key]
|
|
1369
|
+
]
|
|
1370
|
+
},
|
|
1371
|
+
key
|
|
1372
|
+
) : null
|
|
1373
|
+
);
|
|
1374
|
+
})() }) : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "pcx-chips", children: [
|
|
1280
1375
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { className: `pcx-chip ${!category ? "pcx-chip-active" : ""}`, onClick: () => applyFilters({ category: "" }), children: "\u5168\u90E8" }),
|
|
1281
1376
|
CATEGORIES.map((item) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1282
1377
|
"button",
|
|
@@ -1291,14 +1386,17 @@ function Panel() {
|
|
|
1291
1386
|
scope === "installed" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1292
1387
|
InstalledList,
|
|
1293
1388
|
{
|
|
1294
|
-
bundles: state?.installed ?? [],
|
|
1389
|
+
bundles: state?.bundles ?? state?.installed ?? [],
|
|
1295
1390
|
centerItems: items,
|
|
1296
1391
|
query,
|
|
1392
|
+
filter: localFilter,
|
|
1297
1393
|
onOpen: (name) => {
|
|
1298
1394
|
if (items.some((plugin) => plugin.packageName === name)) void openDetail(name);
|
|
1299
1395
|
else void openLocalDetail(name);
|
|
1300
1396
|
},
|
|
1301
|
-
onUninstall: uninstallLocal
|
|
1397
|
+
onUninstall: uninstallLocal,
|
|
1398
|
+
onToggle: (name, enabled) => void toggleBundle(name, enabled),
|
|
1399
|
+
onInstall: (name) => void installDshBundle(name)
|
|
1302
1400
|
}
|
|
1303
1401
|
) : loading && items.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "pcx-empty", children: "\u6B63\u5728\u52A0\u8F7D\u2026" }) : items.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "pcx-empty", children: [
|
|
1304
1402
|
scope === "mine" ? "\u4F60\u8FD8\u6CA1\u6709\u4E0A\u4F20\u8FC7\u63D2\u4EF6" : "\u6CA1\u6709\u627E\u5230\u63D2\u4EF6",
|
package/lib/index.js
CHANGED
|
@@ -384,10 +384,11 @@ export function apply(ctx) {
|
|
|
384
384
|
source: null,
|
|
385
385
|
}
|
|
386
386
|
const manager = ctx.get('pluginManager')
|
|
387
|
+
let bundles = []
|
|
387
388
|
if (manager) {
|
|
388
389
|
try {
|
|
389
|
-
const
|
|
390
|
-
installed =
|
|
390
|
+
const list = await manager.listBundles()
|
|
391
|
+
installed = list
|
|
391
392
|
.filter((bundle) => bundle.installed)
|
|
392
393
|
.map((bundle) => ({
|
|
393
394
|
name: bundle.name,
|
|
@@ -399,7 +400,24 @@ export function apply(ctx) {
|
|
|
399
400
|
source: bundle.source ?? null,
|
|
400
401
|
error: bundle.error?.code ?? null,
|
|
401
402
|
}))
|
|
402
|
-
|
|
403
|
+
// DSH 内置 / 实验性 / 可选 bundle 不一定在 profile 依赖里(availability: installation),
|
|
404
|
+
// 单独给一份完整清单,供「本机」视图展示和启用。
|
|
405
|
+
bundles = list.map((bundle) => ({
|
|
406
|
+
name: bundle.name,
|
|
407
|
+
version: bundle.version ?? null,
|
|
408
|
+
enabled: bundle.enabled,
|
|
409
|
+
installed: Boolean(bundle.installed),
|
|
410
|
+
availability: bundle.availability ?? null,
|
|
411
|
+
official: Boolean(bundle.official),
|
|
412
|
+
optional: Boolean(bundle.optional),
|
|
413
|
+
removable: Boolean(bundle.removable),
|
|
414
|
+
source: bundle.source ?? null,
|
|
415
|
+
error: bundle.error?.code ?? null,
|
|
416
|
+
description: bundle.description ?? null,
|
|
417
|
+
listedByDefault: bundle.listedByDefault !== false,
|
|
418
|
+
installTarget: bundle.installTarget ?? null,
|
|
419
|
+
}))
|
|
420
|
+
const own = list.find((bundle) => bundle.name === SELF_PACKAGE)
|
|
403
421
|
if (own) {
|
|
404
422
|
self = {
|
|
405
423
|
name: own.name,
|
|
@@ -423,12 +441,63 @@ export function apply(ctx) {
|
|
|
423
441
|
hostVersion: HOST_VERSION,
|
|
424
442
|
user,
|
|
425
443
|
installed,
|
|
444
|
+
bundles,
|
|
426
445
|
self,
|
|
427
446
|
selfUpdate: readSelfUpdateRecord(),
|
|
428
447
|
selfUpdateSupported: selfUpdateCapability(manager).supported,
|
|
429
448
|
})
|
|
430
449
|
}
|
|
431
450
|
|
|
451
|
+
// 启用/停用本机 bundle(含 DSH 内置、实验性、可选插件)。
|
|
452
|
+
if (req.method === 'POST' && path === '/bundle-enabled') {
|
|
453
|
+
const body = await readJson(req)
|
|
454
|
+
const name = String(body.name ?? '')
|
|
455
|
+
if (!name) return send(res, 400, { error: '缺少 name 参数' })
|
|
456
|
+
const manager = ctx.get('pluginManager')
|
|
457
|
+
if (!manager) return send(res, 503, { error: 'DSH 插件管理器不可用' })
|
|
458
|
+
if (typeof manager.setBundleEnabled !== 'function') {
|
|
459
|
+
return send(res, 409, { error: '当前 DSH 版本不支持启用/停用 bundle' })
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
const result = await manager.setBundleEnabled(name, Boolean(body.enabled))
|
|
463
|
+
if (result?.error) {
|
|
464
|
+
const detail =
|
|
465
|
+
typeof result.error === 'string' ? result.error : (result.error.message ?? result.error.code)
|
|
466
|
+
return send(res, 400, { error: detail ?? '操作失败', code: result.error.code ?? null })
|
|
467
|
+
}
|
|
468
|
+
logInstall(`bundle-enabled name=${name} enabled=${Boolean(body.enabled)}`)
|
|
469
|
+
return send(res, 200, {
|
|
470
|
+
ok: true,
|
|
471
|
+
name,
|
|
472
|
+
enabled: Boolean(body.enabled),
|
|
473
|
+
application: result?.application ?? null,
|
|
474
|
+
})
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
// 安装 DSH 自带的可选 / 实验性 bundle(listBundles 里带 installTarget 的条目)。
|
|
478
|
+
if (req.method === 'POST' && path === '/bundle-install') {
|
|
479
|
+
const body = await readJson(req)
|
|
480
|
+
const name = String(body.name ?? '')
|
|
481
|
+
if (!name) return send(res, 400, { error: '缺少 name 参数' })
|
|
482
|
+
const manager = ctx.get('pluginManager')
|
|
483
|
+
if (!manager) return send(res, 503, { error: 'DSH 插件管理器不可用' })
|
|
484
|
+
|
|
485
|
+
const list = await manager.listBundles()
|
|
486
|
+
const bundle = list.find((item) => item.name === name)
|
|
487
|
+
if (!bundle) return send(res, 404, { error: `没有找到 ${name}` })
|
|
488
|
+
const spec = bundle.installTarget?.spec
|
|
489
|
+
if (!spec) return send(res, 400, { error: '该插件没有可用的安装来源(不是 DSH 自带的可选插件)' })
|
|
490
|
+
|
|
491
|
+
const result = await manager.installBundle(spec, { enabled: true })
|
|
492
|
+
if (result?.error) {
|
|
493
|
+
const detail =
|
|
494
|
+
typeof result.error === 'string' ? result.error : (result.error.message ?? result.error.code)
|
|
495
|
+
return send(res, 400, { error: detail ?? '安装失败', code: result.error.code ?? null })
|
|
496
|
+
}
|
|
497
|
+
logInstall(`bundle-install name=${name} spec=${spec}`)
|
|
498
|
+
return send(res, 200, { ok: true, name, version: result?.version ?? bundle.installTarget?.version ?? null })
|
|
499
|
+
}
|
|
500
|
+
|
|
432
501
|
if (req.method === 'GET' && path === '/self/update-check') {
|
|
433
502
|
const manager = ctx.get('pluginManager')
|
|
434
503
|
if (!manager) return send(res, 503, { error: 'DSH 插件管理器不可用(当前不是 profile 模式)' })
|