dsh-rank-scan 0.2.4 → 0.3.1
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 +23 -13
- package/lib/client.js +1794 -730
- package/lib/index.js +630 -123
- 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 +93 -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/scan/view.js +64 -2
- package/lib/scan/view.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 +74 -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 +29 -0
- package/lib/types/scan/view.d.ts +18 -0
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -21,12 +21,13 @@ import { FANQIE_MALE } from './sites/fanqie.js';
|
|
|
21
21
|
import { CATEGORIES as QIDIAN_CATEGORIES } from './sites/qidian-mobile.js';
|
|
22
22
|
import { deriveFanqieViews } from './scan/derive.js';
|
|
23
23
|
import { decodePua, hasPua, learnPair, loadFontMap, saveFontMap } from './scan/fontmap.js';
|
|
24
|
-
import { applyColumnPolicy, boardMeta, columnsFor, compareDesc, defaultSortFor, enrichAttemptPolicy, enrichMissingCount, groupBySite, groupChanges, isEnrichableBoard, shouldShowDays, usesRankDelta, withFanqieCat } from './scan/view.js';
|
|
25
|
-
import { looksSwapped } from './scan/judges.js';
|
|
24
|
+
import { applyColumnPolicy, batchKeyOf, batchKindOf, batchLabelOf, boardMeta, columnsFor, compareDesc, defaultSortFor, enrichAttemptPolicy, enrichMissingCount, groupBySite, groupChanges, isBatchBoard, isEnrichableBoard, saleRangeOf, shouldShowDays, usesRankDelta, withFanqieCat } from './scan/view.js';
|
|
26
25
|
import { BookmarkService, BookmarkStore } from './scan/bookmark.js';
|
|
27
26
|
import { parseBookInput } from './scan/bookmark-parse.js';
|
|
28
27
|
import { decodeIfPua } from './scan/fontmap.js';
|
|
29
|
-
import { computeBoardDiff, daysOnBoard, guardCrossPeriod } from './scan/diff.js';
|
|
28
|
+
import { addDays, computeBoardDiff, daysOnBoard, guardCrossPeriod, jitterForBoard } from './scan/diff.js';
|
|
29
|
+
import { boardDayState, mergeDayIndex, mergeSlimBoards, previousTrustedDate, revisionDigest } from './scan/daily.js';
|
|
30
|
+
import { judgeFreshness, judgeSwap, periodKeyFromRows } from './scan/freshness.js';
|
|
30
31
|
import { boundedFetch } from './scan/bounded-fetch.js';
|
|
31
32
|
import { minRequestIntervalMs, setMinRequestIntervalMs as applyRequestInterval } from './scan/rate-limit.js';
|
|
32
33
|
/**
|
|
@@ -37,7 +38,7 @@ import { minRequestIntervalMs, setMinRequestIntervalMs as applyRequestInterval }
|
|
|
37
38
|
* 纪律:本插件**不实现安装与重启**,只转发 dsh-market 的公开更新 API(桌面/被监管宿主由它裁决)。
|
|
38
39
|
*/
|
|
39
40
|
import { readOwnVersion, probeMarket, fetchNpmLatest, normalizeOperation, buildUpdateView } from './scan/update.js';
|
|
40
|
-
import { assertDataDate,
|
|
41
|
+
import { assertDataDate, dirSize, historyFor, listDataDates, listSlim, normalizeRetention, previousDataDate, readSlim, runRetention, sweepTmp, writeReport, writeSlim, } from './scan/files.js';
|
|
41
42
|
import { DEFAULT_FALLBACK_TIME, DEFAULT_SITE_TIMES, hmOf, planSiteRuns, SITE_ORDER, siteOfBoard, validTime } from './scan/schedule.js';
|
|
42
43
|
import { cacheStats, cachedBook, clearCache, putCachedBooks } from './scan/qidian-cache.js';
|
|
43
44
|
import { assignCachedStats, cacheStats as bookCacheStats, cachedEntry, putEntries } from './scan/book-cache.js';
|
|
@@ -361,103 +362,185 @@ export function apply(ctx, config) {
|
|
|
361
362
|
}
|
|
362
363
|
return done;
|
|
363
364
|
}
|
|
365
|
+
/**
|
|
366
|
+
* ★ Spec E(2026-10-24):**运行中那一轮**的扫描记录(只放内存,不落盘)。
|
|
367
|
+
* 落盘 scan.json 只在整轮结束时写一次 ⇒ 旧实现里 overview 在扫描过程中永远读到「上一轮的 completed」,
|
|
368
|
+
* 面板看不到 0/N → 1/N 的真实进度,定时扫描期间连「正在跑」都不知道。
|
|
369
|
+
* onProgress 每完成一个榜就把最新记录放进来;doScan 的 finally 立刻清空 ⇒ 不会残留假 running。
|
|
370
|
+
*/
|
|
371
|
+
let activeScan = null;
|
|
364
372
|
async function doScan(trigger, opts) {
|
|
365
373
|
const st = readState();
|
|
366
374
|
const store = new FileStore(root);
|
|
367
375
|
const effectiveBoards = opts && opts.boards
|
|
368
376
|
? String(opts.boards).split(',').map((x) => x.trim()).filter(Boolean)
|
|
369
377
|
: st.boards;
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
378
|
+
let rec;
|
|
379
|
+
try {
|
|
380
|
+
rec = await runScan({
|
|
381
|
+
/**
|
|
382
|
+
* ★ Spec E:走 serveSiteFor(与 /day、/repair 同一条测试 seam)。
|
|
383
|
+
* 生产没有 cfg.sitesFactory 时原样回退 sitesFor,行为不变;
|
|
384
|
+
* 有了它,单测才能用「可控延迟的隔离站点」验证 overview 在扫描中途读到真实进度。
|
|
385
|
+
*/
|
|
386
|
+
sites: serveSiteFor(effectiveBoards, st.depths || {}),
|
|
387
|
+
clock,
|
|
388
|
+
store,
|
|
389
|
+
trigger,
|
|
390
|
+
boards: effectiveBoards,
|
|
391
|
+
enrich: !!(opts && opts.enrich),
|
|
392
|
+
retryNonOk: !!(opts && opts.retry),
|
|
393
|
+
/** ★ 工作包 A:记录本批的范围(scan.json 是批次记录;当天状态在 day-index) */
|
|
394
|
+
partial: !!(opts && opts.partial),
|
|
395
|
+
batchSite: opts && opts.site ? String(opts.site) : null,
|
|
396
|
+
betweenBoardsMs: 500,
|
|
397
|
+
budget: { maxRequests: st.maxRequests || 600 },
|
|
398
|
+
/** 只更新内存活跃记录;观察者抛错由 runScan 兜住,不会中断扫描 */
|
|
399
|
+
onProgress: (r) => { activeScan = r; },
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
finally {
|
|
403
|
+
// 成功/取消/抛错都必须清:残留会让面板一直显示「扫描中」并按运行态高频轮询
|
|
404
|
+
activeScan = null;
|
|
405
|
+
}
|
|
381
406
|
/**
|
|
382
407
|
* ★ 2026-10-16(按站分时):一次「部分扫描」(只跑一个站)**不能覆盖当天的全量产物**:
|
|
383
408
|
* 精简索引/报告按 `<日期>-<站>` 落盘,全量扫的那份照旧叫 `<日期>`,两边都不丢。
|
|
384
409
|
*/
|
|
385
410
|
const artId = opts && opts.partial && opts.site ? rec.dataDate + '-' + String(opts.site) : rec.dataDate;
|
|
386
411
|
/**
|
|
387
|
-
* ★ 2026-10-
|
|
388
|
-
*
|
|
389
|
-
*
|
|
412
|
+
* ★ 工作包 A(2026-10-22):**唯一的新鲜度/可信度判定点**,取代原来互不相干的两段
|
|
413
|
+
* (①「与上一数据日 key=value 全等 ⇒ 疑似未刷新」② 刺猬猫「交集 ≤2 ⇒ 换榜」)。三个动机:
|
|
414
|
+
* ① 名次榜 value 恒为 null ⇒ 旧签名退化成书号列表,细节数字(收藏/字数)不参与;
|
|
415
|
+
* ② 周期榜同一期本来就不变(刺猬猫首订约 issue 478 连两天)⇒ 误判陈旧并触发**整站**兜底补抓;
|
|
416
|
+
* ③ 判定只改内存记录 ⇒ 被拒的快照仍在展示/变化/书签里(体检 P1-C)。
|
|
417
|
+
* 现在:逐榜向前找**上一次可信成功**(跨过缺日),按榜的更新节奏(日/周/期)判定;
|
|
418
|
+
* 命中 ⇒ 打 <date>/<boardId>.untrusted.json(raw 保留、只隔离使用)+ 记进 day-index。
|
|
390
419
|
*/
|
|
420
|
+
const batchIds = new Set(rec.batch?.boards || rec.boards.map((b) => b.boardId));
|
|
421
|
+
const batchBoards = rec.boards.filter((b) => batchIds.has(b.boardId));
|
|
422
|
+
const samePeriodBoards = new Set();
|
|
391
423
|
try {
|
|
392
|
-
const
|
|
424
|
+
const flagged = {};
|
|
393
425
|
const stS = readState();
|
|
394
426
|
const flags = { ...(stS.staleFlag || {}) };
|
|
395
|
-
for (const b of
|
|
427
|
+
for (const b of batchBoards) {
|
|
396
428
|
if (b.status !== 'ok')
|
|
397
429
|
continue;
|
|
398
430
|
const nx = store.readSnapshot(rec.dataDate, b.boardId);
|
|
431
|
+
if (!nx || !(nx.rows || []).length)
|
|
432
|
+
continue;
|
|
433
|
+
const prevD = previousBoardDate(b.boardId, rec.dataDate);
|
|
399
434
|
const pd = prevD ? store.readSnapshot(prevD, b.boardId) : null;
|
|
400
|
-
|
|
435
|
+
const verdict = judgeFreshness({
|
|
436
|
+
boardId: b.boardId,
|
|
437
|
+
date: rec.dataDate,
|
|
438
|
+
prevDate: prevD,
|
|
439
|
+
currentRows: nx.rows || [],
|
|
440
|
+
previousRows: pd ? (pd.rows || []) : null,
|
|
441
|
+
currentPeriodKey: periodKeyFromRows(nx.rows || []),
|
|
442
|
+
previousPeriodKey: pd ? periodKeyFromRows(pd.rows || []) : null,
|
|
443
|
+
});
|
|
444
|
+
/**
|
|
445
|
+
* ★ 2026-10-25(换期 ≠ 换榜/降级):换榜判据必须先问「是不是同一期」。
|
|
446
|
+
* 刺猬猫首订每周整批换新(交集 0),旧判据把它当换榜/降级隔离 ⇒ 整榜长期不可见。
|
|
447
|
+
* 现在跨期一律不判换榜(见 freshness.ts#judgeSwap)。
|
|
448
|
+
*/
|
|
449
|
+
const swap = b.boardId.startsWith('ciweimao.')
|
|
450
|
+
? judgeSwap({ boardId: b.boardId, date: rec.dataDate, prevDate: prevD, currentRows: nx.rows || [], previousRows: pd ? (pd.rows || []) : null })
|
|
451
|
+
: { swapped: false, samePeriod: null, reason: null };
|
|
452
|
+
if (swap.swapped || verdict.verdict === 'suspected') {
|
|
453
|
+
/**
|
|
454
|
+
* ★ 2026-10-25(防永久锁安全阀):基准只取「上次可信」⇒ 一旦某天判错,之后每天
|
|
455
|
+
* 都拿同一份旧内容重判,永远不自愈(实测 10-24 起两天)。连续 3 个数据日都判
|
|
456
|
+
* 不可信时,接受本次内容但**写明请人工核对**——宁可带警告显示,也不让整榜消失。
|
|
457
|
+
*/
|
|
458
|
+
const priorDays = consecutiveUntrustedDays(b.boardId, rec.dataDate);
|
|
459
|
+
if (priorDays >= 3) {
|
|
460
|
+
try {
|
|
461
|
+
store.clearUntrusted(rec.dataDate, b.boardId);
|
|
462
|
+
}
|
|
463
|
+
catch { /* 清标记失败不影响结果 */ }
|
|
464
|
+
b.acceptedAfterRepeat = true;
|
|
465
|
+
b.reason = '连续 ' + priorDays + ' 天判不可信,已接受本次内容(请人工核对)';
|
|
466
|
+
rec.warnings.push(b.boardId + ':' + b.reason);
|
|
467
|
+
delete flags[b.boardId];
|
|
468
|
+
}
|
|
469
|
+
else {
|
|
470
|
+
const reason = swap.swapped
|
|
471
|
+
? '疑似换榜/降级(同一期内与上次有效快照交集 ≤2)'
|
|
472
|
+
: String(verdict.reason || '疑似未刷新');
|
|
473
|
+
try {
|
|
474
|
+
store.markUntrusted(rec.dataDate, b.boardId, { reason, at: new Date().toISOString(), by: trigger });
|
|
475
|
+
}
|
|
476
|
+
catch { /* 标记失败仍按记录处理 */ }
|
|
477
|
+
b.status = 'stale';
|
|
478
|
+
b.untrusted = true;
|
|
479
|
+
b.reason = reason;
|
|
480
|
+
b.rows = [];
|
|
481
|
+
delete flags[b.boardId];
|
|
482
|
+
if (!swap.swapped)
|
|
483
|
+
flagged[b.boardId] = { date: rec.dataDate, prevDate: prevD, suspected: true };
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
else {
|
|
487
|
+
try {
|
|
488
|
+
store.clearUntrusted(rec.dataDate, b.boardId);
|
|
489
|
+
}
|
|
490
|
+
catch { /* 清标记失败不影响结果 */ }
|
|
401
491
|
delete flags[b.boardId];
|
|
492
|
+
if (verdict.samePeriod) {
|
|
493
|
+
b.samePeriod = true;
|
|
494
|
+
samePeriodBoards.add(b.boardId);
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
/**
|
|
499
|
+
* 适配器自己抛 StaleError 的榜(例如菠萝包判据)同样是「抓到但不可信」:
|
|
500
|
+
* 若当天目录里残留了更早的快照(同日先成功后判 stale),必须一并隔离,不能让它继续被展示。
|
|
501
|
+
*/
|
|
502
|
+
for (const b of batchBoards) {
|
|
503
|
+
if (b.status !== 'stale' || b.untrusted === true)
|
|
402
504
|
continue;
|
|
505
|
+
b.untrusted = true;
|
|
506
|
+
try {
|
|
507
|
+
store.markUntrusted(rec.dataDate, b.boardId, { reason: String(b.reason || '适配器判为不可信'), at: new Date().toISOString(), by: trigger });
|
|
403
508
|
}
|
|
404
|
-
|
|
405
|
-
const a = (nx.rows || []).map(sig).join('|');
|
|
406
|
-
const c = (pd.rows || []).map(sig).join('|');
|
|
407
|
-
if (a && a === c)
|
|
408
|
-
flags[b.boardId] = { date: rec.dataDate, prevDate: prevD, suspected: true };
|
|
409
|
-
else
|
|
410
|
-
delete flags[b.boardId];
|
|
509
|
+
catch { /* 标记失败仍按记录处理 */ }
|
|
411
510
|
}
|
|
511
|
+
// ★ 只把**真正可疑**的榜交回给兜底队列;「同一期未变化」不进 staleFlag(不再误触整站补抓)
|
|
512
|
+
Object.assign(flags, flagged);
|
|
412
513
|
stS.staleFlag = flags;
|
|
413
514
|
writeState(stS);
|
|
414
|
-
const suspectBoards = Object.keys(
|
|
515
|
+
const suspectBoards = Object.keys(flagged);
|
|
415
516
|
if (suspectBoards.length)
|
|
416
|
-
rec.warnings.push('
|
|
517
|
+
rec.warnings.push('以下榜的内容不可信(原始快照已保留,本次不展示、不参与变化):' + suspectBoards.join('、'));
|
|
518
|
+
if (samePeriodBoards.size)
|
|
519
|
+
rec.warnings.push('同一期未变化(正常,不判陈旧):' + Array.from(samePeriodBoards).join('、'));
|
|
520
|
+
}
|
|
521
|
+
catch (e) {
|
|
522
|
+
rec.warnings.push('新鲜度判定失败(不影响抓取):' + String(e).slice(0, 60));
|
|
417
523
|
}
|
|
418
|
-
catch { /* 自检失败不该挡住扫描 */ }
|
|
419
524
|
// 每个榜的「上次扫描」落进 state(部分扫描时 scan.json 只留最后一次 ⇒ 面板要能逐榜查)
|
|
420
525
|
try {
|
|
421
526
|
const stB = readState();
|
|
422
527
|
const bls = { ...(stB.boardLastScan || {}) };
|
|
423
|
-
for (const b of
|
|
528
|
+
for (const b of batchBoards)
|
|
424
529
|
bls[b.boardId] = { date: rec.dataDate, at: new Date().toISOString(), outcome: String(b.status), by: trigger };
|
|
425
530
|
stB.boardLastScan = bls;
|
|
426
531
|
writeState(stB);
|
|
427
532
|
}
|
|
428
533
|
catch { /* 记不上不该影响扫描结果 */ }
|
|
429
534
|
const snaps = new Map();
|
|
430
|
-
for (const b of
|
|
535
|
+
for (const b of batchBoards) {
|
|
431
536
|
if (b.status !== 'ok')
|
|
432
537
|
continue;
|
|
433
538
|
const s = store.readSnapshot(rec.dataDate, b.boardId);
|
|
434
539
|
if (s)
|
|
435
540
|
snaps.set(b.boardId, s);
|
|
436
541
|
}
|
|
437
|
-
//
|
|
542
|
+
// 派生榜不进扫描:如实说一句(否则以后看 scan.json 会以为「漏抓了一个榜」)
|
|
438
543
|
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
544
|
const derivedInCapture = (st.boards || []).filter((b) => b.startsWith('fanqie.derived.'));
|
|
462
545
|
if (derivedInCapture.length) {
|
|
463
546
|
rec.warnings.push('派生榜不进扫描(本地按快照计算,0 请求):' + derivedInCapture.join('、'));
|
|
@@ -465,17 +548,62 @@ export function apply(ctx, config) {
|
|
|
465
548
|
}
|
|
466
549
|
}
|
|
467
550
|
catch (e) {
|
|
468
|
-
rec.warnings.push('
|
|
551
|
+
rec.warnings.push('派生榜说明写入失败:' + String(e).slice(0, 50));
|
|
469
552
|
}
|
|
553
|
+
/**
|
|
554
|
+
* ★ 工作包 A:写「精简索引 + 报告」的唯一入口 —— **按日逐榜合并**。
|
|
555
|
+
* 旧实现 `buildSlim(rec, snaps)` 把整份文件换成「本批跑过的榜」:单榜重抓之后,
|
|
556
|
+
* 当天其余榜从 slim 里消失 ⇒ 之后 historyFor 判「新入榜/回榜」会把回榜算成新入榜(体检 P1-A ②)。
|
|
557
|
+
*/
|
|
558
|
+
const writeArtifacts = () => {
|
|
559
|
+
try {
|
|
560
|
+
const prevSlim = readSlim(root, artId);
|
|
561
|
+
const incoming = {};
|
|
562
|
+
const drop = [];
|
|
563
|
+
for (const b of batchBoards) {
|
|
564
|
+
if (b.untrusted === true) {
|
|
565
|
+
drop.push(b.boardId);
|
|
566
|
+
continue;
|
|
567
|
+
}
|
|
568
|
+
if (b.status !== 'ok')
|
|
569
|
+
continue;
|
|
570
|
+
const snap = snaps.get(b.boardId);
|
|
571
|
+
if (!snap || !(snap.rows || []).length)
|
|
572
|
+
continue;
|
|
573
|
+
incoming[b.boardId] = (snap.rows || []).map((r) => ({ key: r.key, rank: r.rank, metric: r.value }));
|
|
574
|
+
}
|
|
575
|
+
writeSlim(root, mergeSlimBoards(prevSlim, artId, incoming, drop));
|
|
576
|
+
writeReport(root, artId, renderReport(rec, root));
|
|
577
|
+
}
|
|
578
|
+
catch (e) {
|
|
579
|
+
rec.warnings.push('精简索引/报告写入失败:' + String(e).slice(0, 60));
|
|
580
|
+
}
|
|
581
|
+
};
|
|
582
|
+
writeArtifacts();
|
|
583
|
+
/**
|
|
584
|
+
* ★ 工作包 A:当天**逐榜**状态(批次记录 scan.json 只代表本批)。
|
|
585
|
+
* 只更新本批真正跑过的榜;A 站失败不会被之后 B 站成功冲掉。
|
|
586
|
+
*/
|
|
470
587
|
try {
|
|
471
|
-
const
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
588
|
+
const idxPrev = store.readDayIndex(rec.dataDate);
|
|
589
|
+
const updates = rec.boards
|
|
590
|
+
.filter((b) => batchIds.has(b.boardId))
|
|
591
|
+
.map((b) => ({
|
|
592
|
+
boardId: b.boardId,
|
|
593
|
+
status: b.status,
|
|
594
|
+
reason: b.reason ?? null,
|
|
595
|
+
rows: b.untrusted === true ? 0 : (b.rows || []).length,
|
|
596
|
+
trusted: b.untrusted !== true,
|
|
597
|
+
at: b.capturedAt || rec.finishedAt || rec.startedAt,
|
|
598
|
+
by: trigger,
|
|
599
|
+
capturedAt: b.capturedAt ?? null,
|
|
600
|
+
contentDate: b.contentDate ?? null,
|
|
601
|
+
samePeriod: b.samePeriod === true,
|
|
602
|
+
}));
|
|
603
|
+
await store.writeDayIndex(mergeDayIndex(idxPrev, rec.dataDate, updates, new Date().toISOString()));
|
|
476
604
|
}
|
|
477
605
|
catch (e) {
|
|
478
|
-
rec.warnings.push('
|
|
606
|
+
rec.warnings.push('逐榜状态索引写入失败:' + String(e).slice(0, 60));
|
|
479
607
|
}
|
|
480
608
|
/**
|
|
481
609
|
* ★ 2026-10-17(补全移出阻塞路径):把补全**从 /scan 的等待里摘出去**。
|
|
@@ -489,7 +617,7 @@ export function apply(ctx, config) {
|
|
|
489
617
|
* 同步通道(postScanEnrich)第一行就是「关了就直接返回」,defer 分支以前不看 ⇒ 用户关掉自动补全照样跑。
|
|
490
618
|
*/
|
|
491
619
|
if (opts && opts.deferEnrich && readState().autoEnrich !== false) {
|
|
492
|
-
const only = opts.partial ?
|
|
620
|
+
const only = opts.partial ? batchBoards.filter((b) => b.untrusted !== true).map((b) => b.boardId) : undefined;
|
|
493
621
|
/**
|
|
494
622
|
* ★ 2026-10-17(审查续核 ①):起点/起点图另有「起点收藏与三江字数」开关(qidianEnrich)。
|
|
495
623
|
* 同步通道在 postScanEnrich 里判过它;而 defer 路径的 worker 直接调 enrichBoard → qidianEnrichBoard,
|
|
@@ -507,14 +635,7 @@ export function apply(ctx, config) {
|
|
|
507
635
|
const queued = Object.keys((readState().enrichPending) || {}).length;
|
|
508
636
|
rec.warnings.push('补全已转入后台:' + queued + ' 个榜待补(抓榜数据已可用;面板顶部显示进度)');
|
|
509
637
|
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 { /* 索引写失败不影响扫描结果 */ }
|
|
638
|
+
writeArtifacts();
|
|
518
639
|
startEnrichWorker('扫描后后台补全');
|
|
519
640
|
/**
|
|
520
641
|
* ★ 关键:不再跑 postScanEnrich(同步阻塞那 5 分钟)。
|
|
@@ -526,7 +647,7 @@ export function apply(ctx, config) {
|
|
|
526
647
|
// 整站扫描后补全「站上不给」的字数/收藏(刺猬猫 2 + 菠萝包 3;单榜扫描不跑)
|
|
527
648
|
if (opts && opts.enrichAfter && !opts.deferEnrich) {
|
|
528
649
|
try {
|
|
529
|
-
const res = await postScanEnrich(opts && opts.partial ?
|
|
650
|
+
const res = await postScanEnrich(opts && opts.partial ? batchBoards.filter((b) => b.untrusted !== true).map((b) => b.boardId) : undefined);
|
|
530
651
|
if (res && res.length) {
|
|
531
652
|
const total = res.reduce((n, x) => n + (x.requests || 0), 0);
|
|
532
653
|
/**
|
|
@@ -538,11 +659,7 @@ export function apply(ctx, config) {
|
|
|
538
659
|
const pendingN = res.filter((x) => still[x.boardId]).length;
|
|
539
660
|
rec.warnings.push('补全:' + res.length + ' 个榜跑了补全(' + total + ' 请求)' + (pendingN ? ';其中 ' + pendingN + ' 个仍缺字段,已记待办由定时续跑或在面板点「补齐本榜」' : ''));
|
|
540
661
|
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));
|
|
662
|
+
writeArtifacts();
|
|
546
663
|
}
|
|
547
664
|
}
|
|
548
665
|
catch (e) {
|
|
@@ -814,7 +931,7 @@ export function apply(ctx, config) {
|
|
|
814
931
|
*
|
|
815
932
|
* 为什么需要它:跑失败也会写 siteLastRun=today(防 30 秒一次无脑重试),于是 due 永远不会再排它,
|
|
816
933
|
* 而旧兜底分支只认「疑似未刷新」⇒ 一次失败 = 当天彻底没了。现在这类站进兜底队列,22:30 再试一次。
|
|
817
|
-
*
|
|
934
|
+
* 判据:该站实际抓取集内任一榜没有「计划时刻之后」的成功抓取(本地派生榜除外)。
|
|
818
935
|
*/
|
|
819
936
|
function sitesFailedToday(sites, today, siteTimes) {
|
|
820
937
|
const st = readState();
|
|
@@ -826,16 +943,11 @@ export function apply(ctx, config) {
|
|
|
826
943
|
continue;
|
|
827
944
|
const plan = times[s] || DEFAULT_SITE_TIMES[s] || DEFAULT_FALLBACK_TIME;
|
|
828
945
|
const bs = (st.boards || []).filter((b) => siteOfBoard(b) === s);
|
|
829
|
-
|
|
830
|
-
for (const b of bs) {
|
|
946
|
+
const incomplete = bs.filter((b) => !b.startsWith('fanqie.derived.')).some((b) => {
|
|
831
947
|
const hit = bls[b];
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
if (!latest || hm > latest)
|
|
836
|
-
latest = hm;
|
|
837
|
-
}
|
|
838
|
-
if (!latest || latest < plan)
|
|
948
|
+
return !hit || hit.date !== today || hit.outcome !== 'ok' || hmOf(new Date(String(hit.at))) < plan;
|
|
949
|
+
});
|
|
950
|
+
if (incomplete)
|
|
839
951
|
out.push(s);
|
|
840
952
|
}
|
|
841
953
|
return out;
|
|
@@ -855,6 +967,8 @@ export function apply(ctx, config) {
|
|
|
855
967
|
fallbackTime: st.fallbackTime || DEFAULT_FALLBACK_TIME,
|
|
856
968
|
ranToday: sitesRanToday(sites, localDate(new Date()), st.siteTimes || DEFAULT_SITE_TIMES),
|
|
857
969
|
failed: sitesFailedToday(sites, localDate(new Date()), st.siteTimes || DEFAULT_SITE_TIMES),
|
|
970
|
+
retried: st.siteRetry || {},
|
|
971
|
+
stale: SITE_ORDER.filter((s) => Object.keys(st.staleFlag || {}).some((b) => siteOfBoard(b) === s && st.staleFlag[b]?.date === localDate(new Date()))),
|
|
858
972
|
});
|
|
859
973
|
/**
|
|
860
974
|
* ★ 2026-10-16(疑问「关闭状态为什么显示今天已跑」):把「这个站今天抓过没、谁抓的、几点抓的」
|
|
@@ -1084,6 +1198,107 @@ export function apply(ctx, config) {
|
|
|
1084
1198
|
const rec = await st.readScan(date);
|
|
1085
1199
|
return rec ? rec.boards.map((b) => b.boardId) : [];
|
|
1086
1200
|
}
|
|
1201
|
+
/**
|
|
1202
|
+
* ★ 工作包 A(2026-10-22):当天逐榜状态索引 + 可信度 + 数据 revision。
|
|
1203
|
+
* 三者都以「这一次请求要展示的数据日期」为键读取,缺文件时回退老口径(不报错)。
|
|
1204
|
+
*/
|
|
1205
|
+
function dayIndexOf(date) {
|
|
1206
|
+
if (!date)
|
|
1207
|
+
return null;
|
|
1208
|
+
try {
|
|
1209
|
+
return new FileStore(root).readDayIndex(date);
|
|
1210
|
+
}
|
|
1211
|
+
catch {
|
|
1212
|
+
return null;
|
|
1213
|
+
}
|
|
1214
|
+
}
|
|
1215
|
+
/** 这一天的这份快照是否被拒(stale 隔离;raw 仍在盘上) */
|
|
1216
|
+
function isUntrusted(date, boardId) {
|
|
1217
|
+
try {
|
|
1218
|
+
return new FileStore(root).isUntrusted(date, boardId);
|
|
1219
|
+
}
|
|
1220
|
+
catch {
|
|
1221
|
+
return false;
|
|
1222
|
+
}
|
|
1223
|
+
}
|
|
1224
|
+
/**
|
|
1225
|
+
* ★ 工作包 A:**该榜自己的上一次可信成功数据日**(跨过缺日、跨过被拒快照)。
|
|
1226
|
+
* 旧口径只看「全局上一数据日期」:该榜那天没跑成功就判「首次采集」⇒ 变化整列空、
|
|
1227
|
+
* 概览涨/新/退为 null(体检 P1-B:三江 10-18 缺一天,10-19 被误判 firstEver)。
|
|
1228
|
+
*/
|
|
1229
|
+
function previousBoardDate(boardId, date, dates) {
|
|
1230
|
+
const st = new FileStore(root);
|
|
1231
|
+
return previousTrustedDate(dates || listDataDates(root), date, (d) => st.readSnapshot(d, boardId), (d) => st.isUntrusted(d, boardId));
|
|
1232
|
+
}
|
|
1233
|
+
/**
|
|
1234
|
+
* ★ 2026-10-25(防永久锁):从 date 往前数,**连续**多少个数据日被判不可信。
|
|
1235
|
+
* 基准只取可信快照 ⇒ 判错一次就会一直拿同一份旧内容重判;连续 3 天时由扫描侧放行(见 doScan)。
|
|
1236
|
+
*/
|
|
1237
|
+
function consecutiveUntrustedDays(boardId, date) {
|
|
1238
|
+
const st = new FileStore(root);
|
|
1239
|
+
const ds = listDataDates(root);
|
|
1240
|
+
let n = 0;
|
|
1241
|
+
for (let i = ds.length - 1; i >= 0; i--) {
|
|
1242
|
+
const d = ds[i];
|
|
1243
|
+
if (d >= date)
|
|
1244
|
+
continue;
|
|
1245
|
+
if (!st.readSnapshot(d, boardId))
|
|
1246
|
+
break;
|
|
1247
|
+
if (!st.isUntrusted(d, boardId))
|
|
1248
|
+
break;
|
|
1249
|
+
n += 1;
|
|
1250
|
+
}
|
|
1251
|
+
return n;
|
|
1252
|
+
}
|
|
1253
|
+
/**
|
|
1254
|
+
* ★ 工作包 A:手工补数(/day 落盘、/repair)之后把「这一榜这一天」恢复为可信,
|
|
1255
|
+
* 并同步当天逐榜索引 —— 否则隔离标记会一直挂着,展示端永远不给看。
|
|
1256
|
+
*/
|
|
1257
|
+
async function trustBoardDay(date, boardId, at) {
|
|
1258
|
+
const store = new FileStore(root);
|
|
1259
|
+
try {
|
|
1260
|
+
store.clearUntrusted(date, boardId);
|
|
1261
|
+
}
|
|
1262
|
+
catch { /* 清标记失败不影响补数结果 */ }
|
|
1263
|
+
const snap = store.readSnapshot(date, boardId);
|
|
1264
|
+
const rows = snap && Array.isArray(snap.rows) ? snap.rows.length : 0;
|
|
1265
|
+
const idxPrev = store.readDayIndex(date);
|
|
1266
|
+
const updates = [{
|
|
1267
|
+
boardId, status: 'ok', reason: null, rows, trusted: true, at, by: 'manual', capturedAt: at, contentDate: null,
|
|
1268
|
+
}];
|
|
1269
|
+
await store.writeDayIndex(mergeDayIndex(idxPrev, date, updates, at));
|
|
1270
|
+
if (snap)
|
|
1271
|
+
writeSlim(root, mergeSlimBoards(readSlim(root, date), date, {
|
|
1272
|
+
[boardId]: snap.rows.map((r) => ({ key: r.key, rank: r.rank, metric: r.value })),
|
|
1273
|
+
}));
|
|
1274
|
+
}
|
|
1275
|
+
/** 同一数据日期内数据是否变化(前端据此重取;含补全改写的快照) */
|
|
1276
|
+
function dataRevision(date) {
|
|
1277
|
+
if (!date)
|
|
1278
|
+
return null;
|
|
1279
|
+
const store = new FileStore(root);
|
|
1280
|
+
const idx = (() => { try {
|
|
1281
|
+
return store.readDayIndex(date);
|
|
1282
|
+
}
|
|
1283
|
+
catch {
|
|
1284
|
+
return null;
|
|
1285
|
+
} })();
|
|
1286
|
+
let stats = [];
|
|
1287
|
+
let untrusted = [];
|
|
1288
|
+
try {
|
|
1289
|
+
stats = store.snapshotStats(date);
|
|
1290
|
+
}
|
|
1291
|
+
catch {
|
|
1292
|
+
stats = [];
|
|
1293
|
+
}
|
|
1294
|
+
try {
|
|
1295
|
+
untrusted = store.untrustedBoards(date);
|
|
1296
|
+
}
|
|
1297
|
+
catch {
|
|
1298
|
+
untrusted = [];
|
|
1299
|
+
}
|
|
1300
|
+
return revisionDigest(idx ? idx.revision : 0, stats, untrusted);
|
|
1301
|
+
}
|
|
1087
1302
|
function diffFor(boardId, date, prevDate, jitter, slimAll) {
|
|
1088
1303
|
const store = new FileStore(root);
|
|
1089
1304
|
const current = store.readSnapshot(date, boardId);
|
|
@@ -1124,15 +1339,15 @@ export function apply(ctx, config) {
|
|
|
1124
1339
|
// ★ 跨期不可比 ⇒ 调用方必须把变化列判为「不可比」(置空 / 显示「新期」)
|
|
1125
1340
|
crossPeriod: !!d.crossPeriod,
|
|
1126
1341
|
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
|
|
1342
|
+
newEntry: d.newEntry,
|
|
1343
|
+
rebound: d.rebound,
|
|
1344
|
+
up: d.up,
|
|
1345
|
+
down: d.down,
|
|
1131
1346
|
// ★ flat 必须一起回传:面板要按它给「持平」的行标记名次 delta=0。
|
|
1132
1347
|
// 2026-10-15 修:此前 flat 整组丢掉 ⇒ 名次没动/±2 内的行 delta 落 null,
|
|
1133
1348
|
// 「变化」列大面积显示「—」(实测起点 20 行里 18 行是「—」,真实 flat=17)。
|
|
1134
1349
|
flat: d.flat.slice(0, 200),
|
|
1135
|
-
out: d.out
|
|
1350
|
+
out: d.out,
|
|
1136
1351
|
metricDelta: d.metricDelta.slice(0, 20),
|
|
1137
1352
|
};
|
|
1138
1353
|
}
|
|
@@ -1176,8 +1391,16 @@ export function apply(ctx, config) {
|
|
|
1176
1391
|
if (boardId.startsWith('fanqie.derived.'))
|
|
1177
1392
|
return '今日涨幅';
|
|
1178
1393
|
if (meta && meta.metric === 'value') {
|
|
1179
|
-
|
|
1394
|
+
/**
|
|
1395
|
+
* ★ 2026-10-22(工作包 A):三江的主指标是**收藏增量**(value / periodTotal),不是首订。
|
|
1396
|
+
* 旧实现把所有 qidiantu.* 一律叫「首订」⇒ 排序项、书签 metric 全带错标签(体检 P3)。
|
|
1397
|
+
*/
|
|
1398
|
+
if (boardId === 'qidiantu.sanjiang')
|
|
1399
|
+
return '收藏增量';
|
|
1400
|
+
if (boardId === 'qidiantu.shouding')
|
|
1180
1401
|
return '首订';
|
|
1402
|
+
if (boardId.startsWith('qidiantu.'))
|
|
1403
|
+
return '收藏增量';
|
|
1181
1404
|
if (boardId === 'ciweimao.buy.latest')
|
|
1182
1405
|
return '首订(约)';
|
|
1183
1406
|
return '在读';
|
|
@@ -1243,6 +1466,12 @@ export function apply(ctx, config) {
|
|
|
1243
1466
|
let best = null;
|
|
1244
1467
|
for (const date of dates) {
|
|
1245
1468
|
for (const boardId of boards) {
|
|
1469
|
+
/**
|
|
1470
|
+
* ★ 工作包 A:**被拒快照不参与书签自动更新** —— 否则 tab 里会写进一份
|
|
1471
|
+
* 站方还没刷新的旧值,且之后看起来像「今天的数据」。
|
|
1472
|
+
*/
|
|
1473
|
+
if (isUntrusted(date, boardId))
|
|
1474
|
+
continue;
|
|
1246
1475
|
const snap = store.readSnapshot(date, boardId);
|
|
1247
1476
|
if (!snap || !Array.isArray(snap.rows))
|
|
1248
1477
|
continue;
|
|
@@ -1307,15 +1536,35 @@ export function apply(ctx, config) {
|
|
|
1307
1536
|
const { st, dates, latest } = panelCtx();
|
|
1308
1537
|
const store = new FileStore(root);
|
|
1309
1538
|
const rec = latest ? await store.readScan(latest) : null;
|
|
1539
|
+
/** ★ Spec E:本轮正在跑时的内存记录(见 doScan 顶部注释);结束/抛错即清空 */
|
|
1540
|
+
const liveScan = activeScan || null;
|
|
1310
1541
|
const prevDate = latest ? previousDataDate(dates, latest) : null;
|
|
1542
|
+
/**
|
|
1543
|
+
* ★ 工作包 A:**当天逐榜状态**以 day-index.json 为准(scan.json 只是一批)。
|
|
1544
|
+
* 没有 day-index 的旧数据回退到老口径(rec.boards / 快照存在性),不报错、不伪造。
|
|
1545
|
+
*/
|
|
1546
|
+
const day = latest ? store.readDayIndex(latest) : null;
|
|
1311
1547
|
const slimAll = listSlim(root).map(d => readSlim(root, d)).filter(Boolean);
|
|
1312
1548
|
const rows = [];
|
|
1313
1549
|
for (const boardId of st.boards) {
|
|
1314
1550
|
const meta = boardMeta(boardId);
|
|
1315
1551
|
const b = rec && rec.boards ? rec.boards.find((x) => x.boardId === boardId) : null;
|
|
1552
|
+
const dstate = boardDayState(day, boardId);
|
|
1316
1553
|
const snap = latest ? store.readSnapshot(latest, boardId) : null;
|
|
1317
|
-
|
|
1318
|
-
const
|
|
1554
|
+
// ★ 逐榜基准:该榜自己的上一次可信成功(跨过缺日),不是「全局上一数据日」
|
|
1555
|
+
const bPrev = snap && latest ? previousBoardDate(boardId, latest, dates) : null;
|
|
1556
|
+
const trusted = dstate ? dstate.trusted !== false : !(latest && isUntrusted(latest, boardId));
|
|
1557
|
+
/** ★ 2026-10-25:批次榜不比较变化(见 view.ts#isBatchBoard) */
|
|
1558
|
+
const isBatch = isBatchBoard(boardId);
|
|
1559
|
+
const diff = !isBatch && trusted && snap && latest && bPrev ? diffFor(boardId, latest, bPrev, undefined, slimAll) : null;
|
|
1560
|
+
const c = diff && !diff.crossPeriod && diff.counts ? diff.counts : null;
|
|
1561
|
+
const batch = isBatch && snap && latest
|
|
1562
|
+
? (() => {
|
|
1563
|
+
const kind = batchKindOf(boardId);
|
|
1564
|
+
const key = batchKeyOf(kind, snap.rows) || (kind === 'date' ? addDays(latest, -1) : null);
|
|
1565
|
+
return { key, label: batchLabelOf(kind, key), count: (snap.rows || []).length };
|
|
1566
|
+
})()
|
|
1567
|
+
: null;
|
|
1319
1568
|
/**
|
|
1320
1569
|
* ★ 2026-10-17(发布前修):**本地派生榜**(fanqie.derived.*)永远不会有 scan 记录、
|
|
1321
1570
|
* 也不会落快照文件(数据是打开榜页时现算的)⇒ 旧口径「b ? … : snap ? 'ok' : 'missing'」
|
|
@@ -1323,15 +1572,36 @@ export function apply(ctx, config) {
|
|
|
1323
1572
|
* ⇒ 概览永远显示「异常 1 个榜」。它不是「没扫到」,是「不需要扫」:状态直接给 ok。
|
|
1324
1573
|
*/
|
|
1325
1574
|
const derived = boardId.startsWith('fanqie.derived.');
|
|
1575
|
+
const today = localDate(new Date());
|
|
1576
|
+
const attemptedToday = st.boardLastScan?.[boardId]?.date === today || (latest === today && !!(dstate || b));
|
|
1577
|
+
const plannedTime = st.siteTimes?.[meta.site] || DEFAULT_SITE_TIMES[meta.site] || DEFAULT_FALLBACK_TIME;
|
|
1578
|
+
const scheduleState = !derived && st.timerEnabled && !attemptedToday
|
|
1579
|
+
? (hmOf(new Date()) < plannedTime ? 'waiting' : 'due') : null;
|
|
1326
1580
|
rows.push({
|
|
1581
|
+
scheduleState, plannedTime,
|
|
1327
1582
|
boardId,
|
|
1328
1583
|
name: meta.name,
|
|
1329
1584
|
site: meta.site,
|
|
1330
1585
|
siteName: meta.siteName,
|
|
1331
|
-
|
|
1586
|
+
/**
|
|
1587
|
+
* ★ 工作包 A:优先用当天逐榜状态(含 missing/stale/truncated/login_required 五态);
|
|
1588
|
+
* 没有 day-index 才回退老口径。派生榜按设计不扫描 ⇒ 恒 ok。
|
|
1589
|
+
*/
|
|
1590
|
+
status: derived ? 'ok' : dstate ? dstate.status : b ? b.status : snap ? 'ok' : 'missing',
|
|
1591
|
+
/** true = 内容可信(stale 隔离后为 false;前端据此不给「正常」字样) */
|
|
1592
|
+
trusted: derived ? true : dstate ? dstate.trusted !== false : !(latest && isUntrusted(latest, boardId)),
|
|
1593
|
+
/** true = 同一期未变化(周期榜正常形态) */
|
|
1594
|
+
samePeriod: dstate ? dstate.samePeriod === true : false,
|
|
1595
|
+
/** 当天最近一次尝试(失败原因留在这里,不被之后的成功批次冲掉) */
|
|
1596
|
+
attempt: dstate ? dstate.lastAttempt : null,
|
|
1597
|
+
/** 当天最近一次可信成功的时刻(没有就 null) */
|
|
1598
|
+
lastSuccessAt: dstate && dstate.lastSuccess ? dstate.lastSuccess.at : null,
|
|
1332
1599
|
up: c ? c.up : null,
|
|
1333
1600
|
newCount: c ? c.new + c.rebound : null,
|
|
1334
1601
|
out: c ? c.out : null,
|
|
1602
|
+
/** 批次榜:这一批是什么(不是「涨/新/退」,面板据此替换成「第 N 期 · M 本」) */
|
|
1603
|
+
batch,
|
|
1604
|
+
changesEligible: !isBatch,
|
|
1335
1605
|
/**
|
|
1336
1606
|
* ★ 2026-10-17(使用者反馈「为什么 20 个榜都显示 08:30」):以前取的是**整轮扫描记录**的
|
|
1337
1607
|
* finishedAt ⇒ 所有榜共用同一时刻,看着像「按站抓取没生效」。改成三层:
|
|
@@ -1339,6 +1609,9 @@ export function apply(ctx, config) {
|
|
|
1339
1609
|
* ③ 都没有(本地派生榜 / 今天没抓到的榜)就留 null,面板显示「—」,不再拿别人的时间冒充。
|
|
1340
1610
|
*/
|
|
1341
1611
|
lastCapture: (function () {
|
|
1612
|
+
// ★ 工作包 A:优先「当天最近一次可信成功」;否则退回本批的 capturedAt / 旧兜底
|
|
1613
|
+
if (dstate && dstate.lastSuccess && dstate.lastSuccess.at)
|
|
1614
|
+
return String(dstate.lastSuccess.at);
|
|
1342
1615
|
const own = b && b.capturedAt ? String(b.capturedAt) : null;
|
|
1343
1616
|
if (own)
|
|
1344
1617
|
return own;
|
|
@@ -1351,7 +1624,11 @@ export function apply(ctx, config) {
|
|
|
1351
1624
|
const mt = latest ? store.snapshotMtime(boardId, latest) : null;
|
|
1352
1625
|
return mt ? new Date(mt).toISOString() : null;
|
|
1353
1626
|
})(),
|
|
1354
|
-
note: derived
|
|
1627
|
+
note: derived
|
|
1628
|
+
? '本地派生(0 请求,打开榜页时现算)'
|
|
1629
|
+
: dstate
|
|
1630
|
+
? (dstate.reason || (dstate.samePeriod ? '同一期未变化(正常)' : null))
|
|
1631
|
+
: b ? b.reason || null : snap ? null : '今天还没扫(或该榜抓取失败)',
|
|
1355
1632
|
extended: !!meta.extended,
|
|
1356
1633
|
source: meta.source || null,
|
|
1357
1634
|
mainLabel: mainLabelOf(boardId, meta),
|
|
@@ -1368,6 +1645,12 @@ export function apply(ctx, config) {
|
|
|
1368
1645
|
baselineDate: prevDate,
|
|
1369
1646
|
firstEver: dates.length < 2,
|
|
1370
1647
|
counts,
|
|
1648
|
+
/**
|
|
1649
|
+
* ★ 工作包 A:同日数据 revision。扫描/单榜重抓/补全只要改写了快照或隔离标记就会变,
|
|
1650
|
+
* 前端不必等「数据日期」变化才重取(体检 P2-C 的后端侧支撑)。
|
|
1651
|
+
*/
|
|
1652
|
+
revision: dataRevision(latest),
|
|
1653
|
+
dayRevision: day ? day.revision : null,
|
|
1371
1654
|
// 派生榜按设计不进 display ⇒ 不能算进「隐藏 N 个」(它不是被藏起来的,是不需要单独扫)
|
|
1372
1655
|
hiddenCount: rows.filter((r) => !r.displayed && !r.derived).length,
|
|
1373
1656
|
sites: groupBySite(rows).map((s) => ({ ...s, boards: rows.filter((r) => r.site === s.site) })),
|
|
@@ -1401,8 +1684,22 @@ export function apply(ctx, config) {
|
|
|
1401
1684
|
/** ★ 按站分时:现在会跑哪个站、每站上次跑过的数据日(面板「抓什么」页展示) */
|
|
1402
1685
|
schedule: timerPlanNow(),
|
|
1403
1686
|
},
|
|
1404
|
-
|
|
1405
|
-
|
|
1687
|
+
/**
|
|
1688
|
+
* ★ Spec E(2026-10-24):运行中优先用**内存活跃记录**(onProgress 每榜更新),
|
|
1689
|
+
* 落盘 scan.json 只在整轮结束才写 ⇒ 旧实现在扫描过程中永远回上一轮的 completed。
|
|
1690
|
+
* inFlight 让面板能区分「真的在跑」与「上次进程崩了留下的 running」:
|
|
1691
|
+
* 后者不该显示进度、也不该高频轮询。
|
|
1692
|
+
*/
|
|
1693
|
+
scan: (liveScan || rec)
|
|
1694
|
+
? {
|
|
1695
|
+
outcome: (liveScan || rec).outcome,
|
|
1696
|
+
attempt: (liveScan || rec).attempt,
|
|
1697
|
+
trigger: (liveScan || rec).trigger,
|
|
1698
|
+
progress: (liveScan || rec).progress,
|
|
1699
|
+
warnings: (liveScan || rec).warnings,
|
|
1700
|
+
startedAt: (liveScan || rec).startedAt,
|
|
1701
|
+
inFlight: !!liveScan,
|
|
1702
|
+
}
|
|
1406
1703
|
: null,
|
|
1407
1704
|
defaults: {
|
|
1408
1705
|
scanTime: st.scanTime,
|
|
@@ -1498,11 +1795,51 @@ export function apply(ctx, config) {
|
|
|
1498
1795
|
const keys = new Set(applyColumnPolicy(columnsFor(meta, { hasBaseline: flags.hasHistory, hasHistory: flags.hasHistory }), boardId).map((c) => c.key));
|
|
1499
1796
|
return opts.filter((o) => !o.value || o.value === 'rank' || keys.has(o.value));
|
|
1500
1797
|
}
|
|
1798
|
+
/**
|
|
1799
|
+
* ★ 2026-10-25(批次榜):把「数据日期」折成「批」。
|
|
1800
|
+
* 刺猬猫首订一期跨 7 个数据日、内容雷同(实测 issue 478 = 10-17..10-23),
|
|
1801
|
+
* 日期下拉原来列 12 项、其中 7 项是同一期 ⇒ 按批只留一个代表快照日(优先最新**可信**日)。
|
|
1802
|
+
* 起点图首订是「一天一批(按上架日)」,每批同样只有一个代表日。
|
|
1803
|
+
*/
|
|
1804
|
+
function batchPeriodsFor(boardId, datesFor) {
|
|
1805
|
+
const kind = batchKindOf(boardId);
|
|
1806
|
+
if (!kind)
|
|
1807
|
+
return [];
|
|
1808
|
+
const store = new FileStore(root);
|
|
1809
|
+
const groups = new Map();
|
|
1810
|
+
for (const d of datesFor) {
|
|
1811
|
+
const snap = store.readSnapshot(d, boardId);
|
|
1812
|
+
if (!snap || !(snap.rows || []).length)
|
|
1813
|
+
continue;
|
|
1814
|
+
const key = batchKeyOf(kind, snap.rows) || (kind === 'date' ? addDays(d, -1) : null);
|
|
1815
|
+
if (!key)
|
|
1816
|
+
continue;
|
|
1817
|
+
const g = groups.get(key) || { key, dates: [], rows: [] };
|
|
1818
|
+
if (!g.dates.includes(d))
|
|
1819
|
+
g.dates.push(d);
|
|
1820
|
+
if (!g.rows.length)
|
|
1821
|
+
g.rows = snap.rows;
|
|
1822
|
+
groups.set(key, g);
|
|
1823
|
+
}
|
|
1824
|
+
const out = [];
|
|
1825
|
+
for (const g of groups.values()) {
|
|
1826
|
+
const trusted = g.dates.filter((d) => !store.isUntrusted(d, boardId));
|
|
1827
|
+
const rep = (trusted.length ? trusted : g.dates).slice(-1)[0];
|
|
1828
|
+
/**
|
|
1829
|
+
* 本数取**代表日**那份快照的行数:同一期会继续补书(实测 478 期首日 15 本、次日 17 本),
|
|
1830
|
+
* 拿首日数会少报。
|
|
1831
|
+
*/
|
|
1832
|
+
const repSnap = store.readSnapshot(rep, boardId);
|
|
1833
|
+
const count = repSnap && Array.isArray(repSnap.rows) ? repSnap.rows.length : g.rows.length;
|
|
1834
|
+
out.push({ key: g.key, label: batchLabelOf(kind, g.key), date: rep, dates: g.dates.slice(), count, untrusted: trusted.length === 0 });
|
|
1835
|
+
}
|
|
1836
|
+
out.sort((a, b) => (a.date < b.date ? -1 : a.date > b.date ? 1 : 0));
|
|
1837
|
+
return out;
|
|
1838
|
+
}
|
|
1501
1839
|
async function panelBoard(boardId, dateArg, sort, limit = 0) {
|
|
1502
1840
|
const { st, dates, latest } = panelCtx();
|
|
1503
1841
|
const meta = boardMeta(boardId);
|
|
1504
1842
|
const store = new FileStore(root);
|
|
1505
|
-
const useDate = dateArg && dates.includes(dateArg) ? dateArg : latest;
|
|
1506
1843
|
/**
|
|
1507
1844
|
* ★ 日期下拉按**该榜自己有快照的日期**过滤(2026-10-15 使用反馈):
|
|
1508
1845
|
* 之前面板用全局「所有数据日期」,于是给某个榜点一次历史查询,那个日期就会出现在**所有站点**的下拉里。
|
|
@@ -1510,6 +1847,20 @@ export function apply(ctx, config) {
|
|
|
1510
1847
|
*/
|
|
1511
1848
|
// 派生榜没有自己的快照(它按区间动态算,且始终算最新一期)⇒ 日期下拉对它无意义,给空数组让前端隐藏
|
|
1512
1849
|
const datesFor = boardId.startsWith('fanqie.derived.') ? [] : dates.filter((d) => !!store.readSnapshot(d, boardId));
|
|
1850
|
+
/**
|
|
1851
|
+
* ★ 2026-10-25(批次榜):下拉控件是「批」不是「日期」。
|
|
1852
|
+
* 没显式指定时,落到**最新一批**的代表日(优先最新可信日;整批都不可信才落到最新日并标 stale)。
|
|
1853
|
+
*/
|
|
1854
|
+
const isBatch = isBatchBoard(boardId);
|
|
1855
|
+
const periods = isBatch ? batchPeriodsFor(boardId, datesFor) : [];
|
|
1856
|
+
/**
|
|
1857
|
+
* 批次榜对外只暴露「批的代表日」:客户端下拉直接用它当选项(协议不变,仍传 date)。
|
|
1858
|
+
* 同一期的 7 个数据日不再重复出现。
|
|
1859
|
+
*/
|
|
1860
|
+
const shownDates = isBatch ? periods.map((p) => p.date) : datesFor;
|
|
1861
|
+
const useDate = dateArg && dates.includes(dateArg)
|
|
1862
|
+
? dateArg
|
|
1863
|
+
: (isBatch && periods.length ? periods[periods.length - 1].date : latest);
|
|
1513
1864
|
// 「在榜天数」只在**该榜真有历史**时才占列:原判断是全站的(任何榜有历史 ⇒ 每站都挂一列空的),
|
|
1514
1865
|
// 使用者 2026-10-15 点名起点图不要这一列 ⇒ 改成按榜查精简索引里有没有它更早的记录。
|
|
1515
1866
|
if (!latest) {
|
|
@@ -1529,7 +1880,9 @@ export function apply(ctx, config) {
|
|
|
1529
1880
|
// 该榜有任何本地数据就出这一列(单日时每行是「1 天」;没有更早数据 ≠ 没历史)
|
|
1530
1881
|
const hasHistory = shouldShowDays(meta.site, datesFor.length);
|
|
1531
1882
|
// 列集合统一过一遍站点口径(起点图不出名次变化、三江不出重复的 daily、刺猬猫首订不出在榜天数)
|
|
1532
|
-
|
|
1883
|
+
// ★ 工作包 A:「有基准」要按**该榜自己**有没有上一次可信快照判(不能拿全局日期数冒充)
|
|
1884
|
+
const boardPrev = previousBoardDate(boardId, date, dates);
|
|
1885
|
+
const columns = applyColumnPolicy(columnsFor(meta, { hasBaseline: !!boardPrev, hasHistory }), boardId);
|
|
1533
1886
|
// 派生榜(番茄在读涨幅榜 / 七日累计):纯本地算,不发请求
|
|
1534
1887
|
if (boardId.startsWith('fanqie.derived.')) {
|
|
1535
1888
|
const read = (b, d) => store.readSnapshot(d, b);
|
|
@@ -1573,10 +1926,74 @@ export function apply(ctx, config) {
|
|
|
1573
1926
|
}
|
|
1574
1927
|
}
|
|
1575
1928
|
if (!snap)
|
|
1576
|
-
return { boardId, meta, columns, dataDate: useDate, dates:
|
|
1929
|
+
return { boardId, meta, columns, dataDate: useDate, dates: shownDates, rows: [], note: '该榜在这天没有快照(也没找到更早的可用快照)' };
|
|
1577
1930
|
const effDate = fallbackFrom || date;
|
|
1578
|
-
|
|
1579
|
-
|
|
1931
|
+
/**
|
|
1932
|
+
* ★ 2026-10-25(批次榜):这一屏属于哪一批。面板据此把「数据日期 / 对比 YYYY-MM-DD」
|
|
1933
|
+
* 换成「第 479 期 · 上架日 2026-10-23 · 共 17 本」,并且不再给变化计数。
|
|
1934
|
+
*/
|
|
1935
|
+
const batch = isBatch
|
|
1936
|
+
? (() => {
|
|
1937
|
+
const kind = batchKindOf(boardId);
|
|
1938
|
+
const key = batchKeyOf(kind, snap.rows) || (kind === 'date' ? addDays(effDate, -1) : null);
|
|
1939
|
+
const range = kind === 'issue' ? saleRangeOf(snap.rows) : null;
|
|
1940
|
+
const saleStart = range ? range.start : (kind === 'date' ? key : null);
|
|
1941
|
+
const saleEnd = range ? range.end : (kind === 'date' ? key : null);
|
|
1942
|
+
return {
|
|
1943
|
+
kind,
|
|
1944
|
+
key,
|
|
1945
|
+
label: batchLabelOf(kind, key),
|
|
1946
|
+
count: (snap.rows || []).length,
|
|
1947
|
+
saleStart,
|
|
1948
|
+
saleEnd,
|
|
1949
|
+
snapshotDate: effDate,
|
|
1950
|
+
unit: kind === 'issue' ? '期' : '上架日',
|
|
1951
|
+
};
|
|
1952
|
+
})()
|
|
1953
|
+
: null;
|
|
1954
|
+
/**
|
|
1955
|
+
* ★ 工作包 A:逐榜基准 = **该榜自己的上一次可信成功**(跨过缺日、跨过被拒快照)。
|
|
1956
|
+
* 旧口径只看全局上一数据日:该榜缺一天 → previousPer 为空 → 整列变化空、firstEver=true(体检 P1-B)。
|
|
1957
|
+
*/
|
|
1958
|
+
const prevDate = previousBoardDate(boardId, effDate, dates);
|
|
1959
|
+
/**
|
|
1960
|
+
* ★ 工作包 A:**stale 隔离**。raw 快照保留在盘上(证据),但不进展示:
|
|
1961
|
+
* 返回空行 + 明确状态,前端只需按 status/note 显示说明(不再拿被拒页面当今天榜单)。
|
|
1962
|
+
*/
|
|
1963
|
+
if (isUntrusted(effDate, boardId)) {
|
|
1964
|
+
const mark = store.readUntrusted(effDate, boardId);
|
|
1965
|
+
return {
|
|
1966
|
+
boardId,
|
|
1967
|
+
meta: { ...meta, mainLabel: mainLabelOf(boardId, meta) },
|
|
1968
|
+
sortOptions: sortOptionsFor(boardId, meta, { hasHistory }),
|
|
1969
|
+
depth: (st.depths || {})[boardId] ?? (meta.site === 'fanqie' ? 30 : 10),
|
|
1970
|
+
columns,
|
|
1971
|
+
dataDate: effDate,
|
|
1972
|
+
requestedDate: date,
|
|
1973
|
+
fallbackFrom,
|
|
1974
|
+
dates: shownDates,
|
|
1975
|
+
baselineDate: prevDate,
|
|
1976
|
+
firstEver: !prevDate,
|
|
1977
|
+
counts: null,
|
|
1978
|
+
batch,
|
|
1979
|
+
periods,
|
|
1980
|
+
changesEligible: false,
|
|
1981
|
+
status: 'stale',
|
|
1982
|
+
trusted: false,
|
|
1983
|
+
rawRows: (snap.rows || []).length,
|
|
1984
|
+
attempt: store.readDayIndex(effDate)?.boards?.[boardId]?.lastAttempt || null,
|
|
1985
|
+
revision: dataRevision(effDate),
|
|
1986
|
+
enrich: null,
|
|
1987
|
+
rows: [],
|
|
1988
|
+
note: '本次抓到内容不可信(' + String((mark && mark.reason) || '疑似未刷新/换榜') + ')。原始快照已保留在 ' + effDate + '/' + boardId + '.json,但本次不展示、不参与变化。',
|
|
1989
|
+
source: meta.source || null,
|
|
1990
|
+
};
|
|
1991
|
+
}
|
|
1992
|
+
/**
|
|
1993
|
+
* ★ 2026-10-25:批次榜**不算变化**(批内不变、跨批不可比)⇒ 不跑 diff、不给计数。
|
|
1994
|
+
* 留给客户端的只有「这一批是什么」,涨/新/退一律为 null(显示「—」,不是 0)。
|
|
1995
|
+
*/
|
|
1996
|
+
const diff = !isBatch && prevDate ? diffFor(boardId, effDate, prevDate) : null;
|
|
1580
1997
|
const byKey = new Map();
|
|
1581
1998
|
if (diff) {
|
|
1582
1999
|
// 五个组都要建索引(flat 也不许漏,否则持平行的名次 delta 取不到)
|
|
@@ -1612,9 +2029,16 @@ export function apply(ctx, config) {
|
|
|
1612
2029
|
boardId,
|
|
1613
2030
|
prevDate,
|
|
1614
2031
|
date: effDate,
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
2032
|
+
/**
|
|
2033
|
+
* ★ 工作包 A:期键一律取快照里的**真实期号** —— 三江 = extra.periodStart,
|
|
2034
|
+
* 刺猬猫首订(约) = extra.issue。旧实现只给刺猬猫接了这个口,三江退回「本周日」推算,
|
|
2035
|
+
* 而缺日/跨周时推算出的期与站点实际期不一致 ⇒ 跨期保护会漏判。
|
|
2036
|
+
*/
|
|
2037
|
+
periodKeyOf: boardId === 'qidiantu.sanjiang'
|
|
2038
|
+
? (dt) => keyFromSnap(dt === effDate ? snap : prevSnap, 'periodStart')
|
|
2039
|
+
: boardId === 'ciweimao.buy.latest'
|
|
2040
|
+
? (dt) => keyFromSnap(dt === effDate ? snap : prevSnap, 'issue')
|
|
2041
|
+
: undefined,
|
|
1618
2042
|
});
|
|
1619
2043
|
const crossPeriod = guard.crossed;
|
|
1620
2044
|
const prevByKey = new Map();
|
|
@@ -1726,7 +2150,7 @@ export function apply(ctx, config) {
|
|
|
1726
2150
|
}
|
|
1727
2151
|
else if (pr != null && cr != null) {
|
|
1728
2152
|
deltaOut = pr - cr;
|
|
1729
|
-
groupOut = dd ? dd.group : (Math.abs(deltaOut) <=
|
|
2153
|
+
groupOut = dd ? dd.group : (Math.abs(deltaOut) <= jitterForBoard(boardId) ? 'flat' : deltaOut > 0 ? 'up' : 'down');
|
|
1730
2154
|
}
|
|
1731
2155
|
else if (typeof (r.extra && r.extra.rankPosDiff) === 'number') {
|
|
1732
2156
|
/**
|
|
@@ -1768,6 +2192,12 @@ export function apply(ctx, config) {
|
|
|
1768
2192
|
rows = rows.slice().sort((a, b) => compareDesc(num(sortVal(a, effSort)), num(sortVal(b, effSort))));
|
|
1769
2193
|
if (limit > 0)
|
|
1770
2194
|
rows = rows.slice(0, limit);
|
|
2195
|
+
/**
|
|
2196
|
+
* ★ 工作包 A:状态取**当天逐榜索引**(而不是「最后一批扫描记录」)。
|
|
2197
|
+
* 旧实现读 scan.json:一天 5 批之后只剩最后一站的记录 ⇒ 其余站的状态被洗成 ok/missing。
|
|
2198
|
+
*/
|
|
2199
|
+
const dayIdxB = store.readDayIndex(effDate);
|
|
2200
|
+
const dstateB = boardDayState(dayIdxB, boardId);
|
|
1771
2201
|
const statusRow = await store.readScan(effDate);
|
|
1772
2202
|
const brd = statusRow && statusRow.boards ? statusRow.boards.find((x) => x.boardId === boardId) : null;
|
|
1773
2203
|
/**
|
|
@@ -1802,20 +2232,37 @@ export function apply(ctx, config) {
|
|
|
1802
2232
|
dataDate: effDate,
|
|
1803
2233
|
requestedDate: date,
|
|
1804
2234
|
fallbackFrom,
|
|
1805
|
-
dates:
|
|
2235
|
+
dates: shownDates,
|
|
2236
|
+
/** ★ 批次榜:可选「批」列表(每批一个代表快照日 + 标签) */
|
|
2237
|
+
periods,
|
|
2238
|
+
batch,
|
|
2239
|
+
/** false = 该榜不参与「变化」(批次榜整批换新,比较没有意义) */
|
|
2240
|
+
changesEligible: !isBatch,
|
|
1806
2241
|
baselineDate: diff ? diff.baselineDate : null,
|
|
1807
2242
|
firstEver: diff ? diff.firstEver : true,
|
|
1808
|
-
counts: diff ? diff.counts : null,
|
|
1809
|
-
|
|
2243
|
+
counts: diff && !crossPeriod ? diff.counts : null,
|
|
2244
|
+
crossPeriod: isBatch ? false : crossPeriod,
|
|
2245
|
+
status: dstateB ? dstateB.status : brd ? brd.status : 'ok',
|
|
2246
|
+
trusted: dstateB ? dstateB.trusted !== false : !isUntrusted(effDate, boardId),
|
|
2247
|
+
samePeriod: dstateB ? dstateB.samePeriod === true : false,
|
|
2248
|
+
/** 当天最近一次尝试(含失败原因)—— 失败不会被之后别的站的成功冲掉 */
|
|
2249
|
+
attempt: dstateB ? dstateB.lastAttempt : null,
|
|
2250
|
+
/** 同名数据日期内的数据 revision(前端据此重取,不必等跨日) */
|
|
2251
|
+
revision: dataRevision(effDate),
|
|
1810
2252
|
enrich: enrichInfo,
|
|
1811
2253
|
rows,
|
|
1812
2254
|
// ★ 跨期当天必须写明「变化列为什么是空的」(口径说明跟着数据一起走,别只活在代码注释里)
|
|
1813
|
-
note:
|
|
1814
|
-
? (
|
|
1815
|
-
? '
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
:
|
|
2255
|
+
note: isBatch
|
|
2256
|
+
? ([
|
|
2257
|
+
batch && batch.label ? batch.label + ' · 共 ' + batch.count + ' 本' : '批次榜 · 共 ' + ((snap.rows || []).length) + ' 本',
|
|
2258
|
+
'批次榜整批换新,不比较变化',
|
|
2259
|
+
].join(';') + (meta.caliber ? '。' + meta.caliber : ''))
|
|
2260
|
+
: crossPeriod
|
|
2261
|
+
? (guard.prevPeriod && guard.curPeriod && guard.prevPeriod !== guard.curPeriod
|
|
2262
|
+
? '⚠ 本期已换期(期号 ' + guard.prevPeriod + ' → ' + guard.curPeriod + '):「变化」列跨期不可比,一律显示「新期」'
|
|
2263
|
+
: '⚠ 本期已换期:「变化」列跨期不可比,一律显示「新期」')
|
|
2264
|
+
+ (meta.caliber ? '。' + meta.caliber : '')
|
|
2265
|
+
: (meta.caliber || null),
|
|
1819
2266
|
source: meta.source || null,
|
|
1820
2267
|
};
|
|
1821
2268
|
}
|
|
@@ -1829,6 +2276,12 @@ export function apply(ctx, config) {
|
|
|
1829
2276
|
const slimAll = listSlim(root).map(d => readSlim(root, d)).filter(Boolean);
|
|
1830
2277
|
const entries = [];
|
|
1831
2278
|
let firstEver = true;
|
|
2279
|
+
/** ★ 工作包 A:当天有快照但被拒的榜(不让它们的变化漏进来) */
|
|
2280
|
+
const excluded = [];
|
|
2281
|
+
/** ★ 工作包 A:确实没有可比基准的榜(如实说明,而不是静默跳过) */
|
|
2282
|
+
const noBaseline = [];
|
|
2283
|
+
/** ★ 2026-10-25:批次榜不参与变化(见下方 isBatchBoard) */
|
|
2284
|
+
const batchExcluded = [];
|
|
1832
2285
|
for (const boardId of st.boards) {
|
|
1833
2286
|
if (!st.display.includes(boardId))
|
|
1834
2287
|
continue;
|
|
@@ -1838,12 +2291,36 @@ export function apply(ctx, config) {
|
|
|
1838
2291
|
if (!snap)
|
|
1839
2292
|
continue;
|
|
1840
2293
|
const meta = boardMeta(boardId);
|
|
1841
|
-
if (
|
|
2294
|
+
if (isUntrusted(useDate, boardId)) {
|
|
2295
|
+
excluded.push({ boardId, reason: '内容不可信(已隔离)' });
|
|
1842
2296
|
continue;
|
|
1843
|
-
|
|
2297
|
+
}
|
|
2298
|
+
/**
|
|
2299
|
+
* ★ 2026-10-25:批次榜**整批换新**(刺猬猫首订每周一期、起点图首订每天一批),
|
|
2300
|
+
* 批与批之间没有「榜内升降」;把整批新书算成「新入榜/退榜」只会制造假涨退。
|
|
2301
|
+
* 它们的内容在「榜单」页按期看,这里明确列为「不参与变化」,而不是静默跳过。
|
|
2302
|
+
*/
|
|
2303
|
+
if (isBatchBoard(boardId)) {
|
|
2304
|
+
batchExcluded.push(boardId);
|
|
2305
|
+
continue;
|
|
2306
|
+
}
|
|
2307
|
+
/**
|
|
2308
|
+
* ★ 工作包 A:逐榜基准(跨过缺日)。缺基准的榜不再「静默跳过且被算成没变化」,
|
|
2309
|
+
* 而是进 noBaseline 列表,由 note 如实说明。
|
|
2310
|
+
*/
|
|
2311
|
+
const prevB = previousBoardDate(boardId, useDate, dates);
|
|
2312
|
+
if (!prevB) {
|
|
2313
|
+
noBaseline.push(boardId);
|
|
2314
|
+
continue;
|
|
2315
|
+
}
|
|
2316
|
+
const d = diffFor(boardId, useDate, prevB, undefined, slimAll);
|
|
1844
2317
|
if (d.firstEver)
|
|
1845
2318
|
continue;
|
|
1846
2319
|
firstEver = false;
|
|
2320
|
+
if (d.crossPeriod) {
|
|
2321
|
+
excluded.push({ boardId, reason: '新期不可比(不参与变化)' });
|
|
2322
|
+
continue;
|
|
2323
|
+
}
|
|
1847
2324
|
const push = (group, list, sign) => {
|
|
1848
2325
|
for (const e of list || [])
|
|
1849
2326
|
entries.push({
|
|
@@ -1851,6 +2328,8 @@ export function apply(ctx, config) {
|
|
|
1851
2328
|
siteName: meta.siteName,
|
|
1852
2329
|
boardId,
|
|
1853
2330
|
boardName: meta.name,
|
|
2331
|
+
/** ★ 工作包 A:该榜自己的对比基准日(各榜基准可能不同,顶层的 baselineDate 只是汇总) */
|
|
2332
|
+
baselineDate: d.baselineDate,
|
|
1854
2333
|
group,
|
|
1855
2334
|
title: e.title,
|
|
1856
2335
|
delta: e.delta == null ? '' : sign + String(e.delta),
|
|
@@ -1868,8 +2347,18 @@ export function apply(ctx, config) {
|
|
|
1868
2347
|
baselineDate: prevDate,
|
|
1869
2348
|
firstEver: firstEver && !entries.length,
|
|
1870
2349
|
count: entries.length,
|
|
1871
|
-
sites: groupChanges(entries),
|
|
1872
|
-
|
|
2350
|
+
sites: groupChanges(entries).map((site) => ({ ...site, groups: site.groups.map((g) => ({ ...g, count: g.items.length })) })),
|
|
2351
|
+
/** ★ 工作包 A:同日内数据变化就换 revision(前端不必等跨日) */
|
|
2352
|
+
revision: dataRevision(useDate),
|
|
2353
|
+
excluded,
|
|
2354
|
+
noBaseline,
|
|
2355
|
+
batchExcluded,
|
|
2356
|
+
note: [
|
|
2357
|
+
prevDate ? null : '还没有上一数据日:无基准,不报 0',
|
|
2358
|
+
excluded.length ? excluded.length + ' 个榜不参与变化(内容隔离或新期不可比)' : null,
|
|
2359
|
+
batchExcluded.length ? batchExcluded.length + ' 个批次榜不参与变化(整批换新,比较无意义)' : null,
|
|
2360
|
+
noBaseline.length ? noBaseline.length + ' 个榜没有可比基准(缺更早的可信快照)' : null,
|
|
2361
|
+
].filter(Boolean).join(';') || null,
|
|
1873
2362
|
};
|
|
1874
2363
|
}
|
|
1875
2364
|
/** webServer 服务是可选依赖:用依赖光纤做晚绑定(直取 ctx.webServer 在运行时拿不到 —— T12 验收实测 404) */
|
|
@@ -1910,6 +2399,7 @@ export function apply(ctx, config) {
|
|
|
1910
2399
|
for (const [id, meta] of Object.entries(SFACG_BOARDS))
|
|
1911
2400
|
push('sfacg', '菠萝包', '榜单', id, meta.name);
|
|
1912
2401
|
return {
|
|
2402
|
+
defaultCaptures: defaultState().boards,
|
|
1913
2403
|
boards: rows, captures: st.boards, displays: st.display, depths: st.depths || {}, autoEnrich: st.autoEnrich !== false,
|
|
1914
2404
|
// 起点书页补全:开关状态 + 缓存规模(面板据此显示「已缓存 N 本 / 截止时间」)
|
|
1915
2405
|
qidian: { enrich: st.qidianEnrich === true, cache: cacheStats(root), ttlDays: Math.round(QIDIAN_CACHE_TTL_MS / 86400000) },
|
|
@@ -3206,6 +3696,8 @@ export function apply(ctx, config) {
|
|
|
3206
3696
|
if (body.save) {
|
|
3207
3697
|
const store3 = new FileStore(root);
|
|
3208
3698
|
await store3.writeSnapshot({ boardId, dataDate: date, metric: res.metric || 'value', rows: res.rows });
|
|
3699
|
+
// ★ 工作包 A:手工补数成功 ⇒ 解除隔离标记并同步当天逐榜状态
|
|
3700
|
+
await trustBoardDay(date, boardId, new Date().toISOString());
|
|
3209
3701
|
}
|
|
3210
3702
|
return send(200, {
|
|
3211
3703
|
ok: true, boardId, date, saved: !!body.save, contentDate: verdict.contentDate, expected: verdict.expected,
|
|
@@ -3253,6 +3745,8 @@ export function apply(ctx, config) {
|
|
|
3253
3745
|
const contentDate = verdictR.contentDate;
|
|
3254
3746
|
const store2 = new FileStore(root);
|
|
3255
3747
|
await store2.writeSnapshot({ boardId: b, dataDate: date, metric: res.metric || 'value', rows: res.rows });
|
|
3748
|
+
// ★ 工作包 A:修数成功 ⇒ 解除隔离、同步逐榜状态
|
|
3749
|
+
await trustBoardDay(date, b, new Date().toISOString());
|
|
3256
3750
|
// 同步当天 scan.json 的记录,保持「快照 = 记录」
|
|
3257
3751
|
const rec2 = await store2.readScan(date);
|
|
3258
3752
|
if (rec2) {
|
|
@@ -3378,7 +3872,7 @@ export function apply(ctx, config) {
|
|
|
3378
3872
|
if (!got.ok)
|
|
3379
3873
|
return send(409, { error: '已有扫描在进行中,请等它跑完' });
|
|
3380
3874
|
const rec2 = got.value;
|
|
3381
|
-
return send(200, { ok: true, outcome: rec2.outcome, dataDate: rec2.dataDate, attempt: rec2.attempt, progress: rec2.progress });
|
|
3875
|
+
return send(200, { ok: true, outcome: rec2.outcome, dataDate: rec2.dataDate, attempt: rec2.attempt, progress: rec2.progress, revision: dataRevision(rec2.dataDate) });
|
|
3382
3876
|
}
|
|
3383
3877
|
if (p === '/api/rank-scan/scan') {
|
|
3384
3878
|
if (String(req.method || 'GET').toUpperCase() !== 'POST')
|
|
@@ -3412,9 +3906,22 @@ export function apply(ctx, config) {
|
|
|
3412
3906
|
return send(409, { error: '已有扫描在进行中(定时或另一个手动扫描),请等它跑完' });
|
|
3413
3907
|
const rec = got.value;
|
|
3414
3908
|
const stR = readState();
|
|
3909
|
+
const dayAfter = new FileStore(root).readDayIndex(rec.dataDate);
|
|
3415
3910
|
return send(200, {
|
|
3416
3911
|
ok: true, outcome: rec.outcome, dataDate: rec.dataDate, attempt: rec.attempt, progress: rec.progress,
|
|
3417
3912
|
scannedAll: !bsel,
|
|
3913
|
+
/** ★ 工作包 A:同日 revision(前端据此重新取 overview/board/changes) */
|
|
3914
|
+
revision: dataRevision(rec.dataDate),
|
|
3915
|
+
/** 当天**逐榜**最终状态(不是本批)——A 站失败不会被 B 站成功冲掉 */
|
|
3916
|
+
day: dayAfter
|
|
3917
|
+
? Object.keys(dayAfter.boards).map((k) => ({
|
|
3918
|
+
boardId: k,
|
|
3919
|
+
status: dayAfter.boards[k].status,
|
|
3920
|
+
reason: dayAfter.boards[k].reason,
|
|
3921
|
+
trusted: dayAfter.boards[k].trusted !== false,
|
|
3922
|
+
samePeriod: dayAfter.boards[k].samePeriod === true,
|
|
3923
|
+
}))
|
|
3924
|
+
: null,
|
|
3418
3925
|
enrich: stR.enrichRun ? { ...stR.enrichRun, active: timerState.enrichWorker } : null,
|
|
3419
3926
|
enrichPending: Object.keys((stR.enrichPending) || {}).length,
|
|
3420
3927
|
boards: (rec.boards || []).map((b) => ({ boardId: b.boardId, status: b.status, rows: (b.rows || []).length })),
|