dsh-folia 4.21.0 → 4.21.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.
- package/lib/client.js +13 -4
- package/lib/routes/downloads.js +14 -0
- package/lib/routes/site-media.js +7 -4
- package/package.json +1 -1
package/lib/client.js
CHANGED
|
@@ -20914,13 +20914,22 @@ window.__ModuleLoader__.load({
|
|
|
20914
20914
|
try { if (LF_STATE.note) LF_STATE.note(text, ok !== false); } catch { /* 提示失败不影响下载 */ }
|
|
20915
20915
|
}
|
|
20916
20916
|
|
|
20917
|
-
/** 从 inventory
|
|
20917
|
+
/** 从 inventory 里找这条。
|
|
20918
|
+
*
|
|
20919
|
+
* ⚠️ 老实现只认 `items` / `data.items`,而 `/folia/inventory` 实际把壁纸放在 **`wallpapers`** 里
|
|
20920
|
+
* ⇒ 永远找不到 ⇒ 静默不入队 ⇒ 代理侧也拿不到可复用的 job ⇒ 壁纸退化为"远端流式 + 被播放器背压"
|
|
20921
|
+
*(实测 0.6 MB/s、且缓存永远补不满)。现在按"任何一个对象数组里找 id"兜底,不依赖具体键名。
|
|
20922
|
+
*/
|
|
20918
20923
|
async function lfFindItem(id) {
|
|
20919
20924
|
try {
|
|
20920
20925
|
const resp = await apiJson("/inventory");
|
|
20921
|
-
const
|
|
20922
|
-
|
|
20923
|
-
|
|
20926
|
+
const doc = (resp && resp.data && typeof resp.data === 'object') ? resp.data : (resp || {});
|
|
20927
|
+
const pools = [doc.items, doc.wallpapers, doc.list, doc.entries].filter(Array.isArray);
|
|
20928
|
+
for (const pool of pools) {
|
|
20929
|
+
const hit = pool.find((x) => x && x.id === id);
|
|
20930
|
+
if (hit) return hit;
|
|
20931
|
+
}
|
|
20932
|
+
return null;
|
|
20924
20933
|
} catch { return null; }
|
|
20925
20934
|
}
|
|
20926
20935
|
|
package/lib/routes/downloads.js
CHANGED
|
@@ -66,6 +66,20 @@ export function queueJobFor(url, kind = 'wallpaper') {
|
|
|
66
66
|
} catch { return null; }
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
+
/** 队列汇总(给 /site-media-stats 用:壁纸缓存下了多少、多快)。 */
|
|
70
|
+
export function queueSummary() {
|
|
71
|
+
try {
|
|
72
|
+
const jobs = getDownloadQueue().snapshot();
|
|
73
|
+
const done = jobs.filter((j) => j.status === 'done');
|
|
74
|
+
return {
|
|
75
|
+
jobs: jobs.length,
|
|
76
|
+
done: done.length,
|
|
77
|
+
bytes: done.reduce((a, j) => a + (Number(j.total) || 0), 0),
|
|
78
|
+
active: jobs.filter((j) => j.status === 'running').length,
|
|
79
|
+
};
|
|
80
|
+
} catch { return null; }
|
|
81
|
+
}
|
|
82
|
+
|
|
69
83
|
export function registerDownloadsRoutes(webServer, c) {
|
|
70
84
|
const { disposers, base, serveFile, log } = c;
|
|
71
85
|
const downloadQueue = getDownloadQueue(log);
|
package/lib/routes/site-media.js
CHANGED
|
@@ -26,9 +26,9 @@
|
|
|
26
26
|
*
|
|
27
27
|
* 注入契约(ADR-0013 D12):`DEPS` 逐键由 `lib/index.js` 给到。
|
|
28
28
|
*/
|
|
29
|
-
import { createHash } from 'node:crypto';
|
|
30
|
-
import { openSync, readSync, closeSync } from 'node:fs';
|
|
31
|
-
import { queueJobFor } from './downloads.js';
|
|
29
|
+
import { createHash } from 'node:crypto';
|
|
30
|
+
import { openSync, readSync, closeSync } from 'node:fs';
|
|
31
|
+
import { queueJobFor, queueSummary } from './downloads.js';
|
|
32
32
|
import { Readable } from 'node:stream';
|
|
33
33
|
import { createWriteStream, existsSync, mkdirSync, readFileSync, readdirSync, renameSync, rmSync, statSync, utimesSync, writeFileSync } from 'node:fs';
|
|
34
34
|
import { join, extname } from 'node:path';
|
|
@@ -367,7 +367,8 @@ export function registerSiteMediaRoutes(webServer, c) {
|
|
|
367
367
|
files,
|
|
368
368
|
bytesOnDisk: total,
|
|
369
369
|
capBytes: capBytes(),
|
|
370
|
-
hits: stats.hits,
|
|
370
|
+
hits: stats.hits,
|
|
371
|
+
queue: queueSummary(),
|
|
371
372
|
misses: stats.misses,
|
|
372
373
|
failures: stats.failures,
|
|
373
374
|
avgMBps: stats.ms > 0 ? Number(((stats.bytes / 1048576) / (stats.ms / 1000)).toFixed(2)) : null,
|
|
@@ -415,6 +416,8 @@ export function registerSiteMediaRoutes(webServer, c) {
|
|
|
415
416
|
if (job && (job.status === 'done' || job.status === 'running')) {
|
|
416
417
|
const partPath = job.status === 'done' ? job.dest : job.dest + '.part';
|
|
417
418
|
if (existsSync(partPath)) {
|
|
419
|
+
// 复用即算命中:这条路没有走远端,统计里必须体现,否则会一直显示 hits=0 误导判断。
|
|
420
|
+
stats.hits += 1;
|
|
418
421
|
if (job.status === 'done') { try { res.setHeader('x-folia-cache', 'hit'); } catch { /* ignore */ } }
|
|
419
422
|
await serveGrowingFile(partPath, job, res, headOnly);
|
|
420
423
|
return;
|