dsh-folia 4.21.1 → 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/routes/downloads.js +14 -0
- package/lib/routes/site-media.js +7 -4
- package/package.json +1 -1
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;
|