@ququ-jiaxk/dsh-plugin-center 0.1.38 → 0.1.40

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 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.38" : "0.0.0";
33
+ var PLUGIN_VERSION = true ? "0.1.40" : "0.0.0";
34
34
  var PANEL_ID = "plugin-center";
35
35
  var inject = ["slots", "remote", "remote.pluginManager"];
36
36
  var hostCtx = null;
@@ -75,7 +75,8 @@ async function fetchSelfUpdateInfo() {
75
75
  selfUpdateRequest = (async () => {
76
76
  try {
77
77
  const response = await fetch("/plugin-center/api/self/update-check", {
78
- signal: typeof AbortSignal !== "undefined" && AbortSignal.timeout ? AbortSignal.timeout(15e3) : void 0
78
+ // listVersions 会走一次 registry 查询,慢网络下 15s 不够。
79
+ signal: typeof AbortSignal !== "undefined" && AbortSignal.timeout ? AbortSignal.timeout(45e3) : void 0
79
80
  });
80
81
  if (!response.ok) throw new Error(`HTTP ${response.status}`);
81
82
  const data = await response.json();
package/lib/index.js CHANGED
@@ -439,31 +439,6 @@ export function apply(ctx) {
439
439
 
440
440
  const own = await findSelfBundle(manager)
441
441
  const installedVersion = own?.version ?? HOST_VERSION
442
- if (!own?.updatable) {
443
- const blocked = selfUpdateBlockedInfo(own)
444
- // listVersions 对不可升级的 bundle 会直接返回 DSH 的原始拒绝理由(不走网络),
445
- // 把它带出来,省得只能猜是来源、版本还是只读。
446
- let detail = null
447
- try {
448
- const refused = await manager.listVersions(SELF_PACKAGE)
449
- if (refused?.status === 'refused' && refused.reason) detail = String(refused.reason)
450
- } catch {
451
- /* 旧版管理器可能没有 listVersions,忽略 */
452
- }
453
- return send(res, 200, {
454
- status: 'not-updatable',
455
- version: HOST_VERSION,
456
- installedVersion,
457
- source: own?.source ?? null,
458
- reason: blocked.reason,
459
- detail,
460
- availability: own?.availability ?? null,
461
- readOnlyReason: own?.readOnlyReason ?? null,
462
- official: own?.official ?? null,
463
- error: own?.error ?? null,
464
- hint: detail ? `${blocked.hint}(DSH 判断:${detail})` : blocked.hint,
465
- })
466
- }
467
442
 
468
443
  let list
469
444
  try {
@@ -471,6 +446,34 @@ export function apply(ctx) {
471
446
  } catch (error) {
472
447
  return send(res, 502, { error: error?.message ?? '检查更新失败' })
473
448
  }
449
+
450
+ if (list?.status === 'refused') {
451
+ // 旧版 DSH 的 BundleInfo 没有 updatable 字段,只有 listVersions 能给出权威结论。
452
+ if (list.problem === 'not-updatable') {
453
+ const blocked = selfUpdateBlockedInfo(own)
454
+ const detail = list.reason ? String(list.reason) : null
455
+ return send(res, 200, {
456
+ status: 'not-updatable',
457
+ version: HOST_VERSION,
458
+ installedVersion,
459
+ source: own?.source ?? null,
460
+ reason: blocked.reason,
461
+ detail,
462
+ availability: own?.availability ?? null,
463
+ readOnlyReason: own?.readOnlyReason ?? null,
464
+ official: own?.official ?? null,
465
+ error: own?.error ?? null,
466
+ hint: detail ? `${blocked.hint}(DSH 判断:${detail})` : blocked.hint,
467
+ })
468
+ }
469
+ return send(res, 200, {
470
+ status: 'unavailable',
471
+ problem: list.problem ?? 'unknown',
472
+ reason: list.reason ?? '',
473
+ installedVersion,
474
+ })
475
+ }
476
+
474
477
  if (list?.status !== 'listed') {
475
478
  return send(res, 200, {
476
479
  status: 'unavailable',
@@ -536,13 +539,24 @@ export function apply(ctx) {
536
539
  }
537
540
 
538
541
  const own = await findSelfBundle(manager)
539
- if (!own?.updatable) {
540
- const blocked = selfUpdateBlockedInfo(own)
541
- return send(res, 409, {
542
- error: blocked.hint,
543
- code: 'not-updatable',
544
- reason: blocked.reason,
545
- })
542
+ if (own?.updatable !== true) {
543
+ // 旧版 DSH 没有 updatable 字段;用 listVersions 的权威结论判断能否升级。
544
+ let refused = null
545
+ try {
546
+ refused = await manager.listVersions(SELF_PACKAGE)
547
+ } catch {
548
+ refused = null
549
+ }
550
+ if (refused?.status === 'refused' && refused.problem === 'not-updatable') {
551
+ const blocked = selfUpdateBlockedInfo(own)
552
+ const detail = refused.reason ? String(refused.reason) : null
553
+ return send(res, 409, {
554
+ error: detail ? `${blocked.hint}(DSH 判断:${detail})` : blocked.hint,
555
+ code: 'not-updatable',
556
+ reason: blocked.reason,
557
+ detail,
558
+ })
559
+ }
546
560
  }
547
561
 
548
562
  // updateBundle 在 HMR 下会先卸载面板,这条请求可能拿不到后续响应,所以先回 202,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ququ-jiaxk/dsh-plugin-center",
3
- "version": "0.1.38",
3
+ "version": "0.1.40",
4
4
  "description": "DSH 插件中心面板:浏览、安装、更新和发布远端插件中心的插件",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",