dsh-folia 4.23.4 → 4.23.6

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/serve.js CHANGED
@@ -44,6 +44,33 @@ import { Readable } from 'node:stream';
44
44
  import { dirname, resolve, sep } from 'node:path';
45
45
  import { weFocusGuardSource } from './we-focus-guard.js';
46
46
 
47
+ // ── 「已完成载荷」的浏览器缓存时长:按大小分档(4.23.5)──────────────────────
48
+ // 4.23.2 起代理对已完成文件回 `public, max-age=31536000, immutable`。副作用:
49
+ // Electron/Chromium 的 HTTP 缓存也会把大视频存一份 ⇒ 同一个文件在 library 与
50
+ // Chromium Cache 各占一份磁盘(用户报了"缓存目录涨得比预期快")。
51
+ // 规则:小文件长期缓存(收益大、副本小),大文件只缓存 1 小时(避免长期双份):
52
+ // · size ≤ 阈值 ⇒ `public, max-age=31536000, immutable`(与 4.23.2 逐字相同)
53
+ // · size > 阈值 ⇒ `public, max-age=3600`(**不加** immutable:一小时后再验证)
54
+ // 阈值默认 8 MB,`DSH_FOLIA_BIG_CACHE_MB` 可覆盖(夹取 1..1024;非法值回落默认)。
55
+ // ⚠️ 每次响应都重新读环境变量:测试与用户在运行期改设置(重启宿主)都走同一条。
56
+ const BIG_CACHE_DEFAULT_MB = 8;
57
+
58
+ /** 大文件阈值(字节)。边界语义:**等于**阈值算小文件(≤ 才是一年)。 */
59
+ export function bigCacheThresholdBytes() {
60
+ const raw = Number(process.env.DSH_FOLIA_BIG_CACHE_MB);
61
+ const mb = Number.isFinite(raw) && raw > 0 ? Math.min(1024, Math.max(1, raw)) : BIG_CACHE_DEFAULT_MB;
62
+ return Math.round(mb * 1024 * 1024);
63
+ }
64
+
65
+ /** 已完成载荷(内容永不改)的 `Cache-Control`:唯一一处大小分档规则。 */
66
+ export function completedCacheControl(sizeBytes) {
67
+ const size = Number(sizeBytes);
68
+ const known = Number.isFinite(size) && size > 0 ? size : 0;
69
+ return known > bigCacheThresholdBytes()
70
+ ? 'public, max-age=3600'
71
+ : 'public, max-age=31536000, immutable';
72
+ }
73
+
47
74
  // ── 场景载荷传输账本 ────────────────────────────────────────────────────────
48
75
  // **为什么需要它**:`/scene-files` 的 `scene.pkg` 动辄 100–336MB(实测本机
49
76
  // `pkg body: 336161480 bytes`),而渲染页的**首帧**必须等整包到齐(`mountScene` 里
@@ -335,7 +362,12 @@ export function createServeKit(c) {
335
362
  const etag = '"' + st.size.toString(16) + '-' + Math.floor(st.mtimeMs).toString(16) + '"';
336
363
  res.setHeader('ETag', etag);
337
364
  res.setHeader('Last-Modified', new Date(st.mtimeMs).toUTCString());
338
- res.setHeader('Cache-Control', 'public, max-age=31536000, immutable');
365
+ // 4.23.5:大文件降为 1 小时(不加 immutable)—— 见文件头「已完成载荷」那段。
366
+ // 判据:`test/verify-site-media.mjs` ⑧(2 MB / 12 MB / 8 MB 边界 / 环境变量覆盖)。
367
+ res.setHeader('Cache-Control', completedCacheControl(size));
368
+ // Range 请求(播放器的常态)与非 Range 请求是**不同的缓存表示**:加 Vary 让
369
+ // 浏览器/中间缓存不把一个 `bytes=0-` 的分片当作整份文件复用(只多一行头)。
370
+ res.setHeader('Vary', 'Range');
339
371
  if (!headOnly && !req.headers.range && notModifiedSince(req, etag, st.mtimeMs)) {
340
372
  res.statusCode = 304; res.end(); return;
341
373
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-folia",
3
- "version": "4.23.4",
3
+ "version": "4.23.6",
4
4
  "description": "Folia 壁纸引擎:把本机 Wallpaper Engine 壁纸搬进 DSH 界面(场景实时渲染 / 视频 / 网页),内置液态玻璃与 Folia 吉祥物,并可从自建站点拉取壁纸。单包形态(组件已合并)。",
5
5
  "type": "module",
6
6
  "engines": {