@ququ-jiaxk/dsh-plugin-center 0.1.40 → 0.1.42
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 +175 -5
- package/lib/index.js +45 -2
- package/package.json +1 -1
package/lib/client.js
CHANGED
|
@@ -30,7 +30,7 @@ __export(client_exports, {
|
|
|
30
30
|
module.exports = __toCommonJS(client_exports);
|
|
31
31
|
var import_react = require("react");
|
|
32
32
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
33
|
-
var PLUGIN_VERSION = true ? "0.1.
|
|
33
|
+
var PLUGIN_VERSION = true ? "0.1.42" : "0.0.0";
|
|
34
34
|
var PANEL_ID = "plugin-center";
|
|
35
35
|
var inject = ["slots", "remote", "remote.pluginManager"];
|
|
36
36
|
var hostCtx = null;
|
|
@@ -205,6 +205,101 @@ function InstallProgressCard({ progress }) {
|
|
|
205
205
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "pcx-progress-package", children: progress.packageName })
|
|
206
206
|
] });
|
|
207
207
|
}
|
|
208
|
+
function iconLetter(name) {
|
|
209
|
+
const clean = name.startsWith("@") ? name.split("/").pop() ?? name : name;
|
|
210
|
+
return clean.slice(0, 1).toUpperCase();
|
|
211
|
+
}
|
|
212
|
+
function InstalledList({
|
|
213
|
+
bundles,
|
|
214
|
+
centerItems,
|
|
215
|
+
query,
|
|
216
|
+
onOpen,
|
|
217
|
+
onUninstall
|
|
218
|
+
}) {
|
|
219
|
+
const center = new Map(centerItems.map((item) => [item.packageName, item]));
|
|
220
|
+
const keyword = query.trim().toLowerCase();
|
|
221
|
+
const list = bundles.filter((bundle) => {
|
|
222
|
+
if (!keyword) return true;
|
|
223
|
+
const display = center.get(bundle.name)?.displayName ?? "";
|
|
224
|
+
return bundle.name.toLowerCase().includes(keyword) || display.toLowerCase().includes(keyword);
|
|
225
|
+
});
|
|
226
|
+
if (list.length === 0) {
|
|
227
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "pcx-empty", children: [
|
|
228
|
+
keyword ? "\u6CA1\u6709\u5339\u914D\u7684\u672C\u673A\u63D2\u4EF6" : "\u672C\u673A\u8FD8\u6CA1\u6709\u5B89\u88C5\u63D2\u4EF6",
|
|
229
|
+
/* @__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" })
|
|
230
|
+
] });
|
|
231
|
+
}
|
|
232
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "pcx-grid", children: list.map((bundle) => {
|
|
233
|
+
const item = center.get(bundle.name);
|
|
234
|
+
const localInstall = !bundle.source || /(?:^|[^a-z0-9])(?:file|link):/iu.test(bundle.source);
|
|
235
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("article", { className: "pcx-card", children: [
|
|
236
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "pcx-card-main", onClick: () => onOpen(bundle.name), children: [
|
|
237
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "pcx-card-top", children: [
|
|
238
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "pcx-icon", children: iconLetter(item?.displayName ?? bundle.name) }),
|
|
239
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "pcx-card-titles", children: [
|
|
240
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "pcx-row", children: [
|
|
241
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "pcx-name", children: item?.displayName ?? bundle.name }),
|
|
242
|
+
/* @__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" }),
|
|
243
|
+
bundle.error ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "pcx-badge pcx-badge-danger", children: "\u8BFB\u53D6\u5F02\u5E38" }) : null,
|
|
244
|
+
item ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "pcx-badge", children: "\u672A\u4E0A\u67B6" })
|
|
245
|
+
] }),
|
|
246
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "pcx-pkg", children: bundle.name })
|
|
247
|
+
] })
|
|
248
|
+
] }),
|
|
249
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "pcx-foot", children: [
|
|
250
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "pcx-foot-owner", children: bundle.official ? "\u968F DSH \u5B89\u88C5" : localInstall ? "\u672C\u5730\u5305\u5B89\u88C5" : "registry \u5B89\u88C5" }),
|
|
251
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "pcx-foot-meta", children: bundle.version ? `v${bundle.version}` : "\u7248\u672C\u672A\u77E5" })
|
|
252
|
+
] })
|
|
253
|
+
] }),
|
|
254
|
+
bundle.removable ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "pcx-card-actions", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { className: "pcx-btn pcx-btn-sm pcx-btn-danger", onClick: () => onUninstall(bundle.name), children: "\u5378\u8F7D" }) }) : null
|
|
255
|
+
] }, bundle.name);
|
|
256
|
+
}) });
|
|
257
|
+
}
|
|
258
|
+
function LocalDetailView({
|
|
259
|
+
data,
|
|
260
|
+
onBack,
|
|
261
|
+
onOpenCenter,
|
|
262
|
+
onUninstall
|
|
263
|
+
}) {
|
|
264
|
+
const bundle = data.bundle;
|
|
265
|
+
const markdown = data.detail && data.detail.status === "found" ? data.detail.markdown : "";
|
|
266
|
+
const origin = data.detail && data.detail.status === "found" ? data.detail.path : "";
|
|
267
|
+
const localInstall = !bundle.source || /(?:^|[^a-z0-9])(?:file|link):/iu.test(bundle.source);
|
|
268
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "pcx-root", children: [
|
|
269
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("a", { className: "pcx-back", onClick: onBack, children: "\u2190 \u8FD4\u56DE\u5217\u8868" }),
|
|
270
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "pcx-detail-head", children: [
|
|
271
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "pcx-icon pcx-icon-lg", children: iconLetter(bundle.displayName ?? bundle.name) }),
|
|
272
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "pcx-detail-titles", children: [
|
|
273
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "pcx-row", children: [
|
|
274
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h1", { className: "pcx-title", children: bundle.displayName ?? bundle.name }),
|
|
275
|
+
/* @__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" }),
|
|
276
|
+
bundle.error ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "pcx-badge pcx-badge-danger", children: "\u8BFB\u53D6\u5F02\u5E38" }) : null
|
|
277
|
+
] }),
|
|
278
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "pcx-pkg", children: bundle.name }),
|
|
279
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "pcx-desc pcx-desc-block", children: bundle.summary || "\u672C\u673A\u5B89\u88C5\u7684\u63D2\u4EF6" })
|
|
280
|
+
] })
|
|
281
|
+
] }),
|
|
282
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "pcx-actions pcx-actions-left", children: [
|
|
283
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: "pcx-sub", children: [
|
|
284
|
+
bundle.version ? `v${bundle.version}` : "\u7248\u672C\u672A\u77E5",
|
|
285
|
+
" \xB7",
|
|
286
|
+
" ",
|
|
287
|
+
bundle.official ? "\u968F DSH \u5B89\u88C5" : localInstall ? "\u672C\u5730\u5305\u5B89\u88C5" : "registry \u5B89\u88C5",
|
|
288
|
+
bundle.source ? ` \xB7 ${bundle.source}` : ""
|
|
289
|
+
] }),
|
|
290
|
+
onOpenCenter ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { className: "pcx-btn", onClick: onOpenCenter, children: "\u5728\u63D2\u4EF6\u4E2D\u5FC3\u67E5\u770B" }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "pcx-badge", children: "\u672A\u5728\u63D2\u4EF6\u4E2D\u5FC3\u4E0A\u67B6" }),
|
|
291
|
+
bundle.removable ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { className: "pcx-btn pcx-btn-danger", onClick: onUninstall, children: "\u5378\u8F7D" }) : null
|
|
292
|
+
] }),
|
|
293
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("section", { className: "pcx-section", children: [
|
|
294
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h2", { className: "pcx-h2", children: "\u63D2\u4EF6\u8BE6\u60C5" }),
|
|
295
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "pcx-text", children: markdown || bundle.description || "\u8FD9\u4E2A\u63D2\u4EF6\u6CA1\u6709\u63D0\u4F9B README \u6216 locale \u8BE6\u60C5\u3002" })
|
|
296
|
+
] }),
|
|
297
|
+
origin ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("section", { className: "pcx-section", children: [
|
|
298
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h2", { className: "pcx-h2", children: "\u8BE6\u60C5\u6765\u6E90" }),
|
|
299
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "pcx-text", children: origin })
|
|
300
|
+
] }) : null
|
|
301
|
+
] });
|
|
302
|
+
}
|
|
208
303
|
function Panel() {
|
|
209
304
|
const cached = panelSnapshot;
|
|
210
305
|
const rootRef = (0, import_react.useRef)(null);
|
|
@@ -228,6 +323,7 @@ function Panel() {
|
|
|
228
323
|
const pushTrace = (line) => setTrace((current) => [...current.slice(-7), `${(/* @__PURE__ */ new Date()).toLocaleTimeString()} ${line}`]);
|
|
229
324
|
const [view, setView] = (0, import_react.useState)(cached?.view ?? "list");
|
|
230
325
|
const [detail, setDetail] = (0, import_react.useState)(cached?.detail ?? null);
|
|
326
|
+
const [localDetail, setLocalDetail] = (0, import_react.useState)(null);
|
|
231
327
|
const [binding, setBinding] = (0, import_react.useState)(false);
|
|
232
328
|
const [dialog, setDialog] = (0, import_react.useState)(null);
|
|
233
329
|
const [passwordOpen, setPasswordOpen] = (0, import_react.useState)(false);
|
|
@@ -260,12 +356,18 @@ function Panel() {
|
|
|
260
356
|
try {
|
|
261
357
|
const snapshot = await api("/state");
|
|
262
358
|
setState(snapshot);
|
|
263
|
-
const effectiveScope = snapshot.user || nextScope === "public" ? nextScope : "public";
|
|
359
|
+
const effectiveScope = snapshot.user || nextScope === "public" || nextScope === "installed" ? nextScope : "public";
|
|
264
360
|
const effectiveOffset = effectiveScope === nextScope ? nextOffset : 0;
|
|
265
361
|
if (effectiveScope !== nextScope) {
|
|
266
362
|
setScope("public");
|
|
267
363
|
setNotice("\u767B\u5F55\u72B6\u6001\u5DF2\u5931\u6548\uFF0C\u5DF2\u5207\u56DE\u516C\u5F00\u5217\u8868");
|
|
268
364
|
}
|
|
365
|
+
if (effectiveScope === "installed") {
|
|
366
|
+
setTotal(snapshot.installed?.length ?? 0);
|
|
367
|
+
setOffset(0);
|
|
368
|
+
setHasMore(false);
|
|
369
|
+
return;
|
|
370
|
+
}
|
|
269
371
|
const params = new URLSearchParams({
|
|
270
372
|
scope: effectiveScope,
|
|
271
373
|
limit: "24",
|
|
@@ -509,6 +611,21 @@ function Panel() {
|
|
|
509
611
|
} catch {
|
|
510
612
|
}
|
|
511
613
|
}
|
|
614
|
+
function uninstallLocal(packageName) {
|
|
615
|
+
setDialog({
|
|
616
|
+
title: `\u5378\u8F7D\u300C${packageName}\u300D\uFF1F`,
|
|
617
|
+
description: "\u53EA\u4ECE\u672C\u673A DSH \u79FB\u9664\uFF0C\u4E0D\u5F71\u54CD\u63D2\u4EF6\u4E2D\u5FC3\u91CC\u7684\u7248\u672C\u3002",
|
|
618
|
+
input: false,
|
|
619
|
+
confirmLabel: "\u5378\u8F7D",
|
|
620
|
+
danger: true,
|
|
621
|
+
action: async () => {
|
|
622
|
+
await api("/uninstall", { method: "POST", body: { packageName } });
|
|
623
|
+
setLocalDetail(null);
|
|
624
|
+
setNotice(`\u5DF2\u5378\u8F7D ${packageName}`);
|
|
625
|
+
await load(scope, category, query);
|
|
626
|
+
}
|
|
627
|
+
});
|
|
628
|
+
}
|
|
512
629
|
async function install(packageName, version) {
|
|
513
630
|
setNotice(`\u6B63\u5728\u5B89\u88C5 ${packageName}${version ? `@${version}` : ""}\u2026`);
|
|
514
631
|
setError("");
|
|
@@ -676,6 +793,14 @@ function Panel() {
|
|
|
676
793
|
setError(err.message);
|
|
677
794
|
}
|
|
678
795
|
}
|
|
796
|
+
async function openLocalDetail(packageName) {
|
|
797
|
+
setError("");
|
|
798
|
+
try {
|
|
799
|
+
setLocalDetail(await api(`/local-detail?package=${encodeURIComponent(packageName)}`));
|
|
800
|
+
} catch (err) {
|
|
801
|
+
setError(err.message);
|
|
802
|
+
}
|
|
803
|
+
}
|
|
679
804
|
async function afterUpload(packageName) {
|
|
680
805
|
setView("list");
|
|
681
806
|
await load(scope, category, query);
|
|
@@ -708,6 +833,27 @@ function Panel() {
|
|
|
708
833
|
}
|
|
709
834
|
);
|
|
710
835
|
}
|
|
836
|
+
if (localDetail) {
|
|
837
|
+
const centerItem = items.find((plugin) => plugin.packageName === localDetail.bundle.name);
|
|
838
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
839
|
+
notice ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "pcx-toast", children: notice }) : null,
|
|
840
|
+
error ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "pcx-toast pcx-toast-error", children: error }) : null,
|
|
841
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
842
|
+
LocalDetailView,
|
|
843
|
+
{
|
|
844
|
+
data: localDetail,
|
|
845
|
+
onBack: () => setLocalDetail(null),
|
|
846
|
+
onOpenCenter: centerItem ? () => {
|
|
847
|
+
const name = localDetail.bundle.name;
|
|
848
|
+
setLocalDetail(null);
|
|
849
|
+
void openDetail(name);
|
|
850
|
+
} : void 0,
|
|
851
|
+
onUninstall: () => uninstallLocal(localDetail.bundle.name)
|
|
852
|
+
}
|
|
853
|
+
),
|
|
854
|
+
dialog ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PromptDialog, { dialog, onClose: () => setDialog(null) }) : null
|
|
855
|
+
] });
|
|
856
|
+
}
|
|
711
857
|
if (detail) {
|
|
712
858
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
713
859
|
notice ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "pcx-toast", children: notice }) : null,
|
|
@@ -937,7 +1083,19 @@ function Panel() {
|
|
|
937
1083
|
onClick: () => applyFilters({ scope: "all" }),
|
|
938
1084
|
children: "\u5168\u90E8"
|
|
939
1085
|
}
|
|
940
|
-
) : null
|
|
1086
|
+
) : null,
|
|
1087
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
1088
|
+
"button",
|
|
1089
|
+
{
|
|
1090
|
+
className: `pcx-tab ${scope === "installed" ? "pcx-tab-active" : ""}`,
|
|
1091
|
+
title: "\u626B\u63CF\u672C\u673A DSH \u5DF2\u5B89\u88C5\u7684\u63D2\u4EF6\uFF08\u542B\u672A\u5728\u4E2D\u5FC3\u4E0A\u67B6\u7684\uFF09",
|
|
1092
|
+
onClick: () => applyFilters({ scope: "installed" }),
|
|
1093
|
+
children: [
|
|
1094
|
+
"\u5DF2\u88C5",
|
|
1095
|
+
state?.installed?.length ? ` \xB7 ${state.installed.length}` : ""
|
|
1096
|
+
]
|
|
1097
|
+
}
|
|
1098
|
+
)
|
|
941
1099
|
] }),
|
|
942
1100
|
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
943
1101
|
"form",
|
|
@@ -962,7 +1120,7 @@ function Panel() {
|
|
|
962
1120
|
}
|
|
963
1121
|
)
|
|
964
1122
|
] }),
|
|
965
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "pcx-chips", children: [
|
|
1123
|
+
scope === "installed" ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "pcx-chips", children: [
|
|
966
1124
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { className: `pcx-chip ${!category ? "pcx-chip-active" : ""}`, onClick: () => applyFilters({ category: "" }), children: "\u5168\u90E8" }),
|
|
967
1125
|
CATEGORIES.map((item) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
968
1126
|
"button",
|
|
@@ -974,7 +1132,19 @@ function Panel() {
|
|
|
974
1132
|
item.id
|
|
975
1133
|
))
|
|
976
1134
|
] }),
|
|
977
|
-
|
|
1135
|
+
scope === "installed" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1136
|
+
InstalledList,
|
|
1137
|
+
{
|
|
1138
|
+
bundles: state?.installed ?? [],
|
|
1139
|
+
centerItems: items,
|
|
1140
|
+
query,
|
|
1141
|
+
onOpen: (name) => {
|
|
1142
|
+
if (items.some((plugin) => plugin.packageName === name)) void openDetail(name);
|
|
1143
|
+
else void openLocalDetail(name);
|
|
1144
|
+
},
|
|
1145
|
+
onUninstall: uninstallLocal
|
|
1146
|
+
}
|
|
1147
|
+
) : 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: [
|
|
978
1148
|
scope === "mine" ? "\u4F60\u8FD8\u6CA1\u6709\u4E0A\u4F20\u8FC7\u63D2\u4EF6" : "\u6CA1\u6709\u627E\u5230\u63D2\u4EF6",
|
|
979
1149
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "pcx-empty-hint", children: scope === "mine" ? "\u70B9\u53F3\u4E0A\u89D2\u300C\u4E0A\u4F20\u63D2\u4EF6\u300D\u5F00\u59CB" : "\u6362\u4E2A\u5173\u952E\u8BCD\u6216\u5206\u7C7B\u8BD5\u8BD5" })
|
|
980
1150
|
] }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "pcx-grid", children: items.map((plugin) => {
|
package/lib/index.js
CHANGED
|
@@ -388,11 +388,16 @@ export function apply(ctx) {
|
|
|
388
388
|
try {
|
|
389
389
|
const bundles = await manager.listBundles()
|
|
390
390
|
installed = bundles
|
|
391
|
-
.filter((bundle) => bundle.installed
|
|
391
|
+
.filter((bundle) => bundle.installed)
|
|
392
392
|
.map((bundle) => ({
|
|
393
393
|
name: bundle.name,
|
|
394
|
-
version: bundle.version,
|
|
394
|
+
version: bundle.version ?? null,
|
|
395
395
|
enabled: bundle.enabled,
|
|
396
|
+
official: Boolean(bundle.official),
|
|
397
|
+
availability: bundle.availability ?? null,
|
|
398
|
+
removable: Boolean(bundle.removable),
|
|
399
|
+
source: bundle.source ?? null,
|
|
400
|
+
error: bundle.error?.code ?? null,
|
|
396
401
|
}))
|
|
397
402
|
const own = bundles.find((bundle) => bundle.name === SELF_PACKAGE)
|
|
398
403
|
if (own) {
|
|
@@ -914,6 +919,44 @@ export function apply(ctx) {
|
|
|
914
919
|
return send(res, 200, detail)
|
|
915
920
|
}
|
|
916
921
|
|
|
922
|
+
// 本机已装插件的详情:即使没在中心上架,也能读到 README / locale 详情。
|
|
923
|
+
if (req.method === 'GET' && path === '/local-detail') {
|
|
924
|
+
const packageName = url.searchParams.get('package') ?? ''
|
|
925
|
+
if (!packageName) return send(res, 400, { error: '缺少 package 参数' })
|
|
926
|
+
const manager = ctx.get('pluginManager')
|
|
927
|
+
if (!manager) return send(res, 503, { error: 'DSH 插件管理器不可用' })
|
|
928
|
+
|
|
929
|
+
const bundle = (await manager.listBundles()).find((item) => item.name === packageName)
|
|
930
|
+
if (!bundle) return send(res, 404, { error: `本机没有安装 ${packageName}` })
|
|
931
|
+
|
|
932
|
+
const meta = bundle.meta && typeof bundle.meta === 'object' ? bundle.meta : {}
|
|
933
|
+
let detail = null
|
|
934
|
+
try {
|
|
935
|
+
if (typeof manager.readBundleDetail === 'function') {
|
|
936
|
+
detail = await manager.readBundleDetail(packageName, 'zh')
|
|
937
|
+
}
|
|
938
|
+
} catch {
|
|
939
|
+
detail = null
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
return send(res, 200, {
|
|
943
|
+
bundle: {
|
|
944
|
+
name: bundle.name,
|
|
945
|
+
displayName: typeof meta.name === 'string' ? meta.name : bundle.name,
|
|
946
|
+
summary: typeof meta.summary === 'string' ? meta.summary : (bundle.description ?? ''),
|
|
947
|
+
description: bundle.description ?? null,
|
|
948
|
+
version: bundle.version ?? null,
|
|
949
|
+
enabled: bundle.enabled,
|
|
950
|
+
official: Boolean(bundle.official),
|
|
951
|
+
availability: bundle.availability ?? null,
|
|
952
|
+
removable: Boolean(bundle.removable),
|
|
953
|
+
source: bundle.source ?? null,
|
|
954
|
+
error: bundle.error?.code ?? null,
|
|
955
|
+
},
|
|
956
|
+
detail,
|
|
957
|
+
})
|
|
958
|
+
}
|
|
959
|
+
|
|
917
960
|
if (req.method === 'GET' && path === '/install-progress') {
|
|
918
961
|
const packageName = url.searchParams.get('package') ?? ''
|
|
919
962
|
if (!packageName) return send(res, 400, { error: '缺少 package 参数' })
|