dsh-rank-scan 0.2.3 → 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 +30 -27
- package/lib/client.js +1814 -676
- package/lib/index.js +674 -120
- 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 +33 -5
- package/lib/scan/run.js.map +1 -1
- package/lib/scan/schedule.js +10 -4
- package/lib/scan/schedule.js.map +1 -1
- package/lib/scan/store.js +95 -1
- package/lib/scan/store.js.map +1 -1
- package/lib/scan/types.js.map +1 -1
- package/lib/sites/qidiantu.js +9 -1
- package/lib/sites/qidiantu.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/schedule.d.ts +6 -0
- package/lib/types/scan/store.d.ts +44 -0
- package/lib/types/scan/types.d.ts +42 -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';
|
|
@@ -73,6 +75,8 @@ function defaultState() {
|
|
|
73
75
|
fallbackTime: DEFAULT_FALLBACK_TIME,
|
|
74
76
|
/** 每站最近一次定时跑过的数据日(跨重启有效,防重复跑) */
|
|
75
77
|
siteLastRun: {},
|
|
78
|
+
/** ★ 2026-10-17:每站**定时**那次跑成功的时刻(ISO)。siteLastRun 只有日期,面板要显示「定时 08:30」 */
|
|
79
|
+
siteLastTimerAt: {},
|
|
76
80
|
/** 每个榜最近一次扫描(含手动):面板可显示「这个榜上次什么时候抓的」 */
|
|
77
81
|
boardLastScan: {},
|
|
78
82
|
/**
|
|
@@ -283,6 +287,13 @@ export function apply(ctx, config) {
|
|
|
283
287
|
out.push(makeSfacgSite({ boards: sc }));
|
|
284
288
|
return out;
|
|
285
289
|
}
|
|
290
|
+
/**
|
|
291
|
+
* ★ 2026-10-17:站点集合的**测试 seam**(cfg.sitesFactory)。只给「按日期直查 / 修复」两条
|
|
292
|
+
* 写盘路径用 —— 单测要能断言「内容日期对不上时一个字节都没写」,不能真连站点。
|
|
293
|
+
*/
|
|
294
|
+
function serveSiteFor(boards, depths = {}) {
|
|
295
|
+
return typeof cfg.sitesFactory === 'function' ? cfg.sitesFactory(boards, depths) : sitesFor(boards, depths);
|
|
296
|
+
}
|
|
286
297
|
/**
|
|
287
298
|
* 扫描后补全:刺猬猫/菠萝包的**榜单页给不出字数/收藏**(刺猬猫完全没有,菠萝包只有前 2 名),
|
|
288
299
|
* 必须进书页取。默认开(state.autoEnrich !== false),只在整站扫描后跑,单榜扫描不跑。
|
|
@@ -352,103 +363,158 @@ export function apply(ctx, config) {
|
|
|
352
363
|
}
|
|
353
364
|
return done;
|
|
354
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;
|
|
355
373
|
async function doScan(trigger, opts) {
|
|
356
374
|
const st = readState();
|
|
357
375
|
const store = new FileStore(root);
|
|
358
376
|
const effectiveBoards = opts && opts.boards
|
|
359
377
|
? String(opts.boards).split(',').map((x) => x.trim()).filter(Boolean)
|
|
360
378
|
: st.boards;
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
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
|
+
}
|
|
372
407
|
/**
|
|
373
408
|
* ★ 2026-10-16(按站分时):一次「部分扫描」(只跑一个站)**不能覆盖当天的全量产物**:
|
|
374
409
|
* 精简索引/报告按 `<日期>-<站>` 落盘,全量扫的那份照旧叫 `<日期>`,两边都不丢。
|
|
375
410
|
*/
|
|
376
411
|
const artId = opts && opts.partial && opts.site ? rec.dataDate + '-' + String(opts.site) : rec.dataDate;
|
|
377
412
|
/**
|
|
378
|
-
* ★ 2026-10-
|
|
379
|
-
*
|
|
380
|
-
*
|
|
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。
|
|
381
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();
|
|
382
424
|
try {
|
|
383
|
-
const
|
|
425
|
+
const flagged = {};
|
|
384
426
|
const stS = readState();
|
|
385
427
|
const flags = { ...(stS.staleFlag || {}) };
|
|
386
|
-
for (const b of
|
|
428
|
+
for (const b of batchBoards) {
|
|
387
429
|
if (b.status !== 'ok')
|
|
388
430
|
continue;
|
|
389
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);
|
|
390
435
|
const pd = prevD ? store.readSnapshot(prevD, b.boardId) : null;
|
|
391
|
-
|
|
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 = [];
|
|
392
456
|
delete flags[b.boardId];
|
|
393
|
-
|
|
457
|
+
if (!swapped)
|
|
458
|
+
flagged[b.boardId] = { date: rec.dataDate, prevDate: prevD, suspected: true };
|
|
394
459
|
}
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
else
|
|
460
|
+
else {
|
|
461
|
+
try {
|
|
462
|
+
store.clearUntrusted(rec.dataDate, b.boardId);
|
|
463
|
+
}
|
|
464
|
+
catch { /* 清标记失败不影响结果 */ }
|
|
401
465
|
delete flags[b.boardId];
|
|
466
|
+
if (verdict.samePeriod) {
|
|
467
|
+
b.samePeriod = true;
|
|
468
|
+
samePeriodBoards.add(b.boardId);
|
|
469
|
+
}
|
|
470
|
+
}
|
|
402
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);
|
|
403
487
|
stS.staleFlag = flags;
|
|
404
488
|
writeState(stS);
|
|
405
|
-
const suspectBoards = Object.keys(
|
|
489
|
+
const suspectBoards = Object.keys(flagged);
|
|
406
490
|
if (suspectBoards.length)
|
|
407
|
-
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));
|
|
408
497
|
}
|
|
409
|
-
catch { /* 自检失败不该挡住扫描 */ }
|
|
410
498
|
// 每个榜的「上次扫描」落进 state(部分扫描时 scan.json 只留最后一次 ⇒ 面板要能逐榜查)
|
|
411
499
|
try {
|
|
412
500
|
const stB = readState();
|
|
413
501
|
const bls = { ...(stB.boardLastScan || {}) };
|
|
414
|
-
for (const b of
|
|
502
|
+
for (const b of batchBoards)
|
|
415
503
|
bls[b.boardId] = { date: rec.dataDate, at: new Date().toISOString(), outcome: String(b.status), by: trigger };
|
|
416
504
|
stB.boardLastScan = bls;
|
|
417
505
|
writeState(stB);
|
|
418
506
|
}
|
|
419
507
|
catch { /* 记不上不该影响扫描结果 */ }
|
|
420
508
|
const snaps = new Map();
|
|
421
|
-
for (const b of
|
|
509
|
+
for (const b of batchBoards) {
|
|
422
510
|
if (b.status !== 'ok')
|
|
423
511
|
continue;
|
|
424
512
|
const s = store.readSnapshot(rec.dataDate, b.boardId);
|
|
425
513
|
if (s)
|
|
426
514
|
snaps.set(b.boardId, s);
|
|
427
515
|
}
|
|
428
|
-
//
|
|
516
|
+
// 派生榜不进扫描:如实说一句(否则以后看 scan.json 会以为「漏抓了一个榜」)
|
|
429
517
|
try {
|
|
430
|
-
const prevDate = previousDataDate(listDataDates(root), rec.dataDate);
|
|
431
|
-
let changed = false;
|
|
432
|
-
for (const b of rec.boards) {
|
|
433
|
-
if (b.status !== 'ok' || !b.boardId.startsWith('ciweimao.'))
|
|
434
|
-
continue;
|
|
435
|
-
const prev = prevDate ? store.readSnapshot(prevDate, b.boardId) : null;
|
|
436
|
-
if (prev && looksSwapped(b.rows, prev.rows)) {
|
|
437
|
-
b.status = 'stale';
|
|
438
|
-
b.reason = '疑似换榜/降级(与上次有效快照交集 ≤2)';
|
|
439
|
-
b.rows = [];
|
|
440
|
-
changed = true;
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
if (changed) {
|
|
444
|
-
rec.warnings.push('有榜命中「换榜/降级」判据,本次不出条目');
|
|
445
|
-
await store.writeScan(rec);
|
|
446
|
-
}
|
|
447
|
-
/**
|
|
448
|
-
* ★ 抓取集里的**派生榜**不会被扫描(它由本地快照算出来,不发请求):
|
|
449
|
-
* `sitesFor()` 明确排除 `fanqie.derived.*`,而 runScan 只遍历各适配器的 boards ⇒ 它天然缺席。
|
|
450
|
-
* 这是对的,但**必须在记录里说一句**,否则以后看 scan.json 会以为「漏抓了一个榜」(2026-10-15)。
|
|
451
|
-
*/
|
|
452
518
|
const derivedInCapture = (st.boards || []).filter((b) => b.startsWith('fanqie.derived.'));
|
|
453
519
|
if (derivedInCapture.length) {
|
|
454
520
|
rec.warnings.push('派生榜不进扫描(本地按快照计算,0 请求):' + derivedInCapture.join('、'));
|
|
@@ -456,17 +522,62 @@ export function apply(ctx, config) {
|
|
|
456
522
|
}
|
|
457
523
|
}
|
|
458
524
|
catch (e) {
|
|
459
|
-
rec.warnings.push('
|
|
525
|
+
rec.warnings.push('派生榜说明写入失败:' + String(e).slice(0, 50));
|
|
460
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
|
+
*/
|
|
461
561
|
try {
|
|
462
|
-
const
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
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()));
|
|
467
578
|
}
|
|
468
579
|
catch (e) {
|
|
469
|
-
rec.warnings.push('
|
|
580
|
+
rec.warnings.push('逐榜状态索引写入失败:' + String(e).slice(0, 60));
|
|
470
581
|
}
|
|
471
582
|
/**
|
|
472
583
|
* ★ 2026-10-17(补全移出阻塞路径):把补全**从 /scan 的等待里摘出去**。
|
|
@@ -480,7 +591,7 @@ export function apply(ctx, config) {
|
|
|
480
591
|
* 同步通道(postScanEnrich)第一行就是「关了就直接返回」,defer 分支以前不看 ⇒ 用户关掉自动补全照样跑。
|
|
481
592
|
*/
|
|
482
593
|
if (opts && opts.deferEnrich && readState().autoEnrich !== false) {
|
|
483
|
-
const only = opts.partial ?
|
|
594
|
+
const only = opts.partial ? batchBoards.filter((b) => b.untrusted !== true).map((b) => b.boardId) : undefined;
|
|
484
595
|
/**
|
|
485
596
|
* ★ 2026-10-17(审查续核 ①):起点/起点图另有「起点收藏与三江字数」开关(qidianEnrich)。
|
|
486
597
|
* 同步通道在 postScanEnrich 里判过它;而 defer 路径的 worker 直接调 enrichBoard → qidianEnrichBoard,
|
|
@@ -498,14 +609,7 @@ export function apply(ctx, config) {
|
|
|
498
609
|
const queued = Object.keys((readState().enrichPending) || {}).length;
|
|
499
610
|
rec.warnings.push('补全已转入后台:' + queued + ' 个榜待补(抓榜数据已可用;面板顶部显示进度)');
|
|
500
611
|
await store.writeScan(rec);
|
|
501
|
-
|
|
502
|
-
const slimD = buildSlim(rec, snaps);
|
|
503
|
-
if (artId !== rec.dataDate)
|
|
504
|
-
slimD.dataDate = artId;
|
|
505
|
-
writeSlim(root, slimD);
|
|
506
|
-
writeReport(root, artId, renderReport(rec, root));
|
|
507
|
-
}
|
|
508
|
-
catch { /* 索引写失败不影响扫描结果 */ }
|
|
612
|
+
writeArtifacts();
|
|
509
613
|
startEnrichWorker('扫描后后台补全');
|
|
510
614
|
/**
|
|
511
615
|
* ★ 关键:不再跑 postScanEnrich(同步阻塞那 5 分钟)。
|
|
@@ -517,7 +621,7 @@ export function apply(ctx, config) {
|
|
|
517
621
|
// 整站扫描后补全「站上不给」的字数/收藏(刺猬猫 2 + 菠萝包 3;单榜扫描不跑)
|
|
518
622
|
if (opts && opts.enrichAfter && !opts.deferEnrich) {
|
|
519
623
|
try {
|
|
520
|
-
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);
|
|
521
625
|
if (res && res.length) {
|
|
522
626
|
const total = res.reduce((n, x) => n + (x.requests || 0), 0);
|
|
523
627
|
/**
|
|
@@ -529,11 +633,7 @@ export function apply(ctx, config) {
|
|
|
529
633
|
const pendingN = res.filter((x) => still[x.boardId]).length;
|
|
530
634
|
rec.warnings.push('补全:' + res.length + ' 个榜跑了补全(' + total + ' 请求)' + (pendingN ? ';其中 ' + pendingN + ' 个仍缺字段,已记待办由定时续跑或在面板点「补齐本榜」' : ''));
|
|
531
635
|
await store.writeScan(rec);
|
|
532
|
-
|
|
533
|
-
if (artId !== rec.dataDate)
|
|
534
|
-
slim1.dataDate = artId;
|
|
535
|
-
writeSlim(root, slim1);
|
|
536
|
-
writeReport(root, artId, renderReport(rec, root));
|
|
636
|
+
writeArtifacts();
|
|
537
637
|
}
|
|
538
638
|
}
|
|
539
639
|
catch (e) {
|
|
@@ -753,16 +853,75 @@ export function apply(ctx, config) {
|
|
|
753
853
|
catch { /* 记日志本身失败也只能吞 */ }
|
|
754
854
|
}
|
|
755
855
|
}
|
|
756
|
-
/**
|
|
757
|
-
|
|
856
|
+
/**
|
|
857
|
+
* 今天算「已经跑过」的站。
|
|
858
|
+
*
|
|
859
|
+
* ★ 2026-10-17(使用者反馈:手动扫一次就把当天剩下的计划吞掉):旧实现只看「今天每个榜都有快照」,
|
|
860
|
+
* 于是 02:19 手动扫过的站,10:40 / 12:40 的计划时刻再也不会跑 —— 那天的「计划数据」其实是
|
|
861
|
+
* 早八竿子打不着的一次手动抓。现在的判据是**时刻**:
|
|
862
|
+
* ① 定时真的跑过(siteLastRun === today)⇒ 算跑过;
|
|
863
|
+
* ② 否则看该站今天最晚一次成功抓取的时刻(boardLastScan.at / 快照 mtime):
|
|
864
|
+
* **≥ 计划时刻**才算跑过(说明计划时刻之后已经有人抓了,不重复请求);
|
|
865
|
+
* 早于计划时刻 ⇒ 到点还要补跑一次。
|
|
866
|
+
* 用「最晚一次」而不是「每个榜都满足」是有意的:某个榜一直失败也不会让整站每 30 秒重跑一次。
|
|
867
|
+
*/
|
|
868
|
+
function sitesRanToday(sites, today, siteTimes) {
|
|
758
869
|
const st = readState();
|
|
759
870
|
const fst = new FileStore(root);
|
|
871
|
+
const times = siteTimes || st.siteTimes || DEFAULT_SITE_TIMES;
|
|
872
|
+
const bls = st.boardLastScan || {};
|
|
760
873
|
const out = [];
|
|
761
874
|
for (const s of sites) {
|
|
762
875
|
const bs = (st.boards || []).filter((b) => siteOfBoard(b) === s);
|
|
763
876
|
if (!bs.length)
|
|
764
877
|
continue;
|
|
765
|
-
if (
|
|
878
|
+
if ((st.siteLastRun || {})[s] === today) {
|
|
879
|
+
out.push(s);
|
|
880
|
+
continue;
|
|
881
|
+
}
|
|
882
|
+
const plan = times[s] || DEFAULT_SITE_TIMES[s] || DEFAULT_FALLBACK_TIME;
|
|
883
|
+
let lastHM = null;
|
|
884
|
+
for (const b of bs) {
|
|
885
|
+
const hit = bls[b];
|
|
886
|
+
let at = hit && hit.date === today && hit.outcome === 'ok' ? String(hit.at) : '';
|
|
887
|
+
if (!at) {
|
|
888
|
+
const mt = fst.snapshotMtime(b, today);
|
|
889
|
+
if (mt)
|
|
890
|
+
at = new Date(mt).toISOString();
|
|
891
|
+
}
|
|
892
|
+
if (!at)
|
|
893
|
+
continue;
|
|
894
|
+
const hm = hmOf(new Date(at));
|
|
895
|
+
if (!lastHM || hm > lastHM)
|
|
896
|
+
lastHM = hm;
|
|
897
|
+
}
|
|
898
|
+
if (lastHM && lastHM >= plan)
|
|
899
|
+
out.push(s);
|
|
900
|
+
}
|
|
901
|
+
return out;
|
|
902
|
+
}
|
|
903
|
+
/**
|
|
904
|
+
* ★ 2026-10-17(使用者问「兜底到底有没有生效」):今天**定时跑过但没跑成**的站。
|
|
905
|
+
*
|
|
906
|
+
* 为什么需要它:跑失败也会写 siteLastRun=today(防 30 秒一次无脑重试),于是 due 永远不会再排它,
|
|
907
|
+
* 而旧兜底分支只认「疑似未刷新」⇒ 一次失败 = 当天彻底没了。现在这类站进兜底队列,22:30 再试一次。
|
|
908
|
+
* 判据:该站实际抓取集内任一榜没有「计划时刻之后」的成功抓取(本地派生榜除外)。
|
|
909
|
+
*/
|
|
910
|
+
function sitesFailedToday(sites, today, siteTimes) {
|
|
911
|
+
const st = readState();
|
|
912
|
+
const times = siteTimes || st.siteTimes || DEFAULT_SITE_TIMES;
|
|
913
|
+
const bls = st.boardLastScan || {};
|
|
914
|
+
const out = [];
|
|
915
|
+
for (const s of sites) {
|
|
916
|
+
if ((st.siteLastRun || {})[s] !== today)
|
|
917
|
+
continue;
|
|
918
|
+
const plan = times[s] || DEFAULT_SITE_TIMES[s] || DEFAULT_FALLBACK_TIME;
|
|
919
|
+
const bs = (st.boards || []).filter((b) => siteOfBoard(b) === s);
|
|
920
|
+
const incomplete = bs.filter((b) => !b.startsWith('fanqie.derived.')).some((b) => {
|
|
921
|
+
const hit = bls[b];
|
|
922
|
+
return !hit || hit.date !== today || hit.outcome !== 'ok' || hmOf(new Date(String(hit.at))) < plan;
|
|
923
|
+
});
|
|
924
|
+
if (incomplete)
|
|
766
925
|
out.push(s);
|
|
767
926
|
}
|
|
768
927
|
return out;
|
|
@@ -780,7 +939,10 @@ export function apply(ctx, config) {
|
|
|
780
939
|
siteTimes: st.siteTimes || DEFAULT_SITE_TIMES,
|
|
781
940
|
siteLastRun: st.siteLastRun || {},
|
|
782
941
|
fallbackTime: st.fallbackTime || DEFAULT_FALLBACK_TIME,
|
|
783
|
-
ranToday: sitesRanToday(sites, localDate(new Date())),
|
|
942
|
+
ranToday: sitesRanToday(sites, localDate(new Date()), st.siteTimes || DEFAULT_SITE_TIMES),
|
|
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()))),
|
|
784
946
|
});
|
|
785
947
|
/**
|
|
786
948
|
* ★ 2026-10-16(疑问「关闭状态为什么显示今天已跑」):把「这个站今天抓过没、谁抓的、几点抓的」
|
|
@@ -846,7 +1008,8 @@ export function apply(ctx, config) {
|
|
|
846
1008
|
siteTimes: st.siteTimes || DEFAULT_SITE_TIMES,
|
|
847
1009
|
siteLastRun: st.siteLastRun || {},
|
|
848
1010
|
fallbackTime: st.fallbackTime || DEFAULT_FALLBACK_TIME,
|
|
849
|
-
ranToday: sitesRanToday(sites, today),
|
|
1011
|
+
ranToday: sitesRanToday(sites, today, st.siteTimes || DEFAULT_SITE_TIMES),
|
|
1012
|
+
failed: sitesFailedToday(sites, today, st.siteTimes || DEFAULT_SITE_TIMES),
|
|
850
1013
|
stale: staleSites,
|
|
851
1014
|
retried: st.siteRetry || {},
|
|
852
1015
|
});
|
|
@@ -861,6 +1024,15 @@ export function apply(ctx, config) {
|
|
|
861
1024
|
const pend = readState().enrichPending || {};
|
|
862
1025
|
if (!Object.keys(pend).length)
|
|
863
1026
|
return;
|
|
1027
|
+
/**
|
|
1028
|
+
* ★ 2026-10-17(面板闪烁:每 30 秒闪一次):
|
|
1029
|
+
* 条目还在、但**当日额度已试满**(tried >= 3)时,工人一启动就只会立刻 giveup,
|
|
1030
|
+
* 而启动时已经先把 enrichRun 写成 active:true ⇒ 面板先显示「补全中 0/1 个榜」,
|
|
1031
|
+
* 3 秒后写回 active:false ⇒ 又变「补全已尽力」。tick 30 秒一次 ⇒ 一直这样跳。
|
|
1032
|
+
* 这里先问「还有没有能续跑的」,没有了就不起工人(不动 enrichRun,横幅保持静止)。
|
|
1033
|
+
*/
|
|
1034
|
+
if (retryablePendingCount() === 0)
|
|
1035
|
+
return;
|
|
864
1036
|
/**
|
|
865
1037
|
* ★ 2026-10-17:交给后台工人(它自己会落进度、逐榜跑、跑完退出),
|
|
866
1038
|
* 不再在这里同步阻塞一个 tick —— tick 每 30 秒一次,阻塞会让别的站到点跑不动。
|
|
@@ -891,6 +1063,15 @@ export function apply(ctx, config) {
|
|
|
891
1063
|
const slr = { ...(st2.siteLastRun || {}) };
|
|
892
1064
|
slr[target] = today;
|
|
893
1065
|
st2.siteLastRun = slr;
|
|
1066
|
+
/**
|
|
1067
|
+
* ★ 2026-10-17:分开记「定时那次成功的时刻」与「最近一次抓取(含手动)」——
|
|
1068
|
+
* 只有日期的话,面板上「今天已抓(手动 11:43)」会让人以为计划 08:30 没跑。
|
|
1069
|
+
*/
|
|
1070
|
+
if (state === 'ok') {
|
|
1071
|
+
const sla = { ...(st2.siteLastTimerAt || {}) };
|
|
1072
|
+
sla[target] = startedAt;
|
|
1073
|
+
st2.siteLastTimerAt = sla;
|
|
1074
|
+
}
|
|
894
1075
|
// ★ C:这是「疑似未刷新」的补跑 ⇒ 记下来,每站每天最多补跑一次
|
|
895
1076
|
if (isRetryRun) {
|
|
896
1077
|
const srt = { ...(st2.siteRetry || {}) };
|
|
@@ -991,6 +1172,87 @@ export function apply(ctx, config) {
|
|
|
991
1172
|
const rec = await st.readScan(date);
|
|
992
1173
|
return rec ? rec.boards.map((b) => b.boardId) : [];
|
|
993
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
|
+
}
|
|
994
1256
|
function diffFor(boardId, date, prevDate, jitter, slimAll) {
|
|
995
1257
|
const store = new FileStore(root);
|
|
996
1258
|
const current = store.readSnapshot(date, boardId);
|
|
@@ -1031,15 +1293,15 @@ export function apply(ctx, config) {
|
|
|
1031
1293
|
// ★ 跨期不可比 ⇒ 调用方必须把变化列判为「不可比」(置空 / 显示「新期」)
|
|
1032
1294
|
crossPeriod: !!d.crossPeriod,
|
|
1033
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 },
|
|
1034
|
-
newEntry: d.newEntry
|
|
1035
|
-
rebound: d.rebound
|
|
1036
|
-
up: d.up
|
|
1037
|
-
down: d.down
|
|
1296
|
+
newEntry: d.newEntry,
|
|
1297
|
+
rebound: d.rebound,
|
|
1298
|
+
up: d.up,
|
|
1299
|
+
down: d.down,
|
|
1038
1300
|
// ★ flat 必须一起回传:面板要按它给「持平」的行标记名次 delta=0。
|
|
1039
1301
|
// 2026-10-15 修:此前 flat 整组丢掉 ⇒ 名次没动/±2 内的行 delta 落 null,
|
|
1040
1302
|
// 「变化」列大面积显示「—」(实测起点 20 行里 18 行是「—」,真实 flat=17)。
|
|
1041
1303
|
flat: d.flat.slice(0, 200),
|
|
1042
|
-
out: d.out
|
|
1304
|
+
out: d.out,
|
|
1043
1305
|
metricDelta: d.metricDelta.slice(0, 20),
|
|
1044
1306
|
};
|
|
1045
1307
|
}
|
|
@@ -1083,8 +1345,16 @@ export function apply(ctx, config) {
|
|
|
1083
1345
|
if (boardId.startsWith('fanqie.derived.'))
|
|
1084
1346
|
return '今日涨幅';
|
|
1085
1347
|
if (meta && meta.metric === 'value') {
|
|
1086
|
-
|
|
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')
|
|
1087
1355
|
return '首订';
|
|
1356
|
+
if (boardId.startsWith('qidiantu.'))
|
|
1357
|
+
return '收藏增量';
|
|
1088
1358
|
if (boardId === 'ciweimao.buy.latest')
|
|
1089
1359
|
return '首订(约)';
|
|
1090
1360
|
return '在读';
|
|
@@ -1150,6 +1420,12 @@ export function apply(ctx, config) {
|
|
|
1150
1420
|
let best = null;
|
|
1151
1421
|
for (const date of dates) {
|
|
1152
1422
|
for (const boardId of boards) {
|
|
1423
|
+
/**
|
|
1424
|
+
* ★ 工作包 A:**被拒快照不参与书签自动更新** —— 否则 tab 里会写进一份
|
|
1425
|
+
* 站方还没刷新的旧值,且之后看起来像「今天的数据」。
|
|
1426
|
+
*/
|
|
1427
|
+
if (isUntrusted(date, boardId))
|
|
1428
|
+
continue;
|
|
1153
1429
|
const snap = store.readSnapshot(date, boardId);
|
|
1154
1430
|
if (!snap || !Array.isArray(snap.rows))
|
|
1155
1431
|
continue;
|
|
@@ -1214,15 +1490,26 @@ export function apply(ctx, config) {
|
|
|
1214
1490
|
const { st, dates, latest } = panelCtx();
|
|
1215
1491
|
const store = new FileStore(root);
|
|
1216
1492
|
const rec = latest ? await store.readScan(latest) : null;
|
|
1493
|
+
/** ★ Spec E:本轮正在跑时的内存记录(见 doScan 顶部注释);结束/抛错即清空 */
|
|
1494
|
+
const liveScan = activeScan || null;
|
|
1217
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;
|
|
1218
1501
|
const slimAll = listSlim(root).map(d => readSlim(root, d)).filter(Boolean);
|
|
1219
1502
|
const rows = [];
|
|
1220
1503
|
for (const boardId of st.boards) {
|
|
1221
1504
|
const meta = boardMeta(boardId);
|
|
1222
1505
|
const b = rec && rec.boards ? rec.boards.find((x) => x.boardId === boardId) : null;
|
|
1506
|
+
const dstate = boardDayState(day, boardId);
|
|
1223
1507
|
const snap = latest ? store.readSnapshot(latest, boardId) : null;
|
|
1224
|
-
|
|
1225
|
-
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;
|
|
1226
1513
|
/**
|
|
1227
1514
|
* ★ 2026-10-17(发布前修):**本地派生榜**(fanqie.derived.*)永远不会有 scan 记录、
|
|
1228
1515
|
* 也不会落快照文件(数据是打开榜页时现算的)⇒ 旧口径「b ? … : snap ? 'ok' : 'missing'」
|
|
@@ -1230,17 +1517,60 @@ export function apply(ctx, config) {
|
|
|
1230
1517
|
* ⇒ 概览永远显示「异常 1 个榜」。它不是「没扫到」,是「不需要扫」:状态直接给 ok。
|
|
1231
1518
|
*/
|
|
1232
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;
|
|
1233
1525
|
rows.push({
|
|
1526
|
+
scheduleState, plannedTime,
|
|
1234
1527
|
boardId,
|
|
1235
1528
|
name: meta.name,
|
|
1236
1529
|
site: meta.site,
|
|
1237
1530
|
siteName: meta.siteName,
|
|
1238
|
-
|
|
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,
|
|
1239
1544
|
up: c ? c.up : null,
|
|
1240
1545
|
newCount: c ? c.new + c.rebound : null,
|
|
1241
1546
|
out: c ? c.out : null,
|
|
1242
|
-
|
|
1243
|
-
|
|
1547
|
+
/**
|
|
1548
|
+
* ★ 2026-10-17(使用者反馈「为什么 20 个榜都显示 08:30」):以前取的是**整轮扫描记录**的
|
|
1549
|
+
* finishedAt ⇒ 所有榜共用同一时刻,看着像「按站抓取没生效」。改成三层:
|
|
1550
|
+
* ① 这一榜自己的 capturedAt(扫描成功时写);② 快照文件 mtime(老数据兜底);
|
|
1551
|
+
* ③ 都没有(本地派生榜 / 今天没抓到的榜)就留 null,面板显示「—」,不再拿别人的时间冒充。
|
|
1552
|
+
*/
|
|
1553
|
+
lastCapture: (function () {
|
|
1554
|
+
// ★ 工作包 A:优先「当天最近一次可信成功」;否则退回本批的 capturedAt / 旧兜底
|
|
1555
|
+
if (dstate && dstate.lastSuccess && dstate.lastSuccess.at)
|
|
1556
|
+
return String(dstate.lastSuccess.at);
|
|
1557
|
+
const own = b && b.capturedAt ? String(b.capturedAt) : null;
|
|
1558
|
+
if (own)
|
|
1559
|
+
return own;
|
|
1560
|
+
if (derived)
|
|
1561
|
+
return null;
|
|
1562
|
+
// ★ 老数据(没有 capturedAt):boardLastScan 里每个榜都记着「哪天的几点抓的、谁抓的」
|
|
1563
|
+
const hit = (st.boardLastScan || {})[boardId];
|
|
1564
|
+
if (hit && hit.date === latest && hit.at)
|
|
1565
|
+
return String(hit.at);
|
|
1566
|
+
const mt = latest ? store.snapshotMtime(boardId, latest) : null;
|
|
1567
|
+
return mt ? new Date(mt).toISOString() : null;
|
|
1568
|
+
})(),
|
|
1569
|
+
note: derived
|
|
1570
|
+
? '本地派生(0 请求,打开榜页时现算)'
|
|
1571
|
+
: dstate
|
|
1572
|
+
? (dstate.reason || (dstate.samePeriod ? '同一期未变化(正常)' : null))
|
|
1573
|
+
: b ? b.reason || null : snap ? null : '今天还没扫(或该榜抓取失败)',
|
|
1244
1574
|
extended: !!meta.extended,
|
|
1245
1575
|
source: meta.source || null,
|
|
1246
1576
|
mainLabel: mainLabelOf(boardId, meta),
|
|
@@ -1257,6 +1587,12 @@ export function apply(ctx, config) {
|
|
|
1257
1587
|
baselineDate: prevDate,
|
|
1258
1588
|
firstEver: dates.length < 2,
|
|
1259
1589
|
counts,
|
|
1590
|
+
/**
|
|
1591
|
+
* ★ 工作包 A:同日数据 revision。扫描/单榜重抓/补全只要改写了快照或隔离标记就会变,
|
|
1592
|
+
* 前端不必等「数据日期」变化才重取(体检 P2-C 的后端侧支撑)。
|
|
1593
|
+
*/
|
|
1594
|
+
revision: dataRevision(latest),
|
|
1595
|
+
dayRevision: day ? day.revision : null,
|
|
1260
1596
|
// 派生榜按设计不进 display ⇒ 不能算进「隐藏 N 个」(它不是被藏起来的,是不需要单独扫)
|
|
1261
1597
|
hiddenCount: rows.filter((r) => !r.displayed && !r.derived).length,
|
|
1262
1598
|
sites: groupBySite(rows).map((s) => ({ ...s, boards: rows.filter((r) => r.site === s.site) })),
|
|
@@ -1290,8 +1626,22 @@ export function apply(ctx, config) {
|
|
|
1290
1626
|
/** ★ 按站分时:现在会跑哪个站、每站上次跑过的数据日(面板「抓什么」页展示) */
|
|
1291
1627
|
schedule: timerPlanNow(),
|
|
1292
1628
|
},
|
|
1293
|
-
|
|
1294
|
-
|
|
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
|
+
}
|
|
1295
1645
|
: null,
|
|
1296
1646
|
defaults: {
|
|
1297
1647
|
scanTime: st.scanTime,
|
|
@@ -1418,7 +1768,9 @@ export function apply(ctx, config) {
|
|
|
1418
1768
|
// 该榜有任何本地数据就出这一列(单日时每行是「1 天」;没有更早数据 ≠ 没历史)
|
|
1419
1769
|
const hasHistory = shouldShowDays(meta.site, datesFor.length);
|
|
1420
1770
|
// 列集合统一过一遍站点口径(起点图不出名次变化、三江不出重复的 daily、刺猬猫首订不出在榜天数)
|
|
1421
|
-
|
|
1771
|
+
// ★ 工作包 A:「有基准」要按**该榜自己**有没有上一次可信快照判(不能拿全局日期数冒充)
|
|
1772
|
+
const boardPrev = previousBoardDate(boardId, date, dates);
|
|
1773
|
+
const columns = applyColumnPolicy(columnsFor(meta, { hasBaseline: !!boardPrev, hasHistory }), boardId);
|
|
1422
1774
|
// 派生榜(番茄在读涨幅榜 / 七日累计):纯本地算,不发请求
|
|
1423
1775
|
if (boardId.startsWith('fanqie.derived.')) {
|
|
1424
1776
|
const read = (b, d) => store.readSnapshot(d, b);
|
|
@@ -1464,7 +1816,41 @@ export function apply(ctx, config) {
|
|
|
1464
1816
|
if (!snap)
|
|
1465
1817
|
return { boardId, meta, columns, dataDate: useDate, dates: datesFor, rows: [], note: '该榜在这天没有快照(也没找到更早的可用快照)' };
|
|
1466
1818
|
const effDate = fallbackFrom || date;
|
|
1467
|
-
|
|
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
|
+
}
|
|
1468
1854
|
const diff = prevDate ? diffFor(boardId, effDate, prevDate) : null;
|
|
1469
1855
|
const byKey = new Map();
|
|
1470
1856
|
if (diff) {
|
|
@@ -1501,9 +1887,16 @@ export function apply(ctx, config) {
|
|
|
1501
1887
|
boardId,
|
|
1502
1888
|
prevDate,
|
|
1503
1889
|
date: effDate,
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
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,
|
|
1507
1900
|
});
|
|
1508
1901
|
const crossPeriod = guard.crossed;
|
|
1509
1902
|
const prevByKey = new Map();
|
|
@@ -1615,7 +2008,7 @@ export function apply(ctx, config) {
|
|
|
1615
2008
|
}
|
|
1616
2009
|
else if (pr != null && cr != null) {
|
|
1617
2010
|
deltaOut = pr - cr;
|
|
1618
|
-
groupOut = dd ? dd.group : (Math.abs(deltaOut) <=
|
|
2011
|
+
groupOut = dd ? dd.group : (Math.abs(deltaOut) <= jitterForBoard(boardId) ? 'flat' : deltaOut > 0 ? 'up' : 'down');
|
|
1619
2012
|
}
|
|
1620
2013
|
else if (typeof (r.extra && r.extra.rankPosDiff) === 'number') {
|
|
1621
2014
|
/**
|
|
@@ -1657,6 +2050,12 @@ export function apply(ctx, config) {
|
|
|
1657
2050
|
rows = rows.slice().sort((a, b) => compareDesc(num(sortVal(a, effSort)), num(sortVal(b, effSort))));
|
|
1658
2051
|
if (limit > 0)
|
|
1659
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);
|
|
1660
2059
|
const statusRow = await store.readScan(effDate);
|
|
1661
2060
|
const brd = statusRow && statusRow.boards ? statusRow.boards.find((x) => x.boardId === boardId) : null;
|
|
1662
2061
|
/**
|
|
@@ -1694,8 +2093,15 @@ export function apply(ctx, config) {
|
|
|
1694
2093
|
dates: datesFor,
|
|
1695
2094
|
baselineDate: diff ? diff.baselineDate : null,
|
|
1696
2095
|
firstEver: diff ? diff.firstEver : true,
|
|
1697
|
-
counts: diff ? diff.counts : null,
|
|
1698
|
-
|
|
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),
|
|
1699
2105
|
enrich: enrichInfo,
|
|
1700
2106
|
rows,
|
|
1701
2107
|
// ★ 跨期当天必须写明「变化列为什么是空的」(口径说明跟着数据一起走,别只活在代码注释里)
|
|
@@ -1718,6 +2124,10 @@ export function apply(ctx, config) {
|
|
|
1718
2124
|
const slimAll = listSlim(root).map(d => readSlim(root, d)).filter(Boolean);
|
|
1719
2125
|
const entries = [];
|
|
1720
2126
|
let firstEver = true;
|
|
2127
|
+
/** ★ 工作包 A:当天有快照但被拒的榜(不让它们的变化漏进来) */
|
|
2128
|
+
const excluded = [];
|
|
2129
|
+
/** ★ 工作包 A:确实没有可比基准的榜(如实说明,而不是静默跳过) */
|
|
2130
|
+
const noBaseline = [];
|
|
1721
2131
|
for (const boardId of st.boards) {
|
|
1722
2132
|
if (!st.display.includes(boardId))
|
|
1723
2133
|
continue;
|
|
@@ -1727,12 +2137,27 @@ export function apply(ctx, config) {
|
|
|
1727
2137
|
if (!snap)
|
|
1728
2138
|
continue;
|
|
1729
2139
|
const meta = boardMeta(boardId);
|
|
1730
|
-
if (
|
|
2140
|
+
if (isUntrusted(useDate, boardId)) {
|
|
2141
|
+
excluded.push({ boardId, reason: '内容不可信(已隔离)' });
|
|
1731
2142
|
continue;
|
|
1732
|
-
|
|
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);
|
|
1733
2154
|
if (d.firstEver)
|
|
1734
2155
|
continue;
|
|
1735
2156
|
firstEver = false;
|
|
2157
|
+
if (d.crossPeriod) {
|
|
2158
|
+
excluded.push({ boardId, reason: '新期不可比(不参与变化)' });
|
|
2159
|
+
continue;
|
|
2160
|
+
}
|
|
1736
2161
|
const push = (group, list, sign) => {
|
|
1737
2162
|
for (const e of list || [])
|
|
1738
2163
|
entries.push({
|
|
@@ -1740,6 +2165,8 @@ export function apply(ctx, config) {
|
|
|
1740
2165
|
siteName: meta.siteName,
|
|
1741
2166
|
boardId,
|
|
1742
2167
|
boardName: meta.name,
|
|
2168
|
+
/** ★ 工作包 A:该榜自己的对比基准日(各榜基准可能不同,顶层的 baselineDate 只是汇总) */
|
|
2169
|
+
baselineDate: d.baselineDate,
|
|
1743
2170
|
group,
|
|
1744
2171
|
title: e.title,
|
|
1745
2172
|
delta: e.delta == null ? '' : sign + String(e.delta),
|
|
@@ -1757,8 +2184,16 @@ export function apply(ctx, config) {
|
|
|
1757
2184
|
baselineDate: prevDate,
|
|
1758
2185
|
firstEver: firstEver && !entries.length,
|
|
1759
2186
|
count: entries.length,
|
|
1760
|
-
sites: groupChanges(entries),
|
|
1761
|
-
|
|
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,
|
|
1762
2197
|
};
|
|
1763
2198
|
}
|
|
1764
2199
|
/** webServer 服务是可选依赖:用依赖光纤做晚绑定(直取 ctx.webServer 在运行时拿不到 —— T12 验收实测 404) */
|
|
@@ -1799,6 +2234,7 @@ export function apply(ctx, config) {
|
|
|
1799
2234
|
for (const [id, meta] of Object.entries(SFACG_BOARDS))
|
|
1800
2235
|
push('sfacg', '菠萝包', '榜单', id, meta.name);
|
|
1801
2236
|
return {
|
|
2237
|
+
defaultCaptures: defaultState().boards,
|
|
1802
2238
|
boards: rows, captures: st.boards, displays: st.display, depths: st.depths || {}, autoEnrich: st.autoEnrich !== false,
|
|
1803
2239
|
// 起点书页补全:开关状态 + 缓存规模(面板据此显示「已缓存 N 本 / 截止时间」)
|
|
1804
2240
|
qidian: { enrich: st.qidianEnrich === true, cache: cacheStats(root), ttlDays: Math.round(QIDIAN_CACHE_TTL_MS / 86400000) },
|
|
@@ -2143,6 +2579,13 @@ export function apply(ctx, config) {
|
|
|
2143
2579
|
function startEnrichWorker(reason) {
|
|
2144
2580
|
if (timerState.enrichWorker)
|
|
2145
2581
|
return;
|
|
2582
|
+
/**
|
|
2583
|
+
* ★ 2026-10-17(同一毛病在另一个入口):任何调用点起工人前都先问「还有可续跑的榜吗」;
|
|
2584
|
+
* 没有就直接返回、**完全不碰 enrichRun** —— 否则每次起跑都会把 active 置真再立刻置假,
|
|
2585
|
+
* 面板横幅就跟着闪(30 秒一轮)。
|
|
2586
|
+
*/
|
|
2587
|
+
if (retryablePendingCount() === 0)
|
|
2588
|
+
return;
|
|
2146
2589
|
timerState.enrichWorker = true;
|
|
2147
2590
|
const startedAt = new Date().toISOString();
|
|
2148
2591
|
const st0 = readState();
|
|
@@ -2201,17 +2644,38 @@ export function apply(ctx, config) {
|
|
|
2201
2644
|
}
|
|
2202
2645
|
}
|
|
2203
2646
|
catch { /* 计数失败不阻塞 */ }
|
|
2647
|
+
let res = null;
|
|
2204
2648
|
try {
|
|
2205
2649
|
/**
|
|
2206
2650
|
* ★ 2026-10-17(审查续核 ⑥):单榜预算与「一轮总闸」取小 ⇒ 一轮真实请求数**不会**超总闸
|
|
2207
2651
|
* (单榜 24/40 都小于总闸 60,所以以前那个「最多冲到 84」其实到不了;写成 min 是让这个界显式)。
|
|
2208
2652
|
*/
|
|
2209
|
-
|
|
2210
|
-
requests += (
|
|
2653
|
+
res = await enrichBoard(b, false, Math.min(ENRICH_RUN_REQUEST_CAP - requests, enrichBudgetForBoard(b)));
|
|
2654
|
+
requests += (res && typeof res.requests === 'number') ? res.requests : 0;
|
|
2211
2655
|
}
|
|
2212
2656
|
catch (e) {
|
|
2213
2657
|
timerLog('后台补全失败 ' + b + ':' + String(e).slice(0, 100));
|
|
2214
2658
|
}
|
|
2659
|
+
/**
|
|
2660
|
+
* ★ 2026-10-17(额度被「能力缺口」烧掉):enrichBoard 明确说「这个榜暂不支持补全」时,
|
|
2661
|
+
* 这一轮**一个真实请求都没打**,不该记一次尝试 —— 否则一个没接上补全通道的榜
|
|
2662
|
+
* 3 次就把当天的额度烧完,从此每天都是「当日已试满、明天再续」,永远补不上。
|
|
2663
|
+
* 把刚才预扣的那一次退回去(日期对得上才退)。
|
|
2664
|
+
*/
|
|
2665
|
+
try {
|
|
2666
|
+
const err01 = res && res.ok === false ? String(res.error || '') : '';
|
|
2667
|
+
if (err01.indexOf('暂不支持') >= 0) {
|
|
2668
|
+
const s5 = readState();
|
|
2669
|
+
const p5 = { ...(s5.enrichPending || {}) };
|
|
2670
|
+
if (p5[b] && p5[b].date === latest && (p5[b].tried || 0) > 0) {
|
|
2671
|
+
p5[b] = { date: latest, tried: (p5[b].tried || 0) - 1 };
|
|
2672
|
+
s5.enrichPending = p5;
|
|
2673
|
+
writeState(s5);
|
|
2674
|
+
timerLog('补全通道不支持,退回一次尝试额度:' + b);
|
|
2675
|
+
}
|
|
2676
|
+
}
|
|
2677
|
+
}
|
|
2678
|
+
catch { /* 退额度失败不影响主流程 */ }
|
|
2215
2679
|
done += 1;
|
|
2216
2680
|
try {
|
|
2217
2681
|
const s3 = readState();
|
|
@@ -2972,7 +3436,7 @@ export function apply(ctx, config) {
|
|
|
2972
3436
|
const armed = syncTimer();
|
|
2973
3437
|
return send(200, {
|
|
2974
3438
|
ok: true, enabled: on, scanTime: stT.scanTime, siteTimes: stT.siteTimes, fallbackTime: stT.fallbackTime,
|
|
2975
|
-
siteLastRun: stT.siteLastRun || {}, plan: timerPlanNow(), armed,
|
|
3439
|
+
siteLastRun: stT.siteLastRun || {}, siteLastTimerAt: stT.siteLastTimerAt || {}, plan: timerPlanNow(), armed,
|
|
2976
3440
|
note: (on
|
|
2977
3441
|
? '定时已开启(按站分时):' + SITE_ORDER.map((s) => (SITE_CN[s] || s) + ' ' + ((stT.siteTimes || {})[s] || '—')).join('、') + ';当天没跑成的站到 ' + (stT.fallbackTime || DEFAULT_FALLBACK_TIME) + ' 补跑'
|
|
2978
3442
|
: '定时扫描已关闭(面板「立刻扫一次」仍可用)') + (on
|
|
@@ -2982,7 +3446,7 @@ export function apply(ctx, config) {
|
|
|
2982
3446
|
}
|
|
2983
3447
|
if (p === '/api/rank-scan/timer-plan') {
|
|
2984
3448
|
// 只读:现在这一刻会跑哪个站 / 为什么没跑(零请求,诊断与集成测试用)
|
|
2985
|
-
return send(200, { ok: true, plan: timerPlanNow(), siteLastRun: readState().siteLastRun || {} });
|
|
3449
|
+
return send(200, { ok: true, plan: timerPlanNow(), siteLastRun: readState().siteLastRun || {}, siteLastTimerAt: readState().siteLastTimerAt || {} });
|
|
2986
3450
|
}
|
|
2987
3451
|
if (p === '/api/rank-scan/depth') {
|
|
2988
3452
|
if (String(req.method || 'GET').toUpperCase() !== 'POST')
|
|
@@ -2997,6 +3461,42 @@ export function apply(ctx, config) {
|
|
|
2997
3461
|
writeState(st2);
|
|
2998
3462
|
return send(200, { ok: true, boardId, depth: n, note: '每榜取数已设为 ' + n + ' 条(下次扫描生效)' });
|
|
2999
3463
|
}
|
|
3464
|
+
/**
|
|
3465
|
+
* ★ 2026-10-17(数据正确性 P0):按日期直查的**落盘闸门**。
|
|
3466
|
+
* 背景:番茄/起点图的榜单页只给「当下」榜面 —— 对历史地址照样返回今天的榜。
|
|
3467
|
+
* 把这种内容写成「那天的快照」不是补数据,是不可回滚的污染:日期一旦被占,
|
|
3468
|
+
* 事后再也分不清哪几天的数据是假的(站点上取不回真值对照)。
|
|
3469
|
+
* 规则:
|
|
3470
|
+
* ① 写「今天」= 与日常扫描同一语义(当下的榜面本来就属于今天)⇒ 放行;
|
|
3471
|
+
* ② 写历史日期必须可核对:适配器用 contentDateFor 声明「数据日期 → 应当看到的内容日期」,
|
|
3472
|
+
* 且实际返回的 contentDate(页面自报日期)必须与之相等;
|
|
3473
|
+
* ③ 站没声明 / 页面没给日期 / 日期对不上 ⇒ 409 拒绝,一个字节都不写。
|
|
3474
|
+
*/
|
|
3475
|
+
const dayWriteVerdict = (site, boardId, date, res) => {
|
|
3476
|
+
const contentDate = (res && (res.contentDate || res.date)) || null;
|
|
3477
|
+
const expected = typeof site.contentDateFor === 'function' ? site.contentDateFor(boardId, date) : null;
|
|
3478
|
+
if (date === localDate(clock.now()))
|
|
3479
|
+
return { ok: true, contentDate: contentDate, expected: expected };
|
|
3480
|
+
if (expected == null) {
|
|
3481
|
+
return {
|
|
3482
|
+
ok: false, code: 'unsupported', contentDate: contentDate, expected: expected,
|
|
3483
|
+
error: '该站不提供可核对的历史榜面(站点对历史地址仍返回当下榜面)⇒ 拒绝把这次抓到的内容写成 ' + date + ' 的快照。历史只能来自当天真实跑过的那次抓取。',
|
|
3484
|
+
};
|
|
3485
|
+
}
|
|
3486
|
+
if (contentDate == null) {
|
|
3487
|
+
return {
|
|
3488
|
+
ok: false, code: 'unverifiable', contentDate: contentDate, expected: expected,
|
|
3489
|
+
error: '站点没给出内容日期,无法确认这份数据属于 ' + date + '(期望内容日期 ' + expected + ')⇒ 拒绝落盘。',
|
|
3490
|
+
};
|
|
3491
|
+
}
|
|
3492
|
+
if (contentDate !== expected) {
|
|
3493
|
+
return {
|
|
3494
|
+
ok: false, code: 'mismatch', contentDate: contentDate, expected: expected,
|
|
3495
|
+
error: '内容日期不一致:站点给的是 ' + contentDate + ',期望 ' + expected + '(数据日期 ' + date + ')⇒ 拒绝落盘(否则就是把当下的榜面记到过去日期名下)。',
|
|
3496
|
+
};
|
|
3497
|
+
}
|
|
3498
|
+
return { ok: true, contentDate: contentDate, expected: expected };
|
|
3499
|
+
};
|
|
3000
3500
|
if (p === '/api/rank-scan/day') {
|
|
3001
3501
|
if (String(req.method || 'GET').toUpperCase() !== 'POST')
|
|
3002
3502
|
return send(405, { error: 'POST only' });
|
|
@@ -3015,21 +3515,30 @@ export function apply(ctx, config) {
|
|
|
3015
3515
|
if (!boardId)
|
|
3016
3516
|
return send(400, { error: 'boardId 必填' });
|
|
3017
3517
|
const stDay = readState();
|
|
3018
|
-
const site =
|
|
3518
|
+
const site = serveSiteFor([boardId], stDay.depths || {})[0];
|
|
3019
3519
|
if (!site)
|
|
3020
3520
|
return send(400, { error: '没有这个站的适配器:' + boardId });
|
|
3021
3521
|
const target = new Date(date + 'T12:00:00+08:00');
|
|
3022
3522
|
const res = await site.fetchBoard(boardId, { now: () => target, signal: new AbortController().signal, requestTimeoutMs: 15000 });
|
|
3523
|
+
// ★ 先判定、后落盘:内容日期对不上时下面这个 writeSnapshot 一步都不该走到
|
|
3524
|
+
const verdict = dayWriteVerdict(site, boardId, date, res);
|
|
3525
|
+
if (!verdict.ok) {
|
|
3526
|
+
return send(409, {
|
|
3527
|
+
ok: false, code: verdict.code, error: verdict.error,
|
|
3528
|
+
boardId, date, contentDate: verdict.contentDate, expected: verdict.expected, saved: false,
|
|
3529
|
+
});
|
|
3530
|
+
}
|
|
3023
3531
|
if (body.save) {
|
|
3024
3532
|
const store3 = new FileStore(root);
|
|
3025
3533
|
await store3.writeSnapshot({ boardId, dataDate: date, metric: res.metric || 'value', rows: res.rows });
|
|
3534
|
+
// ★ 工作包 A:手工补数成功 ⇒ 解除隔离标记并同步当天逐榜状态
|
|
3535
|
+
await trustBoardDay(date, boardId, new Date().toISOString());
|
|
3026
3536
|
}
|
|
3027
|
-
const contentDate = res.date || null;
|
|
3028
3537
|
return send(200, {
|
|
3029
|
-
ok: true, boardId, date, saved: !!body.save, contentDate,
|
|
3538
|
+
ok: true, boardId, date, saved: !!body.save, contentDate: verdict.contentDate, expected: verdict.expected,
|
|
3030
3539
|
rowsAll: res.rows,
|
|
3031
3540
|
count: res.rows.length,
|
|
3032
|
-
note: '直查站点该日期(未落盘)' + (contentDate
|
|
3541
|
+
note: (body.save ? '已抓取并存入本地快照' : '直查站点该日期(未落盘)') + (verdict.contentDate ? ';内容日期 ' + verdict.contentDate : ''),
|
|
3033
3542
|
});
|
|
3034
3543
|
}
|
|
3035
3544
|
if (p === '/api/rank-scan/repair') {
|
|
@@ -3057,18 +3566,22 @@ export function apply(ctx, config) {
|
|
|
3057
3566
|
}
|
|
3058
3567
|
const b = String(body.boardId || 'qidiantu.shouding');
|
|
3059
3568
|
const st4 = readState();
|
|
3060
|
-
const site =
|
|
3569
|
+
const site = serveSiteFor([b], st4.depths || {})[0];
|
|
3061
3570
|
if (!site)
|
|
3062
3571
|
return send(400, { error: '没有这个站的适配器:' + b });
|
|
3063
3572
|
// 关键:clock 用**目标日期**,否则单日榜会取到今天的内容写到昨天名下
|
|
3064
3573
|
const target = new Date(date + 'T01:30:00+08:00');
|
|
3065
3574
|
const res = await site.fetchBoard(b, { now: () => target, signal: new AbortController().signal, requestTimeoutMs: 15000 });
|
|
3066
|
-
|
|
3067
|
-
|
|
3068
|
-
|
|
3575
|
+
// ★ 与 /day 同一道闸门:旧实现的 contentDate 判定形同虚设——没有任何适配器会返回它
|
|
3576
|
+
const verdictR = dayWriteVerdict(site, b, date, res);
|
|
3577
|
+
if (!verdictR.ok) {
|
|
3578
|
+
return send(409, { ok: false, code: verdictR.code, error: verdictR.error, boardId: b, date, contentDate: verdictR.contentDate, expected: verdictR.expected });
|
|
3069
3579
|
}
|
|
3580
|
+
const contentDate = verdictR.contentDate;
|
|
3070
3581
|
const store2 = new FileStore(root);
|
|
3071
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());
|
|
3072
3585
|
// 同步当天 scan.json 的记录,保持「快照 = 记录」
|
|
3073
3586
|
const rec2 = await store2.readScan(date);
|
|
3074
3587
|
if (rec2) {
|
|
@@ -3113,7 +3626,35 @@ export function apply(ctx, config) {
|
|
|
3113
3626
|
const b = q.get('boardId');
|
|
3114
3627
|
if (!b)
|
|
3115
3628
|
return send(400, { error: 'boardId 必填' });
|
|
3116
|
-
|
|
3629
|
+
const resE = await enrichBoard(b, forceQ);
|
|
3630
|
+
/**
|
|
3631
|
+
* ★ 2026-10-17:手动「补全本榜」补齐后要**把待办销掉** —— 以前只有后台工人那一圈会清,
|
|
3632
|
+
* 手动路径补完了待办还挂着 ⇒ 横幅永远显示「补全已尽力 N 个榜」,而数据其实已经齐了。
|
|
3633
|
+
*/
|
|
3634
|
+
try {
|
|
3635
|
+
if (resE && resE.ok) {
|
|
3636
|
+
const snapE = new FileStore(root).readSnapshot(latestDataDate(), b);
|
|
3637
|
+
if (!needsEnrichRows(b, (snapE && snapE.rows) || [])) {
|
|
3638
|
+
clearEnrichPending(b);
|
|
3639
|
+
/**
|
|
3640
|
+
* ★ 2026-10-17:销账之后把「补全进度」也归位 —— 否则 enrichRun 还记着上一轮的
|
|
3641
|
+
* { done:0, total:1 },面板横幅会拿它算出「还剩 1 个榜」,明明已经补齐了。
|
|
3642
|
+
*/
|
|
3643
|
+
try {
|
|
3644
|
+
const s9 = readState();
|
|
3645
|
+
const left9 = Object.keys((s9.enrichPending) || {}).length;
|
|
3646
|
+
if (!left9 && s9.enrichRun) {
|
|
3647
|
+
;
|
|
3648
|
+
s9.enrichRun = { ...s9.enrichRun, done: s9.enrichRun.total || 0, active: false, note: '已补齐(手动补全)' };
|
|
3649
|
+
writeState(s9);
|
|
3650
|
+
}
|
|
3651
|
+
}
|
|
3652
|
+
catch { /* 归位失败不影响本次结果 */ }
|
|
3653
|
+
}
|
|
3654
|
+
}
|
|
3655
|
+
}
|
|
3656
|
+
catch { /* 销账失败不影响本次结果 */ }
|
|
3657
|
+
return send(200, resE);
|
|
3117
3658
|
}
|
|
3118
3659
|
if (p === '/api/rank-scan/qidianEnrich') {
|
|
3119
3660
|
if (String(req.method || 'GET').toUpperCase() !== 'POST')
|
|
@@ -3166,7 +3707,7 @@ export function apply(ctx, config) {
|
|
|
3166
3707
|
if (!got.ok)
|
|
3167
3708
|
return send(409, { error: '已有扫描在进行中,请等它跑完' });
|
|
3168
3709
|
const rec2 = got.value;
|
|
3169
|
-
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) });
|
|
3170
3711
|
}
|
|
3171
3712
|
if (p === '/api/rank-scan/scan') {
|
|
3172
3713
|
if (String(req.method || 'GET').toUpperCase() !== 'POST')
|
|
@@ -3200,9 +3741,22 @@ export function apply(ctx, config) {
|
|
|
3200
3741
|
return send(409, { error: '已有扫描在进行中(定时或另一个手动扫描),请等它跑完' });
|
|
3201
3742
|
const rec = got.value;
|
|
3202
3743
|
const stR = readState();
|
|
3744
|
+
const dayAfter = new FileStore(root).readDayIndex(rec.dataDate);
|
|
3203
3745
|
return send(200, {
|
|
3204
3746
|
ok: true, outcome: rec.outcome, dataDate: rec.dataDate, attempt: rec.attempt, progress: rec.progress,
|
|
3205
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,
|
|
3206
3760
|
enrich: stR.enrichRun ? { ...stR.enrichRun, active: timerState.enrichWorker } : null,
|
|
3207
3761
|
enrichPending: Object.keys((stR.enrichPending) || {}).length,
|
|
3208
3762
|
boards: (rec.boards || []).map((b) => ({ boardId: b.boardId, status: b.status, rows: (b.rows || []).length })),
|