@ququ-jiaxk/dsh-plugin-center 0.1.35 → 0.1.37
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 +22 -2
- package/lib/index.js +84 -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.37" : "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,7 @@ var selfUpdateTarget = null;
|
|
|
49
49
|
var selfUpdatePolling = false;
|
|
50
50
|
var selfUpdateNotified = false;
|
|
51
51
|
var lastSelfCheckAt = 0;
|
|
52
|
+
var selfUpdateRetried = false;
|
|
52
53
|
var selfUpdateInfo = { latest: null, checkedAt: 0, checking: false };
|
|
53
54
|
var selfUpdateSubscribers = /* @__PURE__ */ new Set();
|
|
54
55
|
var selfUpdateRequest = null;
|
|
@@ -297,6 +298,19 @@ function Panel() {
|
|
|
297
298
|
if (manual) setError("\u68C0\u67E5\u66F4\u65B0\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5");
|
|
298
299
|
return;
|
|
299
300
|
}
|
|
301
|
+
if (result.status === "unsupported") {
|
|
302
|
+
setSelfUpdate({ phase: "idle" });
|
|
303
|
+
if (manual) {
|
|
304
|
+
setDialog({
|
|
305
|
+
title: "\u5F53\u524D DSH \u7248\u672C\u4E0D\u652F\u6301\u81EA\u66F4\u65B0",
|
|
306
|
+
description: String(result.hint ?? ""),
|
|
307
|
+
input: false,
|
|
308
|
+
confirmLabel: "\u77E5\u9053\u4E86",
|
|
309
|
+
action: async () => void 0
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
300
314
|
if (result.status === "available" && result.latest) {
|
|
301
315
|
setSelfUpdate({ phase: "available", to: result.latest });
|
|
302
316
|
if (manual) setNotice(`\u53D1\u73B0\u65B0\u7248\u672C v${result.latest}`);
|
|
@@ -304,9 +318,14 @@ function Panel() {
|
|
|
304
318
|
}
|
|
305
319
|
if (result.status === "not-updatable") {
|
|
306
320
|
setSelfUpdate({ phase: "idle" });
|
|
321
|
+
if (result.reason === "unreadable" && !manual && !selfUpdateRetried) {
|
|
322
|
+
selfUpdateRetried = true;
|
|
323
|
+
setTimeout(() => void checkSelfUpdate(false), 5e3);
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
307
326
|
if (manual) {
|
|
308
327
|
setDialog({
|
|
309
|
-
title: "\u5F53\u524D\u5B89\u88C5\u65B9\u5F0F\u4E0D\u652F\u6301\u81EA\u66F4\u65B0",
|
|
328
|
+
title: result.reason === "local" ? "\u5F53\u524D\u5B89\u88C5\u65B9\u5F0F\u4E0D\u652F\u6301\u81EA\u66F4\u65B0" : "\u6682\u65F6\u65E0\u6CD5\u81EA\u66F4\u65B0",
|
|
310
329
|
description: String(result.hint ?? ""),
|
|
311
330
|
input: false,
|
|
312
331
|
confirmLabel: "\u77E5\u9053\u4E86",
|
|
@@ -315,6 +334,7 @@ function Panel() {
|
|
|
315
334
|
}
|
|
316
335
|
return;
|
|
317
336
|
}
|
|
337
|
+
selfUpdateRetried = false;
|
|
318
338
|
if (result.status === "unavailable") {
|
|
319
339
|
setSelfUpdate({ phase: "idle" });
|
|
320
340
|
if (manual) setError(`\u68C0\u67E5\u66F4\u65B0\u5931\u8D25\uFF1A${result.reason || result.problem || "\u672A\u77E5\u539F\u56E0"}`);
|
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) {
|
|
@@ -139,6 +170,28 @@ async function findSelfBundle(manager) {
|
|
|
139
170
|
}
|
|
140
171
|
}
|
|
141
172
|
|
|
173
|
+
/** 自更新依赖 DSH 0.2.x 的 listVersions / updateBundle;旧版管理器没有这两个方法。 */
|
|
174
|
+
function selfUpdateCapability(manager) {
|
|
175
|
+
if (!manager) return { supported: false, reason: 'no-manager' }
|
|
176
|
+
if (typeof manager.listVersions !== 'function' || typeof manager.updateBundle !== 'function') {
|
|
177
|
+
return { supported: false, reason: 'dsh-version' }
|
|
178
|
+
}
|
|
179
|
+
return { supported: true }
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function selfUpdateUnsupportedInfo(reason) {
|
|
183
|
+
if (reason === 'no-manager') {
|
|
184
|
+
return {
|
|
185
|
+
reason: 'no-manager',
|
|
186
|
+
hint: 'DSH 插件管理器不可用(当前不是 profile 模式),无法自更新。',
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
return {
|
|
190
|
+
reason: 'dsh-version',
|
|
191
|
+
hint: '当前 DSH 版本不支持面板自更新(插件管理器缺少 listVersions / updateBundle)。请先把 DSH 升级到 0.2.2 或更高版本,再点标题旁的版本号检查。',
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
142
195
|
function loadConfig() {
|
|
143
196
|
try {
|
|
144
197
|
const parsed = JSON.parse(readFileSync(CONFIG_PATH, 'utf8'))
|
|
@@ -363,6 +416,7 @@ export function apply(ctx) {
|
|
|
363
416
|
installed,
|
|
364
417
|
self,
|
|
365
418
|
selfUpdate: readSelfUpdateRecord(),
|
|
419
|
+
selfUpdateSupported: selfUpdateCapability(manager).supported,
|
|
366
420
|
})
|
|
367
421
|
}
|
|
368
422
|
|
|
@@ -370,15 +424,26 @@ export function apply(ctx) {
|
|
|
370
424
|
const manager = ctx.get('pluginManager')
|
|
371
425
|
if (!manager) return send(res, 503, { error: 'DSH 插件管理器不可用(当前不是 profile 模式)' })
|
|
372
426
|
|
|
427
|
+
const capability = selfUpdateCapability(manager)
|
|
428
|
+
if (!capability.supported) {
|
|
429
|
+
return send(res, 200, {
|
|
430
|
+
status: 'unsupported',
|
|
431
|
+
...selfUpdateUnsupportedInfo(capability.reason),
|
|
432
|
+
version: HOST_VERSION,
|
|
433
|
+
})
|
|
434
|
+
}
|
|
435
|
+
|
|
373
436
|
const own = await findSelfBundle(manager)
|
|
374
437
|
const installedVersion = own?.version ?? HOST_VERSION
|
|
375
438
|
if (!own?.updatable) {
|
|
439
|
+
const blocked = selfUpdateBlockedInfo(own)
|
|
376
440
|
return send(res, 200, {
|
|
377
441
|
status: 'not-updatable',
|
|
378
442
|
version: HOST_VERSION,
|
|
379
443
|
installedVersion,
|
|
380
444
|
source: own?.source ?? null,
|
|
381
|
-
|
|
445
|
+
reason: blocked.reason,
|
|
446
|
+
hint: blocked.hint,
|
|
382
447
|
})
|
|
383
448
|
}
|
|
384
449
|
|
|
@@ -442,11 +507,23 @@ export function apply(ctx) {
|
|
|
442
507
|
const manager = ctx.get('pluginManager')
|
|
443
508
|
if (!manager) return send(res, 503, { error: 'DSH 插件管理器不可用(当前不是 profile 模式)' })
|
|
444
509
|
|
|
510
|
+
const capability = selfUpdateCapability(manager)
|
|
511
|
+
if (!capability.supported) {
|
|
512
|
+
const unsupported = selfUpdateUnsupportedInfo(capability.reason)
|
|
513
|
+
return send(res, 409, {
|
|
514
|
+
error: unsupported.hint,
|
|
515
|
+
code: 'unsupported',
|
|
516
|
+
reason: unsupported.reason,
|
|
517
|
+
})
|
|
518
|
+
}
|
|
519
|
+
|
|
445
520
|
const own = await findSelfBundle(manager)
|
|
446
521
|
if (!own?.updatable) {
|
|
522
|
+
const blocked = selfUpdateBlockedInfo(own)
|
|
447
523
|
return send(res, 409, {
|
|
448
|
-
error:
|
|
524
|
+
error: blocked.hint,
|
|
449
525
|
code: 'not-updatable',
|
|
526
|
+
reason: blocked.reason,
|
|
450
527
|
})
|
|
451
528
|
}
|
|
452
529
|
|