dsh-folia 4.25.0 → 4.25.2

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.
@@ -310,6 +310,41 @@ export function prefetchCount() {
310
310
  return Math.min(PREFETCH_MAX, Math.round(raw));
311
311
  }
312
312
 
313
+ /**
314
+ * 4.25.1:入队条目的**稳定身份**(同一条目 = 同一条 job)。
315
+ *
316
+ * 客户端带 `itemKey`(`wallpaper:<inventory id>`)时原样采用;否则用 `itemId` / `id`
317
+ * 补上 kind 前缀。ID 若本身是 URL 则放弃(避免把整条 URL 当身份),交给队列按媒体族键兜底。
318
+ */
319
+ function itemKeyOf(it, kind) {
320
+ const raw = String((it && (it.itemKey || it.itemId || it.id)) || '').trim();
321
+ if (!raw || /^[a-z]+:\/\//i.test(raw)) return '';
322
+ if (raw.includes(':')) return raw;
323
+ return String(kind || 'media').trim().toLowerCase() + ':' + raw;
324
+ }
325
+
326
+ /**
327
+ * 入队时这条“应该被认成同一个条目”的全部 URL:原始地址 + 这次选中的地址 + 清单里的变体。
328
+ * 队列按它们精确反查,老数据(没有 itemKey 的变体 URL job)也能被复用/迁移。
329
+ */
330
+ function relatedUrlsOf(originalUrl, finalUrl, it) {
331
+ const out = new Set();
332
+ const add = (raw) => {
333
+ const s = String(raw || '').trim();
334
+ if (!s) return;
335
+ out.add(s);
336
+ try { out.add(new URL(s, originalUrl).toString()); } catch { /* 非绝对地址:保留原样那一个 */ }
337
+ };
338
+ add(originalUrl);
339
+ add(finalUrl);
340
+ add(it && it.variantUrl);
341
+ for (const v of (Array.isArray(it && it.variants) ? it.variants : [])) {
342
+ if (v && typeof v === 'object') add(v.url);
343
+ }
344
+ return [...out];
345
+ }
346
+
347
+
313
348
  /** <home>/library/<kind>/<sha256>.<ext>:同一 URL 同 kind ⇒ 同一路径(幂等的前提)。 */
314
349
  function libraryDest(kind, slug, ext) {
315
350
  const h = createHash('sha256').update(String(kind) + '/' + String(slug) + '/' + String(ext)).digest('hex').slice(0, 32);
@@ -425,6 +460,43 @@ export function queueJobFor(url, kind = 'wallpaper') {
425
460
  } catch { return null; }
426
461
  }
427
462
 
463
+ /**
464
+ * 4.25.1:清单条目 → **它在队列里的那条 job**(条目级身份优先,URL 族兜底)。
465
+ *
466
+ * 为什么需要(用户实测 4.25.0):清单里 `media` 是原始 URL,而队列里那条 job 下的是
467
+ * `.1080p.mp4` / `.30fps.mp4` 变体 ⇒ 客户端拿 URL 比对永远找不到 job,于是:
468
+ * · 卡片「缓存中」没有百分比(进度按 URL 绑丢了);
469
+ * · 启动时也无法判断"这是上次点击留下的 pending".
470
+ *
471
+ * 这里由宿主给出条目级事实(`itemKey` / `jobStatus` / `jobPriority` / `pendingHigh`),
472
+ * 客户端只渲染,不自己按 URL 猜。
473
+ *
474
+ * 只读:不 pump、不写盘、不排下载。
475
+ */
476
+ export function jobStateForItem(item) {
477
+ try {
478
+ const o = item || {};
479
+ const id = String(o.id || '').trim();
480
+ const kind = String(o.kind || 'wallpaper').trim().toLowerCase() || 'wallpaper';
481
+ const itemKey = id ? kind + ':' + id : String(o.itemKey || '').trim();
482
+ const job = getDownloadQueue().jobForItem({
483
+ itemKey,
484
+ url: String(o.media || o.url || ''),
485
+ kind,
486
+ relatedUrls: Array.isArray(o.variants) ? o.variants.map((v) => v && v.url).filter(Boolean) : [],
487
+ });
488
+ if (!job) return null;
489
+ return {
490
+ // 清单条目的规范键优先(`wallpaper:<id>`);队列里老记录的默认族键只做兜底。
491
+ itemKey: itemKey || job.itemKey,
492
+ jobId: job.id,
493
+ jobStatus: job.status,
494
+ jobPriority: job.priority,
495
+ pendingHigh: job.status === 'pending' && job.priority === 'high',
496
+ };
497
+ } catch { return null; }
498
+ }
499
+
428
500
  /** 队列汇总(给 /site-media-stats 用:壁纸缓存下了多少、多快)。 */
429
501
  export function queueSummary() {
430
502
  try {
@@ -513,6 +585,12 @@ export function registerDownloadsRoutes(webServer, c) {
513
585
  const url = String((it && it.url) || '');
514
586
  const kind = String((it && it.kind) || 'media');
515
587
  const priority = normalizePriority((it && it.priority) || bodyPriority);
588
+ /**
589
+ * 4.25.1:**条目级身份**(`itemKey`)。客户端从清单条目 id 生成
590
+ * `wallpaper:<id>`;老客户端 / 特殊调用方没带时,队列会按媒体族键兜底。
591
+ * 有了它,同一张壁纸的原始 URL 与 1080p/30fps 变体 URL 才能落到**同一条 job**。
592
+ */
593
+ const itemKey = itemKeyOf(it, kind);
516
594
  let u;
517
595
  try { u = new URL(url); } catch { out.push({ url, ok: false, error: 'bad-url' }); continue; }
518
596
  if (u.protocol !== 'http:' && u.protocol !== 'https:') { out.push({ url, ok: false, error: 'bad-protocol' }); continue; }
@@ -563,14 +641,34 @@ export function registerDownloadsRoutes(webServer, c) {
563
641
  * 那一刻由队列回调 `resolveCurrentExpectation(job)` 现问(见文件上方 MANIFEST_SOURCES)。
564
642
  * 这样站点在入队之后更新数据(换内容/换哈希)也不会让 job 拿旧值误判。
565
643
  */
644
+ const forceReload = Boolean(it && (it.forceReload === true
645
+ || String((it.quality !== undefined && it.quality !== null && it.quality !== '') ? it.quality : bodyQuality) === 'original'));
646
+ // 4.25.1(连点语义):`clicked:true` 才占"最近点击 8 条"的未开始队列名额;
647
+ // 预取 / 当前在播的 silent promote 都不传(它们不是"用户又点了一张")。
648
+ const clicked = Boolean(it && it.clicked === true);
566
649
  const r = downloadQueue.add({
567
650
  url: finalUrl, dest, kind, priority, chosenVariant: pick.chosen,
651
+ itemKey,
652
+ relatedUrls: relatedUrlsOf(u.toString(), finalUrl, it),
653
+ // 用户显式「用原画」= 允许把一条已完成 job 从变体档迁回原画档;无此标记时
654
+ // 已经缓存好的同族副本优先复用(不因为清单选档变化而整份重下)。
655
+ // 注意 quality 既可能来自条目级覆盖,也可能来自批次级(测试/旧客户端就发批次级)。
656
+ forceReload, clicked,
568
657
  });
658
+ const requestedVariant = pick.chosen === '1080p' || pick.chosen === '4k30' ? pick.chosen : 'original';
659
+ // 4.25.1:如果复用了已缓存的同族副本(原画/变体已在盘上),以 **job 实际 URL** 为准;
660
+ // 显式换档(forceReload)则这次一定会迁到请求的档位(在跑时先 abort 再迁)。
661
+ const jobVariant = forceReload
662
+ ? requestedVariant
663
+ : ((r.job && r.job.chosenVariant) || requestedVariant);
569
664
  out.push({
570
665
  url: finalUrl, ok: true, priority,
571
666
  // 选档结论随条目一起回去(客户端据此显示「1080p」小标,不用再猜)。
572
- chosenVariant: pick.chosen, variantReason: pick.reason,
667
+ chosenVariant: jobVariant,
668
+ variantReason: jobVariant === requestedVariant ? pick.reason : 'reuse-cached-variant',
573
669
  originalUrl: u.toString(),
670
+ // 4.25.1:客户端拿它绑进度(同一条目的原画/变体 job 是同一个 itemKey)。
671
+ itemKey: (r.job && r.job.itemKey) || itemKey,
574
672
  ...r,
575
673
  });
576
674
  }
@@ -664,7 +762,12 @@ export function registerDownloadsRoutes(webServer, c) {
664
762
  id: String((body && body.id) || ''),
665
763
  url: String((body && body.url) || ''),
666
764
  kind: String((body && body.kind) || 'wallpaper'),
765
+ // 4.25.1:同一条目的原画/变体 URL 必须能找到同一条 job(否则 pending 永远提不起来)。
766
+ itemKey: String((body && body.itemKey) || ''),
767
+ relatedUrls: Array.isArray(body && body.relatedUrls) ? body.relatedUrls : [],
667
768
  priority,
769
+ // 显式"点回/继续"才算一次用户点击(预取/在播提权不占连点名额)。
770
+ clicked: body && body.clicked === true,
668
771
  });
669
772
  } catch { /* 队列不可用:按未找到返回,客户端不阻塞切换 */ }
670
773
  send(res, 200, { ok: true, job: row || null });
@@ -107,7 +107,7 @@ import { homedir } from 'node:os';
107
107
  import { dirname, join } from 'node:path';
108
108
  // 本地优先:站点条目若已由下载队列落地,清单里直接给本地地址(渲染只读本地)。
109
109
  import {
110
- localCopyFor, localFamilyCopyFor, isSlowHostUrl, mediaStateOfUrl, registerManifestSource,
110
+ localCopyFor, localFamilyCopyFor, isSlowHostUrl, mediaStateOfUrl, registerManifestSource, jobStateForItem,
111
111
  } from './downloads.js';
112
112
  // **4.23.19:播放源的唯一解析器**(宿主与客户端同一份判据)。
113
113
  import { resolvePlaySrc } from '../media-state.js';
@@ -348,6 +348,26 @@ function siteProxyUrlOf(media) {
348
348
  + '?u=' + encodeURIComponent(s);
349
349
  }
350
350
 
351
+ /**
352
+ * 4.25.1:条目 → **队列事实**(itemKey / jobStatus / jobPriority / pendingHigh)。
353
+ *
354
+ * 客户端需要两个此前拿不到的事实:
355
+ * · 进度按 itemKey 绑(原画 URL 与变体 URL 是同一条目);
356
+ * · 启动时 pending + priority=high ⇒ 「未缓存(点击继续)」,**不自动下载**。
357
+ * 都由宿主随清单下发,客户端不再按 URL 猜。
358
+ */
359
+ function jobFieldsOf(item) {
360
+ const st = jobStateForItem(item);
361
+ const id = String((item && item.id) || '');
362
+ return {
363
+ itemKey: (st && st.itemKey) || (id ? 'wallpaper:' + id : ''),
364
+ jobId: st ? st.jobId : null,
365
+ jobStatus: st ? st.jobStatus : null,
366
+ jobPriority: st ? st.jobPriority : null,
367
+ pendingHigh: Boolean(st && st.pendingHigh),
368
+ };
369
+ }
370
+
351
371
  /**
352
372
  * **清单缓存命中时重算本地字段**(4.23.19)。
353
373
  *
@@ -375,6 +395,8 @@ function refreshLocalFields(item) {
375
395
  localDownload: play.source === 'local' ? family : null,
376
396
  mediaProxy: play.url,
377
397
  mediaState,
398
+ // 4.25.1:队列事实每次重算(缓存里的旧值不能当证据)。
399
+ ...jobFieldsOf(item),
378
400
  });
379
401
  }
380
402
 
@@ -464,7 +486,7 @@ function foliaItemFromCatalog(it, base) {
464
486
  // 这里不再写 `familyCopy ? familyCopy.url : proxy` —— 那条三元式正是"本地地址可能指向缺失文件"的入口。
465
487
  const mediaState = mediaStateOfUrl(media);
466
488
  const play = resolvePlaySrc(mediaState, { mediaProxy: siteProxyUrlOf(media), media });
467
- return {
489
+ const entry = {
468
490
  id: 'folia-' + (slug || media),
469
491
  title: String((it && it.title) || slug || 'Folia'),
470
492
  type, // 'video' | 'image' | 'package'
@@ -565,6 +587,8 @@ function foliaItemFromCatalog(it, base) {
565
587
  return /^[0-9a-f]{64}$/.test(v) ? v : null;
566
588
  })(),
567
589
  };
590
+ // 4.25.1:队列事实(itemKey / jobStatus / jobPriority)随条目下发。
591
+ return Object.assign(entry, jobFieldsOf(entry));
568
592
  }
569
593
 
570
594
  /** 旧静态清单 `{ images: [...] }` 的一条 → inventory 条目。 */
@@ -575,7 +599,7 @@ function foliaItemFromManifest(it, base) {
575
599
  const media = foliaAbs(base, it && it.url);
576
600
  if (!media) return null;
577
601
  const ext = (file.split('.').pop() || (type === 'video' ? 'mp4' : 'jpg')).toLowerCase();
578
- return {
602
+ const entry = {
579
603
  id: 'folia-' + (file || media),
580
604
  title: String((it && it.title) || file || 'Folia'),
581
605
  type,
@@ -593,6 +617,8 @@ function foliaItemFromManifest(it, base) {
593
617
  liveFrame: null,
594
618
  source: 'folia',
595
619
  };
620
+ // 4.25.1:同 catalog 路径 —— 队列事实随条目下发。
621
+ return Object.assign(entry, jobFieldsOf(entry));
596
622
  }
597
623
 
598
624
  /**
@@ -642,7 +668,7 @@ async function foliaRefresh(force = false, filter = null) {
642
668
 
643
669
  const startedAt = Date.now();
644
670
  /** @type {any[]} */
645
- let items = [];
671
+ const items = [];
646
672
  let error = null;
647
673
  let usedPath = FOLIA_CATALOG_PATH;
648
674
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-folia",
3
- "version": "4.25.0",
3
+ "version": "4.25.2",
4
4
  "description": "Folia 壁纸引擎:把本机 Wallpaper Engine 壁纸搬进 DSH 界面(场景实时渲染 / 视频 / 网页),内置液态玻璃与 Folia 吉祥物,并可从自建站点拉取壁纸。单包形态(组件已合并)。",
5
5
  "type": "module",
6
6
  "engines": {
@@ -182,6 +182,33 @@
182
182
  }
183
183
  },
184
184
  "license": "MIT",
185
+ "scripts": {
186
+ "build": "node scripts/build-client.mjs",
187
+ "install:source": "node scripts/install-source.mjs",
188
+ "install:release": "node scripts/install-release.mjs",
189
+ "pack:release": "node scripts/pack-release.mjs",
190
+ "verify:deployment": "node test/verify-deployment.mjs",
191
+ "verify:pet-link": "node test/verify-pet-link.mjs",
192
+ "verify:pet-link:integration": "node test/verify-pet-hotplug-integration.mjs",
193
+ "verify:pet-link:browser": "node test/verify-pet-tuner-browser.mjs",
194
+ "verify": "node test/run-guards.mjs verify",
195
+ "verify:docs": "node test/run-guards.mjs docs",
196
+ "verify:bridge": "node test/verify-bridge-ci.mjs --provision",
197
+ "verify:bridge:strict": "node test/verify-media-bridge.mjs --provision",
198
+ "verify:e2e": "node test/e2e-web-media-origin.mjs",
199
+ "lint": "eslint .",
200
+ "typecheck": "tsc --noEmit -p tsconfig.json",
201
+ "verify:static": "node test/verify-static.mjs",
202
+ "smoke": "node test/run-guards.mjs smoke",
203
+ "verify:all": "node test/run-guards.mjs all",
204
+ "prepack": "node scripts/prepare.mjs",
205
+ "test:boot": "node test/boot-http.mjs",
206
+ "test:pets": "node test/pets-http.mjs",
207
+ "test:pets-layer": "node test/pets-layer.mjs",
208
+ "test:features": "node test/verify-features.mjs",
209
+ "audit": "node test/run-audit.mjs",
210
+ "gate": "node scripts/build-client.mjs && node test/run-guards.mjs smoke && node test/verify-features.mjs && node test/verify-route-registry.mjs && node test/verify-settings-ownership.mjs && node test/boot-http.mjs && node test/pets-http.mjs && node test/pets-layer.mjs"
211
+ },
185
212
  "peerDependencies": {
186
213
  "@deepseek-ai/cordis": "^4.0.4",
187
214
  "@deepseek-ai/dsh-client-runtime": ">=0.1.5-rc.1",
@@ -214,31 +241,5 @@
214
241
  "@types/node": "^26.6.5",
215
242
  "eslint": "^10.12.0",
216
243
  "typescript": "^7.0.2"
217
- },
218
- "scripts": {
219
- "build": "node scripts/build-client.mjs",
220
- "install:source": "node scripts/install-source.mjs",
221
- "install:release": "node scripts/install-release.mjs",
222
- "pack:release": "node scripts/pack-release.mjs",
223
- "verify:deployment": "node test/verify-deployment.mjs",
224
- "verify:pet-link": "node test/verify-pet-link.mjs",
225
- "verify:pet-link:integration": "node test/verify-pet-hotplug-integration.mjs",
226
- "verify:pet-link:browser": "node test/verify-pet-tuner-browser.mjs",
227
- "verify": "node test/run-guards.mjs verify",
228
- "verify:docs": "node test/run-guards.mjs docs",
229
- "verify:bridge": "node test/verify-bridge-ci.mjs --provision",
230
- "verify:bridge:strict": "node test/verify-media-bridge.mjs --provision",
231
- "verify:e2e": "node test/e2e-web-media-origin.mjs",
232
- "lint": "eslint .",
233
- "typecheck": "tsc --noEmit -p tsconfig.json",
234
- "verify:static": "node test/verify-static.mjs",
235
- "smoke": "node test/run-guards.mjs smoke",
236
- "verify:all": "node test/run-guards.mjs all",
237
- "test:boot": "node test/boot-http.mjs",
238
- "test:pets": "node test/pets-http.mjs",
239
- "test:pets-layer": "node test/pets-layer.mjs",
240
- "test:features": "node test/verify-features.mjs",
241
- "audit": "node test/run-audit.mjs",
242
- "gate": "node scripts/build-client.mjs && node test/run-guards.mjs smoke && node test/verify-features.mjs && node test/verify-route-registry.mjs && node test/verify-settings-ownership.mjs && node test/boot-http.mjs && node test/pets-http.mjs && node test/pets-layer.mjs"
243
244
  }
244
- }
245
+ }