dsh-rank-scan 0.2.4 → 0.3.0
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/README.md +22 -13
- package/lib/client.js +1756 -725
- package/lib/index.js +453 -111
- package/lib/index.js.map +1 -1
- package/lib/scan/daily.js +93 -0
- package/lib/scan/daily.js.map +1 -0
- package/lib/scan/diff.js +9 -1
- package/lib/scan/diff.js.map +1 -1
- package/lib/scan/freshness.js +67 -0
- package/lib/scan/freshness.js.map +1 -0
- package/lib/scan/run.js +32 -4
- package/lib/scan/run.js.map +1 -1
- package/lib/scan/schedule.js +1 -1
- package/lib/scan/schedule.js.map +1 -1
- package/lib/scan/store.js +82 -1
- package/lib/scan/store.js.map +1 -1
- package/lib/scan/types.js.map +1 -1
- package/lib/types/scan/daily.d.ts +89 -0
- package/lib/types/scan/diff.d.ts +6 -0
- package/lib/types/scan/freshness.d.ts +42 -0
- package/lib/types/scan/run.d.ts +8 -0
- package/lib/types/scan/store.d.ts +38 -0
- package/lib/types/scan/types.d.ts +24 -0
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -26,7 +26,9 @@ import { looksSwapped } from './scan/judges.js';
|
|
|
26
26
|
import { BookmarkService, BookmarkStore } from './scan/bookmark.js';
|
|
27
27
|
import { parseBookInput } from './scan/bookmark-parse.js';
|
|
28
28
|
import { decodeIfPua } from './scan/fontmap.js';
|
|
29
|
-
import { computeBoardDiff, daysOnBoard, guardCrossPeriod } from './scan/diff.js';
|
|
29
|
+
import { computeBoardDiff, daysOnBoard, guardCrossPeriod, jitterForBoard } from './scan/diff.js';
|
|
30
|
+
import { boardDayState, mergeDayIndex, mergeSlimBoards, previousTrustedDate, revisionDigest } from './scan/daily.js';
|
|
31
|
+
import { judgeFreshness, periodKeyFromRows } from './scan/freshness.js';
|
|
30
32
|
import { boundedFetch } from './scan/bounded-fetch.js';
|
|
31
33
|
import { minRequestIntervalMs, setMinRequestIntervalMs as applyRequestInterval } from './scan/rate-limit.js';
|
|
32
34
|
/**
|
|
@@ -37,7 +39,7 @@ import { minRequestIntervalMs, setMinRequestIntervalMs as applyRequestInterval }
|
|
|
37
39
|
* 纪律:本插件**不实现安装与重启**,只转发 dsh-market 的公开更新 API(桌面/被监管宿主由它裁决)。
|
|
38
40
|
*/
|
|
39
41
|
import { readOwnVersion, probeMarket, fetchNpmLatest, normalizeOperation, buildUpdateView } from './scan/update.js';
|
|
40
|
-
import { assertDataDate,
|
|
42
|
+
import { assertDataDate, dirSize, historyFor, listDataDates, listSlim, normalizeRetention, previousDataDate, readSlim, runRetention, sweepTmp, writeReport, writeSlim, } from './scan/files.js';
|
|
41
43
|
import { DEFAULT_FALLBACK_TIME, DEFAULT_SITE_TIMES, hmOf, planSiteRuns, SITE_ORDER, siteOfBoard, validTime } from './scan/schedule.js';
|
|
42
44
|
import { cacheStats, cachedBook, clearCache, putCachedBooks } from './scan/qidian-cache.js';
|
|
43
45
|
import { assignCachedStats, cacheStats as bookCacheStats, cachedEntry, putEntries } from './scan/book-cache.js';
|
|
@@ -361,103 +363,158 @@ export function apply(ctx, config) {
|
|
|
361
363
|
}
|
|
362
364
|
return done;
|
|
363
365
|
}
|
|
366
|
+
/**
|
|
367
|
+
* ★ Spec E(2026-10-24):**运行中那一轮**的扫描记录(只放内存,不落盘)。
|
|
368
|
+
* 落盘 scan.json 只在整轮结束时写一次 ⇒ 旧实现里 overview 在扫描过程中永远读到「上一轮的 completed」,
|
|
369
|
+
* 面板看不到 0/N → 1/N 的真实进度,定时扫描期间连「正在跑」都不知道。
|
|
370
|
+
* onProgress 每完成一个榜就把最新记录放进来;doScan 的 finally 立刻清空 ⇒ 不会残留假 running。
|
|
371
|
+
*/
|
|
372
|
+
let activeScan = null;
|
|
364
373
|
async function doScan(trigger, opts) {
|
|
365
374
|
const st = readState();
|
|
366
375
|
const store = new FileStore(root);
|
|
367
376
|
const effectiveBoards = opts && opts.boards
|
|
368
377
|
? String(opts.boards).split(',').map((x) => x.trim()).filter(Boolean)
|
|
369
378
|
: st.boards;
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
379
|
+
let rec;
|
|
380
|
+
try {
|
|
381
|
+
rec = await runScan({
|
|
382
|
+
/**
|
|
383
|
+
* ★ Spec E:走 serveSiteFor(与 /day、/repair 同一条测试 seam)。
|
|
384
|
+
* 生产没有 cfg.sitesFactory 时原样回退 sitesFor,行为不变;
|
|
385
|
+
* 有了它,单测才能用「可控延迟的隔离站点」验证 overview 在扫描中途读到真实进度。
|
|
386
|
+
*/
|
|
387
|
+
sites: serveSiteFor(effectiveBoards, st.depths || {}),
|
|
388
|
+
clock,
|
|
389
|
+
store,
|
|
390
|
+
trigger,
|
|
391
|
+
boards: effectiveBoards,
|
|
392
|
+
enrich: !!(opts && opts.enrich),
|
|
393
|
+
retryNonOk: !!(opts && opts.retry),
|
|
394
|
+
/** ★ 工作包 A:记录本批的范围(scan.json 是批次记录;当天状态在 day-index) */
|
|
395
|
+
partial: !!(opts && opts.partial),
|
|
396
|
+
batchSite: opts && opts.site ? String(opts.site) : null,
|
|
397
|
+
betweenBoardsMs: 500,
|
|
398
|
+
budget: { maxRequests: st.maxRequests || 600 },
|
|
399
|
+
/** 只更新内存活跃记录;观察者抛错由 runScan 兜住,不会中断扫描 */
|
|
400
|
+
onProgress: (r) => { activeScan = r; },
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
finally {
|
|
404
|
+
// 成功/取消/抛错都必须清:残留会让面板一直显示「扫描中」并按运行态高频轮询
|
|
405
|
+
activeScan = null;
|
|
406
|
+
}
|
|
381
407
|
/**
|
|
382
408
|
* ★ 2026-10-16(按站分时):一次「部分扫描」(只跑一个站)**不能覆盖当天的全量产物**:
|
|
383
409
|
* 精简索引/报告按 `<日期>-<站>` 落盘,全量扫的那份照旧叫 `<日期>`,两边都不丢。
|
|
384
410
|
*/
|
|
385
411
|
const artId = opts && opts.partial && opts.site ? rec.dataDate + '-' + String(opts.site) : rec.dataDate;
|
|
386
412
|
/**
|
|
387
|
-
* ★ 2026-10-
|
|
388
|
-
*
|
|
389
|
-
*
|
|
413
|
+
* ★ 工作包 A(2026-10-22):**唯一的新鲜度/可信度判定点**,取代原来互不相干的两段
|
|
414
|
+
* (①「与上一数据日 key=value 全等 ⇒ 疑似未刷新」② 刺猬猫「交集 ≤2 ⇒ 换榜」)。三个动机:
|
|
415
|
+
* ① 名次榜 value 恒为 null ⇒ 旧签名退化成书号列表,细节数字(收藏/字数)不参与;
|
|
416
|
+
* ② 周期榜同一期本来就不变(刺猬猫首订约 issue 478 连两天)⇒ 误判陈旧并触发**整站**兜底补抓;
|
|
417
|
+
* ③ 判定只改内存记录 ⇒ 被拒的快照仍在展示/变化/书签里(体检 P1-C)。
|
|
418
|
+
* 现在:逐榜向前找**上一次可信成功**(跨过缺日),按榜的更新节奏(日/周/期)判定;
|
|
419
|
+
* 命中 ⇒ 打 <date>/<boardId>.untrusted.json(raw 保留、只隔离使用)+ 记进 day-index。
|
|
390
420
|
*/
|
|
421
|
+
const batchIds = new Set(rec.batch?.boards || rec.boards.map((b) => b.boardId));
|
|
422
|
+
const batchBoards = rec.boards.filter((b) => batchIds.has(b.boardId));
|
|
423
|
+
const samePeriodBoards = new Set();
|
|
391
424
|
try {
|
|
392
|
-
const
|
|
425
|
+
const flagged = {};
|
|
393
426
|
const stS = readState();
|
|
394
427
|
const flags = { ...(stS.staleFlag || {}) };
|
|
395
|
-
for (const b of
|
|
428
|
+
for (const b of batchBoards) {
|
|
396
429
|
if (b.status !== 'ok')
|
|
397
430
|
continue;
|
|
398
431
|
const nx = store.readSnapshot(rec.dataDate, b.boardId);
|
|
432
|
+
if (!nx || !(nx.rows || []).length)
|
|
433
|
+
continue;
|
|
434
|
+
const prevD = previousBoardDate(b.boardId, rec.dataDate);
|
|
399
435
|
const pd = prevD ? store.readSnapshot(prevD, b.boardId) : null;
|
|
400
|
-
|
|
436
|
+
const verdict = judgeFreshness({
|
|
437
|
+
boardId: b.boardId,
|
|
438
|
+
date: rec.dataDate,
|
|
439
|
+
prevDate: prevD,
|
|
440
|
+
currentRows: nx.rows || [],
|
|
441
|
+
previousRows: pd ? (pd.rows || []) : null,
|
|
442
|
+
currentPeriodKey: periodKeyFromRows(nx.rows || []),
|
|
443
|
+
previousPeriodKey: pd ? periodKeyFromRows(pd.rows || []) : null,
|
|
444
|
+
});
|
|
445
|
+
const swapped = b.boardId.startsWith('ciweimao.') && !!pd && looksSwapped(b.rows, pd.rows);
|
|
446
|
+
if (swapped || verdict.verdict === 'suspected') {
|
|
447
|
+
const reason = swapped ? '疑似换榜/降级(与上次有效快照交集 ≤2)' : String(verdict.reason || '疑似未刷新');
|
|
448
|
+
try {
|
|
449
|
+
store.markUntrusted(rec.dataDate, b.boardId, { reason, at: new Date().toISOString(), by: trigger });
|
|
450
|
+
}
|
|
451
|
+
catch { /* 标记失败仍按记录处理 */ }
|
|
452
|
+
b.status = 'stale';
|
|
453
|
+
b.untrusted = true;
|
|
454
|
+
b.reason = reason;
|
|
455
|
+
b.rows = [];
|
|
401
456
|
delete flags[b.boardId];
|
|
402
|
-
|
|
457
|
+
if (!swapped)
|
|
458
|
+
flagged[b.boardId] = { date: rec.dataDate, prevDate: prevD, suspected: true };
|
|
403
459
|
}
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
else
|
|
460
|
+
else {
|
|
461
|
+
try {
|
|
462
|
+
store.clearUntrusted(rec.dataDate, b.boardId);
|
|
463
|
+
}
|
|
464
|
+
catch { /* 清标记失败不影响结果 */ }
|
|
410
465
|
delete flags[b.boardId];
|
|
466
|
+
if (verdict.samePeriod) {
|
|
467
|
+
b.samePeriod = true;
|
|
468
|
+
samePeriodBoards.add(b.boardId);
|
|
469
|
+
}
|
|
470
|
+
}
|
|
411
471
|
}
|
|
472
|
+
/**
|
|
473
|
+
* 适配器自己抛 StaleError 的榜(例如菠萝包判据)同样是「抓到但不可信」:
|
|
474
|
+
* 若当天目录里残留了更早的快照(同日先成功后判 stale),必须一并隔离,不能让它继续被展示。
|
|
475
|
+
*/
|
|
476
|
+
for (const b of batchBoards) {
|
|
477
|
+
if (b.status !== 'stale' || b.untrusted === true)
|
|
478
|
+
continue;
|
|
479
|
+
b.untrusted = true;
|
|
480
|
+
try {
|
|
481
|
+
store.markUntrusted(rec.dataDate, b.boardId, { reason: String(b.reason || '适配器判为不可信'), at: new Date().toISOString(), by: trigger });
|
|
482
|
+
}
|
|
483
|
+
catch { /* 标记失败仍按记录处理 */ }
|
|
484
|
+
}
|
|
485
|
+
// ★ 只把**真正可疑**的榜交回给兜底队列;「同一期未变化」不进 staleFlag(不再误触整站补抓)
|
|
486
|
+
Object.assign(flags, flagged);
|
|
412
487
|
stS.staleFlag = flags;
|
|
413
488
|
writeState(stS);
|
|
414
|
-
const suspectBoards = Object.keys(
|
|
489
|
+
const suspectBoards = Object.keys(flagged);
|
|
415
490
|
if (suspectBoards.length)
|
|
416
|
-
rec.warnings.push('
|
|
491
|
+
rec.warnings.push('以下榜的内容不可信(原始快照已保留,本次不展示、不参与变化):' + suspectBoards.join('、'));
|
|
492
|
+
if (samePeriodBoards.size)
|
|
493
|
+
rec.warnings.push('同一期未变化(正常,不判陈旧):' + Array.from(samePeriodBoards).join('、'));
|
|
494
|
+
}
|
|
495
|
+
catch (e) {
|
|
496
|
+
rec.warnings.push('新鲜度判定失败(不影响抓取):' + String(e).slice(0, 60));
|
|
417
497
|
}
|
|
418
|
-
catch { /* 自检失败不该挡住扫描 */ }
|
|
419
498
|
// 每个榜的「上次扫描」落进 state(部分扫描时 scan.json 只留最后一次 ⇒ 面板要能逐榜查)
|
|
420
499
|
try {
|
|
421
500
|
const stB = readState();
|
|
422
501
|
const bls = { ...(stB.boardLastScan || {}) };
|
|
423
|
-
for (const b of
|
|
502
|
+
for (const b of batchBoards)
|
|
424
503
|
bls[b.boardId] = { date: rec.dataDate, at: new Date().toISOString(), outcome: String(b.status), by: trigger };
|
|
425
504
|
stB.boardLastScan = bls;
|
|
426
505
|
writeState(stB);
|
|
427
506
|
}
|
|
428
507
|
catch { /* 记不上不该影响扫描结果 */ }
|
|
429
508
|
const snaps = new Map();
|
|
430
|
-
for (const b of
|
|
509
|
+
for (const b of batchBoards) {
|
|
431
510
|
if (b.status !== 'ok')
|
|
432
511
|
continue;
|
|
433
512
|
const s = store.readSnapshot(rec.dataDate, b.boardId);
|
|
434
513
|
if (s)
|
|
435
514
|
snaps.set(b.boardId, s);
|
|
436
515
|
}
|
|
437
|
-
//
|
|
516
|
+
// 派生榜不进扫描:如实说一句(否则以后看 scan.json 会以为「漏抓了一个榜」)
|
|
438
517
|
try {
|
|
439
|
-
const prevDate = previousDataDate(listDataDates(root), rec.dataDate);
|
|
440
|
-
let changed = false;
|
|
441
|
-
for (const b of rec.boards) {
|
|
442
|
-
if (b.status !== 'ok' || !b.boardId.startsWith('ciweimao.'))
|
|
443
|
-
continue;
|
|
444
|
-
const prev = prevDate ? store.readSnapshot(prevDate, b.boardId) : null;
|
|
445
|
-
if (prev && looksSwapped(b.rows, prev.rows)) {
|
|
446
|
-
b.status = 'stale';
|
|
447
|
-
b.reason = '疑似换榜/降级(与上次有效快照交集 ≤2)';
|
|
448
|
-
b.rows = [];
|
|
449
|
-
changed = true;
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
if (changed) {
|
|
453
|
-
rec.warnings.push('有榜命中「换榜/降级」判据,本次不出条目');
|
|
454
|
-
await store.writeScan(rec);
|
|
455
|
-
}
|
|
456
|
-
/**
|
|
457
|
-
* ★ 抓取集里的**派生榜**不会被扫描(它由本地快照算出来,不发请求):
|
|
458
|
-
* `sitesFor()` 明确排除 `fanqie.derived.*`,而 runScan 只遍历各适配器的 boards ⇒ 它天然缺席。
|
|
459
|
-
* 这是对的,但**必须在记录里说一句**,否则以后看 scan.json 会以为「漏抓了一个榜」(2026-10-15)。
|
|
460
|
-
*/
|
|
461
518
|
const derivedInCapture = (st.boards || []).filter((b) => b.startsWith('fanqie.derived.'));
|
|
462
519
|
if (derivedInCapture.length) {
|
|
463
520
|
rec.warnings.push('派生榜不进扫描(本地按快照计算,0 请求):' + derivedInCapture.join('、'));
|
|
@@ -465,17 +522,62 @@ export function apply(ctx, config) {
|
|
|
465
522
|
}
|
|
466
523
|
}
|
|
467
524
|
catch (e) {
|
|
468
|
-
rec.warnings.push('
|
|
525
|
+
rec.warnings.push('派生榜说明写入失败:' + String(e).slice(0, 50));
|
|
469
526
|
}
|
|
527
|
+
/**
|
|
528
|
+
* ★ 工作包 A:写「精简索引 + 报告」的唯一入口 —— **按日逐榜合并**。
|
|
529
|
+
* 旧实现 `buildSlim(rec, snaps)` 把整份文件换成「本批跑过的榜」:单榜重抓之后,
|
|
530
|
+
* 当天其余榜从 slim 里消失 ⇒ 之后 historyFor 判「新入榜/回榜」会把回榜算成新入榜(体检 P1-A ②)。
|
|
531
|
+
*/
|
|
532
|
+
const writeArtifacts = () => {
|
|
533
|
+
try {
|
|
534
|
+
const prevSlim = readSlim(root, artId);
|
|
535
|
+
const incoming = {};
|
|
536
|
+
const drop = [];
|
|
537
|
+
for (const b of batchBoards) {
|
|
538
|
+
if (b.untrusted === true) {
|
|
539
|
+
drop.push(b.boardId);
|
|
540
|
+
continue;
|
|
541
|
+
}
|
|
542
|
+
if (b.status !== 'ok')
|
|
543
|
+
continue;
|
|
544
|
+
const snap = snaps.get(b.boardId);
|
|
545
|
+
if (!snap || !(snap.rows || []).length)
|
|
546
|
+
continue;
|
|
547
|
+
incoming[b.boardId] = (snap.rows || []).map((r) => ({ key: r.key, rank: r.rank, metric: r.value }));
|
|
548
|
+
}
|
|
549
|
+
writeSlim(root, mergeSlimBoards(prevSlim, artId, incoming, drop));
|
|
550
|
+
writeReport(root, artId, renderReport(rec, root));
|
|
551
|
+
}
|
|
552
|
+
catch (e) {
|
|
553
|
+
rec.warnings.push('精简索引/报告写入失败:' + String(e).slice(0, 60));
|
|
554
|
+
}
|
|
555
|
+
};
|
|
556
|
+
writeArtifacts();
|
|
557
|
+
/**
|
|
558
|
+
* ★ 工作包 A:当天**逐榜**状态(批次记录 scan.json 只代表本批)。
|
|
559
|
+
* 只更新本批真正跑过的榜;A 站失败不会被之后 B 站成功冲掉。
|
|
560
|
+
*/
|
|
470
561
|
try {
|
|
471
|
-
const
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
562
|
+
const idxPrev = store.readDayIndex(rec.dataDate);
|
|
563
|
+
const updates = rec.boards
|
|
564
|
+
.filter((b) => batchIds.has(b.boardId))
|
|
565
|
+
.map((b) => ({
|
|
566
|
+
boardId: b.boardId,
|
|
567
|
+
status: b.status,
|
|
568
|
+
reason: b.reason ?? null,
|
|
569
|
+
rows: b.untrusted === true ? 0 : (b.rows || []).length,
|
|
570
|
+
trusted: b.untrusted !== true,
|
|
571
|
+
at: b.capturedAt || rec.finishedAt || rec.startedAt,
|
|
572
|
+
by: trigger,
|
|
573
|
+
capturedAt: b.capturedAt ?? null,
|
|
574
|
+
contentDate: b.contentDate ?? null,
|
|
575
|
+
samePeriod: b.samePeriod === true,
|
|
576
|
+
}));
|
|
577
|
+
await store.writeDayIndex(mergeDayIndex(idxPrev, rec.dataDate, updates, new Date().toISOString()));
|
|
476
578
|
}
|
|
477
579
|
catch (e) {
|
|
478
|
-
rec.warnings.push('
|
|
580
|
+
rec.warnings.push('逐榜状态索引写入失败:' + String(e).slice(0, 60));
|
|
479
581
|
}
|
|
480
582
|
/**
|
|
481
583
|
* ★ 2026-10-17(补全移出阻塞路径):把补全**从 /scan 的等待里摘出去**。
|
|
@@ -489,7 +591,7 @@ export function apply(ctx, config) {
|
|
|
489
591
|
* 同步通道(postScanEnrich)第一行就是「关了就直接返回」,defer 分支以前不看 ⇒ 用户关掉自动补全照样跑。
|
|
490
592
|
*/
|
|
491
593
|
if (opts && opts.deferEnrich && readState().autoEnrich !== false) {
|
|
492
|
-
const only = opts.partial ?
|
|
594
|
+
const only = opts.partial ? batchBoards.filter((b) => b.untrusted !== true).map((b) => b.boardId) : undefined;
|
|
493
595
|
/**
|
|
494
596
|
* ★ 2026-10-17(审查续核 ①):起点/起点图另有「起点收藏与三江字数」开关(qidianEnrich)。
|
|
495
597
|
* 同步通道在 postScanEnrich 里判过它;而 defer 路径的 worker 直接调 enrichBoard → qidianEnrichBoard,
|
|
@@ -507,14 +609,7 @@ export function apply(ctx, config) {
|
|
|
507
609
|
const queued = Object.keys((readState().enrichPending) || {}).length;
|
|
508
610
|
rec.warnings.push('补全已转入后台:' + queued + ' 个榜待补(抓榜数据已可用;面板顶部显示进度)');
|
|
509
611
|
await store.writeScan(rec);
|
|
510
|
-
|
|
511
|
-
const slimD = buildSlim(rec, snaps);
|
|
512
|
-
if (artId !== rec.dataDate)
|
|
513
|
-
slimD.dataDate = artId;
|
|
514
|
-
writeSlim(root, slimD);
|
|
515
|
-
writeReport(root, artId, renderReport(rec, root));
|
|
516
|
-
}
|
|
517
|
-
catch { /* 索引写失败不影响扫描结果 */ }
|
|
612
|
+
writeArtifacts();
|
|
518
613
|
startEnrichWorker('扫描后后台补全');
|
|
519
614
|
/**
|
|
520
615
|
* ★ 关键:不再跑 postScanEnrich(同步阻塞那 5 分钟)。
|
|
@@ -526,7 +621,7 @@ export function apply(ctx, config) {
|
|
|
526
621
|
// 整站扫描后补全「站上不给」的字数/收藏(刺猬猫 2 + 菠萝包 3;单榜扫描不跑)
|
|
527
622
|
if (opts && opts.enrichAfter && !opts.deferEnrich) {
|
|
528
623
|
try {
|
|
529
|
-
const res = await postScanEnrich(opts && opts.partial ?
|
|
624
|
+
const res = await postScanEnrich(opts && opts.partial ? batchBoards.filter((b) => b.untrusted !== true).map((b) => b.boardId) : undefined);
|
|
530
625
|
if (res && res.length) {
|
|
531
626
|
const total = res.reduce((n, x) => n + (x.requests || 0), 0);
|
|
532
627
|
/**
|
|
@@ -538,11 +633,7 @@ export function apply(ctx, config) {
|
|
|
538
633
|
const pendingN = res.filter((x) => still[x.boardId]).length;
|
|
539
634
|
rec.warnings.push('补全:' + res.length + ' 个榜跑了补全(' + total + ' 请求)' + (pendingN ? ';其中 ' + pendingN + ' 个仍缺字段,已记待办由定时续跑或在面板点「补齐本榜」' : ''));
|
|
540
635
|
await store.writeScan(rec);
|
|
541
|
-
|
|
542
|
-
if (artId !== rec.dataDate)
|
|
543
|
-
slim1.dataDate = artId;
|
|
544
|
-
writeSlim(root, slim1);
|
|
545
|
-
writeReport(root, artId, renderReport(rec, root));
|
|
636
|
+
writeArtifacts();
|
|
546
637
|
}
|
|
547
638
|
}
|
|
548
639
|
catch (e) {
|
|
@@ -814,7 +905,7 @@ export function apply(ctx, config) {
|
|
|
814
905
|
*
|
|
815
906
|
* 为什么需要它:跑失败也会写 siteLastRun=today(防 30 秒一次无脑重试),于是 due 永远不会再排它,
|
|
816
907
|
* 而旧兜底分支只认「疑似未刷新」⇒ 一次失败 = 当天彻底没了。现在这类站进兜底队列,22:30 再试一次。
|
|
817
|
-
*
|
|
908
|
+
* 判据:该站实际抓取集内任一榜没有「计划时刻之后」的成功抓取(本地派生榜除外)。
|
|
818
909
|
*/
|
|
819
910
|
function sitesFailedToday(sites, today, siteTimes) {
|
|
820
911
|
const st = readState();
|
|
@@ -826,16 +917,11 @@ export function apply(ctx, config) {
|
|
|
826
917
|
continue;
|
|
827
918
|
const plan = times[s] || DEFAULT_SITE_TIMES[s] || DEFAULT_FALLBACK_TIME;
|
|
828
919
|
const bs = (st.boards || []).filter((b) => siteOfBoard(b) === s);
|
|
829
|
-
|
|
830
|
-
for (const b of bs) {
|
|
920
|
+
const incomplete = bs.filter((b) => !b.startsWith('fanqie.derived.')).some((b) => {
|
|
831
921
|
const hit = bls[b];
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
if (!latest || hm > latest)
|
|
836
|
-
latest = hm;
|
|
837
|
-
}
|
|
838
|
-
if (!latest || latest < plan)
|
|
922
|
+
return !hit || hit.date !== today || hit.outcome !== 'ok' || hmOf(new Date(String(hit.at))) < plan;
|
|
923
|
+
});
|
|
924
|
+
if (incomplete)
|
|
839
925
|
out.push(s);
|
|
840
926
|
}
|
|
841
927
|
return out;
|
|
@@ -855,6 +941,8 @@ export function apply(ctx, config) {
|
|
|
855
941
|
fallbackTime: st.fallbackTime || DEFAULT_FALLBACK_TIME,
|
|
856
942
|
ranToday: sitesRanToday(sites, localDate(new Date()), st.siteTimes || DEFAULT_SITE_TIMES),
|
|
857
943
|
failed: sitesFailedToday(sites, localDate(new Date()), st.siteTimes || DEFAULT_SITE_TIMES),
|
|
944
|
+
retried: st.siteRetry || {},
|
|
945
|
+
stale: SITE_ORDER.filter((s) => Object.keys(st.staleFlag || {}).some((b) => siteOfBoard(b) === s && st.staleFlag[b]?.date === localDate(new Date()))),
|
|
858
946
|
});
|
|
859
947
|
/**
|
|
860
948
|
* ★ 2026-10-16(疑问「关闭状态为什么显示今天已跑」):把「这个站今天抓过没、谁抓的、几点抓的」
|
|
@@ -1084,6 +1172,87 @@ export function apply(ctx, config) {
|
|
|
1084
1172
|
const rec = await st.readScan(date);
|
|
1085
1173
|
return rec ? rec.boards.map((b) => b.boardId) : [];
|
|
1086
1174
|
}
|
|
1175
|
+
/**
|
|
1176
|
+
* ★ 工作包 A(2026-10-22):当天逐榜状态索引 + 可信度 + 数据 revision。
|
|
1177
|
+
* 三者都以「这一次请求要展示的数据日期」为键读取,缺文件时回退老口径(不报错)。
|
|
1178
|
+
*/
|
|
1179
|
+
function dayIndexOf(date) {
|
|
1180
|
+
if (!date)
|
|
1181
|
+
return null;
|
|
1182
|
+
try {
|
|
1183
|
+
return new FileStore(root).readDayIndex(date);
|
|
1184
|
+
}
|
|
1185
|
+
catch {
|
|
1186
|
+
return null;
|
|
1187
|
+
}
|
|
1188
|
+
}
|
|
1189
|
+
/** 这一天的这份快照是否被拒(stale 隔离;raw 仍在盘上) */
|
|
1190
|
+
function isUntrusted(date, boardId) {
|
|
1191
|
+
try {
|
|
1192
|
+
return new FileStore(root).isUntrusted(date, boardId);
|
|
1193
|
+
}
|
|
1194
|
+
catch {
|
|
1195
|
+
return false;
|
|
1196
|
+
}
|
|
1197
|
+
}
|
|
1198
|
+
/**
|
|
1199
|
+
* ★ 工作包 A:**该榜自己的上一次可信成功数据日**(跨过缺日、跨过被拒快照)。
|
|
1200
|
+
* 旧口径只看「全局上一数据日期」:该榜那天没跑成功就判「首次采集」⇒ 变化整列空、
|
|
1201
|
+
* 概览涨/新/退为 null(体检 P1-B:三江 10-18 缺一天,10-19 被误判 firstEver)。
|
|
1202
|
+
*/
|
|
1203
|
+
function previousBoardDate(boardId, date, dates) {
|
|
1204
|
+
const st = new FileStore(root);
|
|
1205
|
+
return previousTrustedDate(dates || listDataDates(root), date, (d) => st.readSnapshot(d, boardId), (d) => st.isUntrusted(d, boardId));
|
|
1206
|
+
}
|
|
1207
|
+
/**
|
|
1208
|
+
* ★ 工作包 A:手工补数(/day 落盘、/repair)之后把「这一榜这一天」恢复为可信,
|
|
1209
|
+
* 并同步当天逐榜索引 —— 否则隔离标记会一直挂着,展示端永远不给看。
|
|
1210
|
+
*/
|
|
1211
|
+
async function trustBoardDay(date, boardId, at) {
|
|
1212
|
+
const store = new FileStore(root);
|
|
1213
|
+
try {
|
|
1214
|
+
store.clearUntrusted(date, boardId);
|
|
1215
|
+
}
|
|
1216
|
+
catch { /* 清标记失败不影响补数结果 */ }
|
|
1217
|
+
const snap = store.readSnapshot(date, boardId);
|
|
1218
|
+
const rows = snap && Array.isArray(snap.rows) ? snap.rows.length : 0;
|
|
1219
|
+
const idxPrev = store.readDayIndex(date);
|
|
1220
|
+
const updates = [{
|
|
1221
|
+
boardId, status: 'ok', reason: null, rows, trusted: true, at, by: 'manual', capturedAt: at, contentDate: null,
|
|
1222
|
+
}];
|
|
1223
|
+
await store.writeDayIndex(mergeDayIndex(idxPrev, date, updates, at));
|
|
1224
|
+
if (snap)
|
|
1225
|
+
writeSlim(root, mergeSlimBoards(readSlim(root, date), date, {
|
|
1226
|
+
[boardId]: snap.rows.map((r) => ({ key: r.key, rank: r.rank, metric: r.value })),
|
|
1227
|
+
}));
|
|
1228
|
+
}
|
|
1229
|
+
/** 同一数据日期内数据是否变化(前端据此重取;含补全改写的快照) */
|
|
1230
|
+
function dataRevision(date) {
|
|
1231
|
+
if (!date)
|
|
1232
|
+
return null;
|
|
1233
|
+
const store = new FileStore(root);
|
|
1234
|
+
const idx = (() => { try {
|
|
1235
|
+
return store.readDayIndex(date);
|
|
1236
|
+
}
|
|
1237
|
+
catch {
|
|
1238
|
+
return null;
|
|
1239
|
+
} })();
|
|
1240
|
+
let stats = [];
|
|
1241
|
+
let untrusted = [];
|
|
1242
|
+
try {
|
|
1243
|
+
stats = store.snapshotStats(date);
|
|
1244
|
+
}
|
|
1245
|
+
catch {
|
|
1246
|
+
stats = [];
|
|
1247
|
+
}
|
|
1248
|
+
try {
|
|
1249
|
+
untrusted = store.untrustedBoards(date);
|
|
1250
|
+
}
|
|
1251
|
+
catch {
|
|
1252
|
+
untrusted = [];
|
|
1253
|
+
}
|
|
1254
|
+
return revisionDigest(idx ? idx.revision : 0, stats, untrusted);
|
|
1255
|
+
}
|
|
1087
1256
|
function diffFor(boardId, date, prevDate, jitter, slimAll) {
|
|
1088
1257
|
const store = new FileStore(root);
|
|
1089
1258
|
const current = store.readSnapshot(date, boardId);
|
|
@@ -1124,15 +1293,15 @@ export function apply(ctx, config) {
|
|
|
1124
1293
|
// ★ 跨期不可比 ⇒ 调用方必须把变化列判为「不可比」(置空 / 显示「新期」)
|
|
1125
1294
|
crossPeriod: !!d.crossPeriod,
|
|
1126
1295
|
counts: { new: d.newEntry.length, rebound: d.rebound.length, up: d.up.length, down: d.down.length, flat: d.flat.length, out: d.out.length },
|
|
1127
|
-
newEntry: d.newEntry
|
|
1128
|
-
rebound: d.rebound
|
|
1129
|
-
up: d.up
|
|
1130
|
-
down: d.down
|
|
1296
|
+
newEntry: d.newEntry,
|
|
1297
|
+
rebound: d.rebound,
|
|
1298
|
+
up: d.up,
|
|
1299
|
+
down: d.down,
|
|
1131
1300
|
// ★ flat 必须一起回传:面板要按它给「持平」的行标记名次 delta=0。
|
|
1132
1301
|
// 2026-10-15 修:此前 flat 整组丢掉 ⇒ 名次没动/±2 内的行 delta 落 null,
|
|
1133
1302
|
// 「变化」列大面积显示「—」(实测起点 20 行里 18 行是「—」,真实 flat=17)。
|
|
1134
1303
|
flat: d.flat.slice(0, 200),
|
|
1135
|
-
out: d.out
|
|
1304
|
+
out: d.out,
|
|
1136
1305
|
metricDelta: d.metricDelta.slice(0, 20),
|
|
1137
1306
|
};
|
|
1138
1307
|
}
|
|
@@ -1176,8 +1345,16 @@ export function apply(ctx, config) {
|
|
|
1176
1345
|
if (boardId.startsWith('fanqie.derived.'))
|
|
1177
1346
|
return '今日涨幅';
|
|
1178
1347
|
if (meta && meta.metric === 'value') {
|
|
1179
|
-
|
|
1348
|
+
/**
|
|
1349
|
+
* ★ 2026-10-22(工作包 A):三江的主指标是**收藏增量**(value / periodTotal),不是首订。
|
|
1350
|
+
* 旧实现把所有 qidiantu.* 一律叫「首订」⇒ 排序项、书签 metric 全带错标签(体检 P3)。
|
|
1351
|
+
*/
|
|
1352
|
+
if (boardId === 'qidiantu.sanjiang')
|
|
1353
|
+
return '收藏增量';
|
|
1354
|
+
if (boardId === 'qidiantu.shouding')
|
|
1180
1355
|
return '首订';
|
|
1356
|
+
if (boardId.startsWith('qidiantu.'))
|
|
1357
|
+
return '收藏增量';
|
|
1181
1358
|
if (boardId === 'ciweimao.buy.latest')
|
|
1182
1359
|
return '首订(约)';
|
|
1183
1360
|
return '在读';
|
|
@@ -1243,6 +1420,12 @@ export function apply(ctx, config) {
|
|
|
1243
1420
|
let best = null;
|
|
1244
1421
|
for (const date of dates) {
|
|
1245
1422
|
for (const boardId of boards) {
|
|
1423
|
+
/**
|
|
1424
|
+
* ★ 工作包 A:**被拒快照不参与书签自动更新** —— 否则 tab 里会写进一份
|
|
1425
|
+
* 站方还没刷新的旧值,且之后看起来像「今天的数据」。
|
|
1426
|
+
*/
|
|
1427
|
+
if (isUntrusted(date, boardId))
|
|
1428
|
+
continue;
|
|
1246
1429
|
const snap = store.readSnapshot(date, boardId);
|
|
1247
1430
|
if (!snap || !Array.isArray(snap.rows))
|
|
1248
1431
|
continue;
|
|
@@ -1307,15 +1490,26 @@ export function apply(ctx, config) {
|
|
|
1307
1490
|
const { st, dates, latest } = panelCtx();
|
|
1308
1491
|
const store = new FileStore(root);
|
|
1309
1492
|
const rec = latest ? await store.readScan(latest) : null;
|
|
1493
|
+
/** ★ Spec E:本轮正在跑时的内存记录(见 doScan 顶部注释);结束/抛错即清空 */
|
|
1494
|
+
const liveScan = activeScan || null;
|
|
1310
1495
|
const prevDate = latest ? previousDataDate(dates, latest) : null;
|
|
1496
|
+
/**
|
|
1497
|
+
* ★ 工作包 A:**当天逐榜状态**以 day-index.json 为准(scan.json 只是一批)。
|
|
1498
|
+
* 没有 day-index 的旧数据回退到老口径(rec.boards / 快照存在性),不报错、不伪造。
|
|
1499
|
+
*/
|
|
1500
|
+
const day = latest ? store.readDayIndex(latest) : null;
|
|
1311
1501
|
const slimAll = listSlim(root).map(d => readSlim(root, d)).filter(Boolean);
|
|
1312
1502
|
const rows = [];
|
|
1313
1503
|
for (const boardId of st.boards) {
|
|
1314
1504
|
const meta = boardMeta(boardId);
|
|
1315
1505
|
const b = rec && rec.boards ? rec.boards.find((x) => x.boardId === boardId) : null;
|
|
1506
|
+
const dstate = boardDayState(day, boardId);
|
|
1316
1507
|
const snap = latest ? store.readSnapshot(latest, boardId) : null;
|
|
1317
|
-
|
|
1318
|
-
const
|
|
1508
|
+
// ★ 逐榜基准:该榜自己的上一次可信成功(跨过缺日),不是「全局上一数据日」
|
|
1509
|
+
const bPrev = snap && latest ? previousBoardDate(boardId, latest, dates) : null;
|
|
1510
|
+
const trusted = dstate ? dstate.trusted !== false : !(latest && isUntrusted(latest, boardId));
|
|
1511
|
+
const diff = trusted && snap && latest && bPrev ? diffFor(boardId, latest, bPrev, undefined, slimAll) : null;
|
|
1512
|
+
const c = diff && !diff.crossPeriod && diff.counts ? diff.counts : null;
|
|
1319
1513
|
/**
|
|
1320
1514
|
* ★ 2026-10-17(发布前修):**本地派生榜**(fanqie.derived.*)永远不会有 scan 记录、
|
|
1321
1515
|
* 也不会落快照文件(数据是打开榜页时现算的)⇒ 旧口径「b ? … : snap ? 'ok' : 'missing'」
|
|
@@ -1323,12 +1517,30 @@ export function apply(ctx, config) {
|
|
|
1323
1517
|
* ⇒ 概览永远显示「异常 1 个榜」。它不是「没扫到」,是「不需要扫」:状态直接给 ok。
|
|
1324
1518
|
*/
|
|
1325
1519
|
const derived = boardId.startsWith('fanqie.derived.');
|
|
1520
|
+
const today = localDate(new Date());
|
|
1521
|
+
const attemptedToday = st.boardLastScan?.[boardId]?.date === today || (latest === today && !!(dstate || b));
|
|
1522
|
+
const plannedTime = st.siteTimes?.[meta.site] || DEFAULT_SITE_TIMES[meta.site] || DEFAULT_FALLBACK_TIME;
|
|
1523
|
+
const scheduleState = !derived && st.timerEnabled && !attemptedToday
|
|
1524
|
+
? (hmOf(new Date()) < plannedTime ? 'waiting' : 'due') : null;
|
|
1326
1525
|
rows.push({
|
|
1526
|
+
scheduleState, plannedTime,
|
|
1327
1527
|
boardId,
|
|
1328
1528
|
name: meta.name,
|
|
1329
1529
|
site: meta.site,
|
|
1330
1530
|
siteName: meta.siteName,
|
|
1331
|
-
|
|
1531
|
+
/**
|
|
1532
|
+
* ★ 工作包 A:优先用当天逐榜状态(含 missing/stale/truncated/login_required 五态);
|
|
1533
|
+
* 没有 day-index 才回退老口径。派生榜按设计不扫描 ⇒ 恒 ok。
|
|
1534
|
+
*/
|
|
1535
|
+
status: derived ? 'ok' : dstate ? dstate.status : b ? b.status : snap ? 'ok' : 'missing',
|
|
1536
|
+
/** true = 内容可信(stale 隔离后为 false;前端据此不给「正常」字样) */
|
|
1537
|
+
trusted: derived ? true : dstate ? dstate.trusted !== false : !(latest && isUntrusted(latest, boardId)),
|
|
1538
|
+
/** true = 同一期未变化(周期榜正常形态) */
|
|
1539
|
+
samePeriod: dstate ? dstate.samePeriod === true : false,
|
|
1540
|
+
/** 当天最近一次尝试(失败原因留在这里,不被之后的成功批次冲掉) */
|
|
1541
|
+
attempt: dstate ? dstate.lastAttempt : null,
|
|
1542
|
+
/** 当天最近一次可信成功的时刻(没有就 null) */
|
|
1543
|
+
lastSuccessAt: dstate && dstate.lastSuccess ? dstate.lastSuccess.at : null,
|
|
1332
1544
|
up: c ? c.up : null,
|
|
1333
1545
|
newCount: c ? c.new + c.rebound : null,
|
|
1334
1546
|
out: c ? c.out : null,
|
|
@@ -1339,6 +1551,9 @@ export function apply(ctx, config) {
|
|
|
1339
1551
|
* ③ 都没有(本地派生榜 / 今天没抓到的榜)就留 null,面板显示「—」,不再拿别人的时间冒充。
|
|
1340
1552
|
*/
|
|
1341
1553
|
lastCapture: (function () {
|
|
1554
|
+
// ★ 工作包 A:优先「当天最近一次可信成功」;否则退回本批的 capturedAt / 旧兜底
|
|
1555
|
+
if (dstate && dstate.lastSuccess && dstate.lastSuccess.at)
|
|
1556
|
+
return String(dstate.lastSuccess.at);
|
|
1342
1557
|
const own = b && b.capturedAt ? String(b.capturedAt) : null;
|
|
1343
1558
|
if (own)
|
|
1344
1559
|
return own;
|
|
@@ -1351,7 +1566,11 @@ export function apply(ctx, config) {
|
|
|
1351
1566
|
const mt = latest ? store.snapshotMtime(boardId, latest) : null;
|
|
1352
1567
|
return mt ? new Date(mt).toISOString() : null;
|
|
1353
1568
|
})(),
|
|
1354
|
-
note: derived
|
|
1569
|
+
note: derived
|
|
1570
|
+
? '本地派生(0 请求,打开榜页时现算)'
|
|
1571
|
+
: dstate
|
|
1572
|
+
? (dstate.reason || (dstate.samePeriod ? '同一期未变化(正常)' : null))
|
|
1573
|
+
: b ? b.reason || null : snap ? null : '今天还没扫(或该榜抓取失败)',
|
|
1355
1574
|
extended: !!meta.extended,
|
|
1356
1575
|
source: meta.source || null,
|
|
1357
1576
|
mainLabel: mainLabelOf(boardId, meta),
|
|
@@ -1368,6 +1587,12 @@ export function apply(ctx, config) {
|
|
|
1368
1587
|
baselineDate: prevDate,
|
|
1369
1588
|
firstEver: dates.length < 2,
|
|
1370
1589
|
counts,
|
|
1590
|
+
/**
|
|
1591
|
+
* ★ 工作包 A:同日数据 revision。扫描/单榜重抓/补全只要改写了快照或隔离标记就会变,
|
|
1592
|
+
* 前端不必等「数据日期」变化才重取(体检 P2-C 的后端侧支撑)。
|
|
1593
|
+
*/
|
|
1594
|
+
revision: dataRevision(latest),
|
|
1595
|
+
dayRevision: day ? day.revision : null,
|
|
1371
1596
|
// 派生榜按设计不进 display ⇒ 不能算进「隐藏 N 个」(它不是被藏起来的,是不需要单独扫)
|
|
1372
1597
|
hiddenCount: rows.filter((r) => !r.displayed && !r.derived).length,
|
|
1373
1598
|
sites: groupBySite(rows).map((s) => ({ ...s, boards: rows.filter((r) => r.site === s.site) })),
|
|
@@ -1401,8 +1626,22 @@ export function apply(ctx, config) {
|
|
|
1401
1626
|
/** ★ 按站分时:现在会跑哪个站、每站上次跑过的数据日(面板「抓什么」页展示) */
|
|
1402
1627
|
schedule: timerPlanNow(),
|
|
1403
1628
|
},
|
|
1404
|
-
|
|
1405
|
-
|
|
1629
|
+
/**
|
|
1630
|
+
* ★ Spec E(2026-10-24):运行中优先用**内存活跃记录**(onProgress 每榜更新),
|
|
1631
|
+
* 落盘 scan.json 只在整轮结束才写 ⇒ 旧实现在扫描过程中永远回上一轮的 completed。
|
|
1632
|
+
* inFlight 让面板能区分「真的在跑」与「上次进程崩了留下的 running」:
|
|
1633
|
+
* 后者不该显示进度、也不该高频轮询。
|
|
1634
|
+
*/
|
|
1635
|
+
scan: (liveScan || rec)
|
|
1636
|
+
? {
|
|
1637
|
+
outcome: (liveScan || rec).outcome,
|
|
1638
|
+
attempt: (liveScan || rec).attempt,
|
|
1639
|
+
trigger: (liveScan || rec).trigger,
|
|
1640
|
+
progress: (liveScan || rec).progress,
|
|
1641
|
+
warnings: (liveScan || rec).warnings,
|
|
1642
|
+
startedAt: (liveScan || rec).startedAt,
|
|
1643
|
+
inFlight: !!liveScan,
|
|
1644
|
+
}
|
|
1406
1645
|
: null,
|
|
1407
1646
|
defaults: {
|
|
1408
1647
|
scanTime: st.scanTime,
|
|
@@ -1529,7 +1768,9 @@ export function apply(ctx, config) {
|
|
|
1529
1768
|
// 该榜有任何本地数据就出这一列(单日时每行是「1 天」;没有更早数据 ≠ 没历史)
|
|
1530
1769
|
const hasHistory = shouldShowDays(meta.site, datesFor.length);
|
|
1531
1770
|
// 列集合统一过一遍站点口径(起点图不出名次变化、三江不出重复的 daily、刺猬猫首订不出在榜天数)
|
|
1532
|
-
|
|
1771
|
+
// ★ 工作包 A:「有基准」要按**该榜自己**有没有上一次可信快照判(不能拿全局日期数冒充)
|
|
1772
|
+
const boardPrev = previousBoardDate(boardId, date, dates);
|
|
1773
|
+
const columns = applyColumnPolicy(columnsFor(meta, { hasBaseline: !!boardPrev, hasHistory }), boardId);
|
|
1533
1774
|
// 派生榜(番茄在读涨幅榜 / 七日累计):纯本地算,不发请求
|
|
1534
1775
|
if (boardId.startsWith('fanqie.derived.')) {
|
|
1535
1776
|
const read = (b, d) => store.readSnapshot(d, b);
|
|
@@ -1575,7 +1816,41 @@ export function apply(ctx, config) {
|
|
|
1575
1816
|
if (!snap)
|
|
1576
1817
|
return { boardId, meta, columns, dataDate: useDate, dates: datesFor, rows: [], note: '该榜在这天没有快照(也没找到更早的可用快照)' };
|
|
1577
1818
|
const effDate = fallbackFrom || date;
|
|
1578
|
-
|
|
1819
|
+
/**
|
|
1820
|
+
* ★ 工作包 A:逐榜基准 = **该榜自己的上一次可信成功**(跨过缺日、跨过被拒快照)。
|
|
1821
|
+
* 旧口径只看全局上一数据日:该榜缺一天 → previousPer 为空 → 整列变化空、firstEver=true(体检 P1-B)。
|
|
1822
|
+
*/
|
|
1823
|
+
const prevDate = previousBoardDate(boardId, effDate, dates);
|
|
1824
|
+
/**
|
|
1825
|
+
* ★ 工作包 A:**stale 隔离**。raw 快照保留在盘上(证据),但不进展示:
|
|
1826
|
+
* 返回空行 + 明确状态,前端只需按 status/note 显示说明(不再拿被拒页面当今天榜单)。
|
|
1827
|
+
*/
|
|
1828
|
+
if (isUntrusted(effDate, boardId)) {
|
|
1829
|
+
const mark = store.readUntrusted(effDate, boardId);
|
|
1830
|
+
return {
|
|
1831
|
+
boardId,
|
|
1832
|
+
meta: { ...meta, mainLabel: mainLabelOf(boardId, meta) },
|
|
1833
|
+
sortOptions: sortOptionsFor(boardId, meta, { hasHistory }),
|
|
1834
|
+
depth: (st.depths || {})[boardId] ?? (meta.site === 'fanqie' ? 30 : 10),
|
|
1835
|
+
columns,
|
|
1836
|
+
dataDate: effDate,
|
|
1837
|
+
requestedDate: date,
|
|
1838
|
+
fallbackFrom,
|
|
1839
|
+
dates: datesFor,
|
|
1840
|
+
baselineDate: prevDate,
|
|
1841
|
+
firstEver: !prevDate,
|
|
1842
|
+
counts: null,
|
|
1843
|
+
status: 'stale',
|
|
1844
|
+
trusted: false,
|
|
1845
|
+
rawRows: (snap.rows || []).length,
|
|
1846
|
+
attempt: store.readDayIndex(effDate)?.boards?.[boardId]?.lastAttempt || null,
|
|
1847
|
+
revision: dataRevision(effDate),
|
|
1848
|
+
enrich: null,
|
|
1849
|
+
rows: [],
|
|
1850
|
+
note: '本次抓到内容不可信(' + String((mark && mark.reason) || '疑似未刷新/换榜') + ')。原始快照已保留在 ' + effDate + '/' + boardId + '.json,但本次不展示、不参与变化。',
|
|
1851
|
+
source: meta.source || null,
|
|
1852
|
+
};
|
|
1853
|
+
}
|
|
1579
1854
|
const diff = prevDate ? diffFor(boardId, effDate, prevDate) : null;
|
|
1580
1855
|
const byKey = new Map();
|
|
1581
1856
|
if (diff) {
|
|
@@ -1612,9 +1887,16 @@ export function apply(ctx, config) {
|
|
|
1612
1887
|
boardId,
|
|
1613
1888
|
prevDate,
|
|
1614
1889
|
date: effDate,
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1890
|
+
/**
|
|
1891
|
+
* ★ 工作包 A:期键一律取快照里的**真实期号** —— 三江 = extra.periodStart,
|
|
1892
|
+
* 刺猬猫首订(约) = extra.issue。旧实现只给刺猬猫接了这个口,三江退回「本周日」推算,
|
|
1893
|
+
* 而缺日/跨周时推算出的期与站点实际期不一致 ⇒ 跨期保护会漏判。
|
|
1894
|
+
*/
|
|
1895
|
+
periodKeyOf: boardId === 'qidiantu.sanjiang'
|
|
1896
|
+
? (dt) => keyFromSnap(dt === effDate ? snap : prevSnap, 'periodStart')
|
|
1897
|
+
: boardId === 'ciweimao.buy.latest'
|
|
1898
|
+
? (dt) => keyFromSnap(dt === effDate ? snap : prevSnap, 'issue')
|
|
1899
|
+
: undefined,
|
|
1618
1900
|
});
|
|
1619
1901
|
const crossPeriod = guard.crossed;
|
|
1620
1902
|
const prevByKey = new Map();
|
|
@@ -1726,7 +2008,7 @@ export function apply(ctx, config) {
|
|
|
1726
2008
|
}
|
|
1727
2009
|
else if (pr != null && cr != null) {
|
|
1728
2010
|
deltaOut = pr - cr;
|
|
1729
|
-
groupOut = dd ? dd.group : (Math.abs(deltaOut) <=
|
|
2011
|
+
groupOut = dd ? dd.group : (Math.abs(deltaOut) <= jitterForBoard(boardId) ? 'flat' : deltaOut > 0 ? 'up' : 'down');
|
|
1730
2012
|
}
|
|
1731
2013
|
else if (typeof (r.extra && r.extra.rankPosDiff) === 'number') {
|
|
1732
2014
|
/**
|
|
@@ -1768,6 +2050,12 @@ export function apply(ctx, config) {
|
|
|
1768
2050
|
rows = rows.slice().sort((a, b) => compareDesc(num(sortVal(a, effSort)), num(sortVal(b, effSort))));
|
|
1769
2051
|
if (limit > 0)
|
|
1770
2052
|
rows = rows.slice(0, limit);
|
|
2053
|
+
/**
|
|
2054
|
+
* ★ 工作包 A:状态取**当天逐榜索引**(而不是「最后一批扫描记录」)。
|
|
2055
|
+
* 旧实现读 scan.json:一天 5 批之后只剩最后一站的记录 ⇒ 其余站的状态被洗成 ok/missing。
|
|
2056
|
+
*/
|
|
2057
|
+
const dayIdxB = store.readDayIndex(effDate);
|
|
2058
|
+
const dstateB = boardDayState(dayIdxB, boardId);
|
|
1771
2059
|
const statusRow = await store.readScan(effDate);
|
|
1772
2060
|
const brd = statusRow && statusRow.boards ? statusRow.boards.find((x) => x.boardId === boardId) : null;
|
|
1773
2061
|
/**
|
|
@@ -1805,8 +2093,15 @@ export function apply(ctx, config) {
|
|
|
1805
2093
|
dates: datesFor,
|
|
1806
2094
|
baselineDate: diff ? diff.baselineDate : null,
|
|
1807
2095
|
firstEver: diff ? diff.firstEver : true,
|
|
1808
|
-
counts: diff ? diff.counts : null,
|
|
1809
|
-
|
|
2096
|
+
counts: diff && !crossPeriod ? diff.counts : null,
|
|
2097
|
+
crossPeriod,
|
|
2098
|
+
status: dstateB ? dstateB.status : brd ? brd.status : 'ok',
|
|
2099
|
+
trusted: dstateB ? dstateB.trusted !== false : !isUntrusted(effDate, boardId),
|
|
2100
|
+
samePeriod: dstateB ? dstateB.samePeriod === true : false,
|
|
2101
|
+
/** 当天最近一次尝试(含失败原因)—— 失败不会被之后别的站的成功冲掉 */
|
|
2102
|
+
attempt: dstateB ? dstateB.lastAttempt : null,
|
|
2103
|
+
/** 同名数据日期内的数据 revision(前端据此重取,不必等跨日) */
|
|
2104
|
+
revision: dataRevision(effDate),
|
|
1810
2105
|
enrich: enrichInfo,
|
|
1811
2106
|
rows,
|
|
1812
2107
|
// ★ 跨期当天必须写明「变化列为什么是空的」(口径说明跟着数据一起走,别只活在代码注释里)
|
|
@@ -1829,6 +2124,10 @@ export function apply(ctx, config) {
|
|
|
1829
2124
|
const slimAll = listSlim(root).map(d => readSlim(root, d)).filter(Boolean);
|
|
1830
2125
|
const entries = [];
|
|
1831
2126
|
let firstEver = true;
|
|
2127
|
+
/** ★ 工作包 A:当天有快照但被拒的榜(不让它们的变化漏进来) */
|
|
2128
|
+
const excluded = [];
|
|
2129
|
+
/** ★ 工作包 A:确实没有可比基准的榜(如实说明,而不是静默跳过) */
|
|
2130
|
+
const noBaseline = [];
|
|
1832
2131
|
for (const boardId of st.boards) {
|
|
1833
2132
|
if (!st.display.includes(boardId))
|
|
1834
2133
|
continue;
|
|
@@ -1838,12 +2137,27 @@ export function apply(ctx, config) {
|
|
|
1838
2137
|
if (!snap)
|
|
1839
2138
|
continue;
|
|
1840
2139
|
const meta = boardMeta(boardId);
|
|
1841
|
-
if (
|
|
2140
|
+
if (isUntrusted(useDate, boardId)) {
|
|
2141
|
+
excluded.push({ boardId, reason: '内容不可信(已隔离)' });
|
|
1842
2142
|
continue;
|
|
1843
|
-
|
|
2143
|
+
}
|
|
2144
|
+
/**
|
|
2145
|
+
* ★ 工作包 A:逐榜基准(跨过缺日)。缺基准的榜不再「静默跳过且被算成没变化」,
|
|
2146
|
+
* 而是进 noBaseline 列表,由 note 如实说明。
|
|
2147
|
+
*/
|
|
2148
|
+
const prevB = previousBoardDate(boardId, useDate, dates);
|
|
2149
|
+
if (!prevB) {
|
|
2150
|
+
noBaseline.push(boardId);
|
|
2151
|
+
continue;
|
|
2152
|
+
}
|
|
2153
|
+
const d = diffFor(boardId, useDate, prevB, undefined, slimAll);
|
|
1844
2154
|
if (d.firstEver)
|
|
1845
2155
|
continue;
|
|
1846
2156
|
firstEver = false;
|
|
2157
|
+
if (d.crossPeriod) {
|
|
2158
|
+
excluded.push({ boardId, reason: '新期不可比(不参与变化)' });
|
|
2159
|
+
continue;
|
|
2160
|
+
}
|
|
1847
2161
|
const push = (group, list, sign) => {
|
|
1848
2162
|
for (const e of list || [])
|
|
1849
2163
|
entries.push({
|
|
@@ -1851,6 +2165,8 @@ export function apply(ctx, config) {
|
|
|
1851
2165
|
siteName: meta.siteName,
|
|
1852
2166
|
boardId,
|
|
1853
2167
|
boardName: meta.name,
|
|
2168
|
+
/** ★ 工作包 A:该榜自己的对比基准日(各榜基准可能不同,顶层的 baselineDate 只是汇总) */
|
|
2169
|
+
baselineDate: d.baselineDate,
|
|
1854
2170
|
group,
|
|
1855
2171
|
title: e.title,
|
|
1856
2172
|
delta: e.delta == null ? '' : sign + String(e.delta),
|
|
@@ -1868,8 +2184,16 @@ export function apply(ctx, config) {
|
|
|
1868
2184
|
baselineDate: prevDate,
|
|
1869
2185
|
firstEver: firstEver && !entries.length,
|
|
1870
2186
|
count: entries.length,
|
|
1871
|
-
sites: groupChanges(entries),
|
|
1872
|
-
|
|
2187
|
+
sites: groupChanges(entries).map((site) => ({ ...site, groups: site.groups.map((g) => ({ ...g, count: g.items.length })) })),
|
|
2188
|
+
/** ★ 工作包 A:同日内数据变化就换 revision(前端不必等跨日) */
|
|
2189
|
+
revision: dataRevision(useDate),
|
|
2190
|
+
excluded,
|
|
2191
|
+
noBaseline,
|
|
2192
|
+
note: [
|
|
2193
|
+
prevDate ? null : '还没有上一数据日:无基准,不报 0',
|
|
2194
|
+
excluded.length ? excluded.length + ' 个榜不参与变化(内容隔离或新期不可比)' : null,
|
|
2195
|
+
noBaseline.length ? noBaseline.length + ' 个榜没有可比基准(缺更早的可信快照)' : null,
|
|
2196
|
+
].filter(Boolean).join(';') || null,
|
|
1873
2197
|
};
|
|
1874
2198
|
}
|
|
1875
2199
|
/** webServer 服务是可选依赖:用依赖光纤做晚绑定(直取 ctx.webServer 在运行时拿不到 —— T12 验收实测 404) */
|
|
@@ -1910,6 +2234,7 @@ export function apply(ctx, config) {
|
|
|
1910
2234
|
for (const [id, meta] of Object.entries(SFACG_BOARDS))
|
|
1911
2235
|
push('sfacg', '菠萝包', '榜单', id, meta.name);
|
|
1912
2236
|
return {
|
|
2237
|
+
defaultCaptures: defaultState().boards,
|
|
1913
2238
|
boards: rows, captures: st.boards, displays: st.display, depths: st.depths || {}, autoEnrich: st.autoEnrich !== false,
|
|
1914
2239
|
// 起点书页补全:开关状态 + 缓存规模(面板据此显示「已缓存 N 本 / 截止时间」)
|
|
1915
2240
|
qidian: { enrich: st.qidianEnrich === true, cache: cacheStats(root), ttlDays: Math.round(QIDIAN_CACHE_TTL_MS / 86400000) },
|
|
@@ -3206,6 +3531,8 @@ export function apply(ctx, config) {
|
|
|
3206
3531
|
if (body.save) {
|
|
3207
3532
|
const store3 = new FileStore(root);
|
|
3208
3533
|
await store3.writeSnapshot({ boardId, dataDate: date, metric: res.metric || 'value', rows: res.rows });
|
|
3534
|
+
// ★ 工作包 A:手工补数成功 ⇒ 解除隔离标记并同步当天逐榜状态
|
|
3535
|
+
await trustBoardDay(date, boardId, new Date().toISOString());
|
|
3209
3536
|
}
|
|
3210
3537
|
return send(200, {
|
|
3211
3538
|
ok: true, boardId, date, saved: !!body.save, contentDate: verdict.contentDate, expected: verdict.expected,
|
|
@@ -3253,6 +3580,8 @@ export function apply(ctx, config) {
|
|
|
3253
3580
|
const contentDate = verdictR.contentDate;
|
|
3254
3581
|
const store2 = new FileStore(root);
|
|
3255
3582
|
await store2.writeSnapshot({ boardId: b, dataDate: date, metric: res.metric || 'value', rows: res.rows });
|
|
3583
|
+
// ★ 工作包 A:修数成功 ⇒ 解除隔离、同步逐榜状态
|
|
3584
|
+
await trustBoardDay(date, b, new Date().toISOString());
|
|
3256
3585
|
// 同步当天 scan.json 的记录,保持「快照 = 记录」
|
|
3257
3586
|
const rec2 = await store2.readScan(date);
|
|
3258
3587
|
if (rec2) {
|
|
@@ -3378,7 +3707,7 @@ export function apply(ctx, config) {
|
|
|
3378
3707
|
if (!got.ok)
|
|
3379
3708
|
return send(409, { error: '已有扫描在进行中,请等它跑完' });
|
|
3380
3709
|
const rec2 = got.value;
|
|
3381
|
-
return send(200, { ok: true, outcome: rec2.outcome, dataDate: rec2.dataDate, attempt: rec2.attempt, progress: rec2.progress });
|
|
3710
|
+
return send(200, { ok: true, outcome: rec2.outcome, dataDate: rec2.dataDate, attempt: rec2.attempt, progress: rec2.progress, revision: dataRevision(rec2.dataDate) });
|
|
3382
3711
|
}
|
|
3383
3712
|
if (p === '/api/rank-scan/scan') {
|
|
3384
3713
|
if (String(req.method || 'GET').toUpperCase() !== 'POST')
|
|
@@ -3412,9 +3741,22 @@ export function apply(ctx, config) {
|
|
|
3412
3741
|
return send(409, { error: '已有扫描在进行中(定时或另一个手动扫描),请等它跑完' });
|
|
3413
3742
|
const rec = got.value;
|
|
3414
3743
|
const stR = readState();
|
|
3744
|
+
const dayAfter = new FileStore(root).readDayIndex(rec.dataDate);
|
|
3415
3745
|
return send(200, {
|
|
3416
3746
|
ok: true, outcome: rec.outcome, dataDate: rec.dataDate, attempt: rec.attempt, progress: rec.progress,
|
|
3417
3747
|
scannedAll: !bsel,
|
|
3748
|
+
/** ★ 工作包 A:同日 revision(前端据此重新取 overview/board/changes) */
|
|
3749
|
+
revision: dataRevision(rec.dataDate),
|
|
3750
|
+
/** 当天**逐榜**最终状态(不是本批)——A 站失败不会被 B 站成功冲掉 */
|
|
3751
|
+
day: dayAfter
|
|
3752
|
+
? Object.keys(dayAfter.boards).map((k) => ({
|
|
3753
|
+
boardId: k,
|
|
3754
|
+
status: dayAfter.boards[k].status,
|
|
3755
|
+
reason: dayAfter.boards[k].reason,
|
|
3756
|
+
trusted: dayAfter.boards[k].trusted !== false,
|
|
3757
|
+
samePeriod: dayAfter.boards[k].samePeriod === true,
|
|
3758
|
+
}))
|
|
3759
|
+
: null,
|
|
3418
3760
|
enrich: stR.enrichRun ? { ...stR.enrichRun, active: timerState.enrichWorker } : null,
|
|
3419
3761
|
enrichPending: Object.keys((stR.enrichPending) || {}).length,
|
|
3420
3762
|
boards: (rec.boards || []).map((b) => ({ boardId: b.boardId, status: b.status, rows: (b.rows || []).length })),
|