@ququ-jiaxk/dsh-plugin-center 0.1.34 → 0.1.36
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 +137 -38
- package/lib/index.js +42 -7
- 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.36" : "0.0.0";
|
|
34
34
|
var PANEL_ID = "plugin-center";
|
|
35
35
|
var inject = ["slots", "remote", "remote.pluginManager"];
|
|
36
36
|
var hostCtx = null;
|
|
@@ -49,6 +49,64 @@ var selfUpdateTarget = null;
|
|
|
49
49
|
var selfUpdatePolling = false;
|
|
50
50
|
var selfUpdateNotified = false;
|
|
51
51
|
var lastSelfCheckAt = 0;
|
|
52
|
+
var selfUpdateRetried = false;
|
|
53
|
+
var selfUpdateInfo = { latest: null, checkedAt: 0, checking: false };
|
|
54
|
+
var selfUpdateSubscribers = /* @__PURE__ */ new Set();
|
|
55
|
+
var selfUpdateRequest = null;
|
|
56
|
+
function publishSelfUpdate(patch) {
|
|
57
|
+
selfUpdateInfo = { ...selfUpdateInfo, ...patch };
|
|
58
|
+
for (const notify of selfUpdateSubscribers) notify();
|
|
59
|
+
}
|
|
60
|
+
function useSelfUpdateInfo() {
|
|
61
|
+
const [info, setInfo] = (0, import_react.useState)(selfUpdateInfo);
|
|
62
|
+
(0, import_react.useEffect)(() => {
|
|
63
|
+
const notify = () => setInfo(selfUpdateInfo);
|
|
64
|
+
selfUpdateSubscribers.add(notify);
|
|
65
|
+
return () => {
|
|
66
|
+
selfUpdateSubscribers.delete(notify);
|
|
67
|
+
};
|
|
68
|
+
}, []);
|
|
69
|
+
return info;
|
|
70
|
+
}
|
|
71
|
+
async function fetchSelfUpdateInfo() {
|
|
72
|
+
if (typeof fetch !== "function") return null;
|
|
73
|
+
if (selfUpdateRequest) return selfUpdateRequest;
|
|
74
|
+
publishSelfUpdate({ checking: true });
|
|
75
|
+
selfUpdateRequest = (async () => {
|
|
76
|
+
try {
|
|
77
|
+
const response = await fetch("/plugin-center/api/self/update-check", {
|
|
78
|
+
signal: typeof AbortSignal !== "undefined" && AbortSignal.timeout ? AbortSignal.timeout(15e3) : void 0
|
|
79
|
+
});
|
|
80
|
+
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
|
81
|
+
const data = await response.json();
|
|
82
|
+
publishSelfUpdate({
|
|
83
|
+
latest: data?.status === "available" && data.latest ? String(data.latest) : null,
|
|
84
|
+
checkedAt: Date.now(),
|
|
85
|
+
checking: false
|
|
86
|
+
});
|
|
87
|
+
return data;
|
|
88
|
+
} catch {
|
|
89
|
+
publishSelfUpdate({ checkedAt: Date.now(), checking: false });
|
|
90
|
+
return null;
|
|
91
|
+
} finally {
|
|
92
|
+
selfUpdateRequest = null;
|
|
93
|
+
}
|
|
94
|
+
})();
|
|
95
|
+
return selfUpdateRequest;
|
|
96
|
+
}
|
|
97
|
+
function startSelfUpdateWatcher() {
|
|
98
|
+
if (typeof window === "undefined" || typeof document === "undefined") return;
|
|
99
|
+
if (typeof fetch !== "function" || typeof setTimeout !== "function") return;
|
|
100
|
+
setTimeout(() => void fetchSelfUpdateInfo(), 2500);
|
|
101
|
+
if (typeof setInterval === "function") {
|
|
102
|
+
setInterval(() => void fetchSelfUpdateInfo(), 6 * 60 * 60 * 1e3);
|
|
103
|
+
}
|
|
104
|
+
document.addEventListener("visibilitychange", () => {
|
|
105
|
+
if (document.visibilityState !== "visible") return;
|
|
106
|
+
if (Date.now() - selfUpdateInfo.checkedAt < 30 * 60 * 1e3) return;
|
|
107
|
+
void fetchSelfUpdateInfo();
|
|
108
|
+
});
|
|
109
|
+
}
|
|
52
110
|
var authDraft = null;
|
|
53
111
|
var uploadDraft = null;
|
|
54
112
|
async function api(path, init = {}) {
|
|
@@ -94,13 +152,18 @@ function apply(ctx) {
|
|
|
94
152
|
ctx.slots.inject("main", function* () {
|
|
95
153
|
yield ctx.slots.register({ name: "main", key: PANEL_ID }, Panel);
|
|
96
154
|
});
|
|
155
|
+
startSelfUpdateWatcher();
|
|
97
156
|
}
|
|
98
|
-
function PanelIcon() {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
/* @__PURE__ */ (0, import_jsx_runtime.
|
|
102
|
-
|
|
103
|
-
|
|
157
|
+
function PanelIcon({ size = 16 }) {
|
|
158
|
+
const { latest } = useSelfUpdateInfo();
|
|
159
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: "pcx-sidebar-icon", children: [
|
|
160
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("svg", { width: size, height: size, viewBox: "0 0 16 16", fill: "none", "aria-hidden": "true", children: [
|
|
161
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("rect", { x: "1.75", y: "1.75", width: "5", height: "5", rx: "1.2", stroke: "currentColor", strokeWidth: "1.3" }),
|
|
162
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("rect", { x: "9.25", y: "1.75", width: "5", height: "5", rx: "1.2", stroke: "currentColor", strokeWidth: "1.3" }),
|
|
163
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("rect", { x: "1.75", y: "9.25", width: "5", height: "5", rx: "1.2", stroke: "currentColor", strokeWidth: "1.3" }),
|
|
164
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M11.75 9.5v4.25M9.63 11.63h4.25", stroke: "currentColor", strokeWidth: "1.3", strokeLinecap: "round" })
|
|
165
|
+
] }),
|
|
166
|
+
latest ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "pcx-sidebar-dot", "aria-hidden": "true" }) : null
|
|
104
167
|
] });
|
|
105
168
|
}
|
|
106
169
|
function isNewer(latest, installed) {
|
|
@@ -168,9 +231,22 @@ function Panel() {
|
|
|
168
231
|
const [dialog, setDialog] = (0, import_react.useState)(null);
|
|
169
232
|
const [passwordOpen, setPasswordOpen] = (0, import_react.useState)(false);
|
|
170
233
|
const [authView, setAuthView] = (0, import_react.useState)("login");
|
|
171
|
-
const [selfUpdate, setSelfUpdate] = (0, import_react.useState)(
|
|
172
|
-
selfUpdateTarget
|
|
173
|
-
|
|
234
|
+
const [selfUpdate, setSelfUpdate] = (0, import_react.useState)(() => {
|
|
235
|
+
if (selfUpdateTarget) return { phase: "running", to: selfUpdateTarget };
|
|
236
|
+
if (selfUpdateInfo.latest) return { phase: "available", to: selfUpdateInfo.latest };
|
|
237
|
+
return { phase: "idle" };
|
|
238
|
+
});
|
|
239
|
+
const updateInfo = useSelfUpdateInfo();
|
|
240
|
+
(0, import_react.useEffect)(() => {
|
|
241
|
+
if (selfUpdateTarget) return;
|
|
242
|
+
if (updateInfo.latest) {
|
|
243
|
+
setSelfUpdate(
|
|
244
|
+
(current) => current.phase === "idle" || current.phase === "checking" ? { phase: "available", to: updateInfo.latest } : current
|
|
245
|
+
);
|
|
246
|
+
} else {
|
|
247
|
+
setSelfUpdate((current) => current.phase === "available" ? { phase: "idle" } : current);
|
|
248
|
+
}
|
|
249
|
+
}, [updateInfo.latest]);
|
|
174
250
|
(0, import_react.useEffect)(() => {
|
|
175
251
|
if (!notice) return;
|
|
176
252
|
const timer = setTimeout(() => setNotice(""), 4e3);
|
|
@@ -215,37 +291,44 @@ function Panel() {
|
|
|
215
291
|
}, [cached, load]);
|
|
216
292
|
async function checkSelfUpdate(manual) {
|
|
217
293
|
if (manual) setSelfUpdate({ phase: "checking" });
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
}
|
|
294
|
+
lastSelfCheckAt = Date.now();
|
|
295
|
+
const result = await fetchSelfUpdateInfo();
|
|
296
|
+
if (!result) {
|
|
297
|
+
setSelfUpdate({ phase: "idle" });
|
|
298
|
+
if (manual) setError("\u68C0\u67E5\u66F4\u65B0\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5");
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
if (result.status === "available" && result.latest) {
|
|
302
|
+
setSelfUpdate({ phase: "available", to: result.latest });
|
|
303
|
+
if (manual) setNotice(`\u53D1\u73B0\u65B0\u7248\u672C v${result.latest}`);
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
if (result.status === "not-updatable") {
|
|
307
|
+
setSelfUpdate({ phase: "idle" });
|
|
308
|
+
if (result.reason === "unreadable" && !manual && !selfUpdateRetried) {
|
|
309
|
+
selfUpdateRetried = true;
|
|
310
|
+
setTimeout(() => void checkSelfUpdate(false), 5e3);
|
|
236
311
|
return;
|
|
237
312
|
}
|
|
238
|
-
if (
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
313
|
+
if (manual) {
|
|
314
|
+
setDialog({
|
|
315
|
+
title: result.reason === "local" ? "\u5F53\u524D\u5B89\u88C5\u65B9\u5F0F\u4E0D\u652F\u6301\u81EA\u66F4\u65B0" : "\u6682\u65F6\u65E0\u6CD5\u81EA\u66F4\u65B0",
|
|
316
|
+
description: String(result.hint ?? ""),
|
|
317
|
+
input: false,
|
|
318
|
+
confirmLabel: "\u77E5\u9053\u4E86",
|
|
319
|
+
action: async () => void 0
|
|
320
|
+
});
|
|
242
321
|
}
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
selfUpdateRetried = false;
|
|
325
|
+
if (result.status === "unavailable") {
|
|
243
326
|
setSelfUpdate({ phase: "idle" });
|
|
244
|
-
if (manual)
|
|
245
|
-
|
|
246
|
-
setSelfUpdate({ phase: "idle" });
|
|
247
|
-
if (manual) setError(err.message);
|
|
327
|
+
if (manual) setError(`\u68C0\u67E5\u66F4\u65B0\u5931\u8D25\uFF1A${result.reason || result.problem || "\u672A\u77E5\u539F\u56E0"}`);
|
|
328
|
+
return;
|
|
248
329
|
}
|
|
330
|
+
setSelfUpdate({ phase: "idle" });
|
|
331
|
+
if (manual) setNotice("\u63D2\u4EF6\u4E2D\u5FC3\u5DF2\u662F\u6700\u65B0\u7248\u672C");
|
|
249
332
|
}
|
|
250
333
|
async function pollSelfUpdate(version) {
|
|
251
334
|
if (selfUpdatePolling) return;
|
|
@@ -267,6 +350,7 @@ function Panel() {
|
|
|
267
350
|
if (next.self?.version === version || next.self?.installedVersion === version) {
|
|
268
351
|
selfUpdateTarget = null;
|
|
269
352
|
selfUpdateNotified = true;
|
|
353
|
+
publishSelfUpdate({ latest: null, checkedAt: Date.now() });
|
|
270
354
|
if (record?.application === "restart-required" || next.self?.version !== version) {
|
|
271
355
|
setSelfUpdate({ phase: "restart", to: version });
|
|
272
356
|
return;
|
|
@@ -329,8 +413,7 @@ function Panel() {
|
|
|
329
413
|
void pollSelfUpdate(selfUpdateTarget);
|
|
330
414
|
return;
|
|
331
415
|
}
|
|
332
|
-
if (Date.now() - lastSelfCheckAt <
|
|
333
|
-
lastSelfCheckAt = Date.now();
|
|
416
|
+
if (Date.now() - Math.max(lastSelfCheckAt, selfUpdateInfo.checkedAt) < 30 * 1e3) return;
|
|
334
417
|
void checkSelfUpdate(false);
|
|
335
418
|
}, [ready]);
|
|
336
419
|
(0, import_react.useEffect)(() => {
|
|
@@ -2520,6 +2603,22 @@ var CSS = `
|
|
|
2520
2603
|
}
|
|
2521
2604
|
.pcx-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
|
|
2522
2605
|
.pcx-brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
|
|
2606
|
+
.pcx-sidebar-icon {
|
|
2607
|
+
position: relative;
|
|
2608
|
+
display: inline-flex;
|
|
2609
|
+
align-items: center;
|
|
2610
|
+
justify-content: center;
|
|
2611
|
+
}
|
|
2612
|
+
.pcx-sidebar-dot {
|
|
2613
|
+
position: absolute;
|
|
2614
|
+
top: -1px;
|
|
2615
|
+
right: -2px;
|
|
2616
|
+
width: 7px;
|
|
2617
|
+
height: 7px;
|
|
2618
|
+
border-radius: 50%;
|
|
2619
|
+
background: var(--dsw-alias-state-business-primary, #1f6feb);
|
|
2620
|
+
box-shadow: 0 0 0 1.5px var(--dsw-specific-sidebar-fill, #fff);
|
|
2621
|
+
}
|
|
2523
2622
|
.pcx-logo {
|
|
2524
2623
|
width: 28px; height: 28px; border-radius: 8px; flex: none;
|
|
2525
2624
|
display: grid; place-items: center;
|
package/lib/index.js
CHANGED
|
@@ -123,11 +123,42 @@ function selfUpdateRecord(phase, extra = {}) {
|
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
125
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
126
|
+
/**
|
|
127
|
+
* DSH 拒绝升级时给出可执行的下一步。
|
|
128
|
+
* 注意:`updatable: false` 不只代表"本地包安装"——刚安装完、包还没落盘时也会是 false,
|
|
129
|
+
* 所以这里按来源和 bundle 状态区分,避免误导。
|
|
130
|
+
*/
|
|
131
|
+
function selfUpdateBlockedInfo(own) {
|
|
132
|
+
const reinstall = `dsh plugin remove ${SELF_PACKAGE} && dsh plugin add ${SELF_PACKAGE}@latest`
|
|
133
|
+
|
|
134
|
+
if (!own) {
|
|
135
|
+
return {
|
|
136
|
+
reason: 'unreadable',
|
|
137
|
+
hint: `DSH 没有列出面板自身的 bundle,通常是安装还没完成或需要重启。重启 DSH 后点标题旁的版本号重新检查;仍然不行就重装:${reinstall}。`,
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const source = own.source ?? null
|
|
142
|
+
const local = !source || /(?:^|[^a-z0-9])(?:file|link):/iu.test(source)
|
|
143
|
+
if (local) {
|
|
144
|
+
return {
|
|
145
|
+
reason: 'local',
|
|
146
|
+
hint: `当前插件中心是按本地包安装的(${source ?? 'file:'}),DSH 无法原地升级。执行一次迁移后即可自动更新:${reinstall},然后重启 DSH。`,
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (own.availability !== 'profile' || own.error) {
|
|
151
|
+
const detail = own.error?.code ? `(DSH:${own.error.code})` : ''
|
|
152
|
+
return {
|
|
153
|
+
reason: 'unreadable',
|
|
154
|
+
hint: `DSH 现在读不到已安装的面板包${detail},通常是刚安装完还没完全落盘。重启 DSH 后点标题旁的版本号重新检查;仍然不行就重装:${reinstall}。`,
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
return {
|
|
159
|
+
reason: 'unrecognized',
|
|
160
|
+
hint: `DSH 没有把当前依赖识别成可原地升级的 registry 规格(来源:${source ?? '未记录'})。重启 DSH 后再检查一次;仍然不行就重装:${reinstall}。`,
|
|
161
|
+
}
|
|
131
162
|
}
|
|
132
163
|
|
|
133
164
|
async function findSelfBundle(manager) {
|
|
@@ -373,12 +404,14 @@ export function apply(ctx) {
|
|
|
373
404
|
const own = await findSelfBundle(manager)
|
|
374
405
|
const installedVersion = own?.version ?? HOST_VERSION
|
|
375
406
|
if (!own?.updatable) {
|
|
407
|
+
const blocked = selfUpdateBlockedInfo(own)
|
|
376
408
|
return send(res, 200, {
|
|
377
409
|
status: 'not-updatable',
|
|
378
410
|
version: HOST_VERSION,
|
|
379
411
|
installedVersion,
|
|
380
412
|
source: own?.source ?? null,
|
|
381
|
-
|
|
413
|
+
reason: blocked.reason,
|
|
414
|
+
hint: blocked.hint,
|
|
382
415
|
})
|
|
383
416
|
}
|
|
384
417
|
|
|
@@ -444,9 +477,11 @@ export function apply(ctx) {
|
|
|
444
477
|
|
|
445
478
|
const own = await findSelfBundle(manager)
|
|
446
479
|
if (!own?.updatable) {
|
|
480
|
+
const blocked = selfUpdateBlockedInfo(own)
|
|
447
481
|
return send(res, 409, {
|
|
448
|
-
error:
|
|
482
|
+
error: blocked.hint,
|
|
449
483
|
code: 'not-updatable',
|
|
484
|
+
reason: blocked.reason,
|
|
450
485
|
})
|
|
451
486
|
}
|
|
452
487
|
|