dsh-rank-scan 0.2.3 → 0.2.4
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 +13 -19
- package/lib/client.js +179 -72
- package/lib/index.js +231 -19
- package/lib/index.js.map +1 -1
- package/lib/scan/run.js +1 -1
- package/lib/scan/run.js.map +1 -1
- package/lib/scan/schedule.js +9 -3
- package/lib/scan/schedule.js.map +1 -1
- package/lib/scan/store.js +14 -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/schedule.d.ts +6 -0
- package/lib/types/scan/store.d.ts +6 -0
- package/lib/types/scan/types.d.ts +18 -0
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -73,6 +73,8 @@ function defaultState() {
|
|
|
73
73
|
fallbackTime: DEFAULT_FALLBACK_TIME,
|
|
74
74
|
/** 每站最近一次定时跑过的数据日(跨重启有效,防重复跑) */
|
|
75
75
|
siteLastRun: {},
|
|
76
|
+
/** ★ 2026-10-17:每站**定时**那次跑成功的时刻(ISO)。siteLastRun 只有日期,面板要显示「定时 08:30」 */
|
|
77
|
+
siteLastTimerAt: {},
|
|
76
78
|
/** 每个榜最近一次扫描(含手动):面板可显示「这个榜上次什么时候抓的」 */
|
|
77
79
|
boardLastScan: {},
|
|
78
80
|
/**
|
|
@@ -283,6 +285,13 @@ export function apply(ctx, config) {
|
|
|
283
285
|
out.push(makeSfacgSite({ boards: sc }));
|
|
284
286
|
return out;
|
|
285
287
|
}
|
|
288
|
+
/**
|
|
289
|
+
* ★ 2026-10-17:站点集合的**测试 seam**(cfg.sitesFactory)。只给「按日期直查 / 修复」两条
|
|
290
|
+
* 写盘路径用 —— 单测要能断言「内容日期对不上时一个字节都没写」,不能真连站点。
|
|
291
|
+
*/
|
|
292
|
+
function serveSiteFor(boards, depths = {}) {
|
|
293
|
+
return typeof cfg.sitesFactory === 'function' ? cfg.sitesFactory(boards, depths) : sitesFor(boards, depths);
|
|
294
|
+
}
|
|
286
295
|
/**
|
|
287
296
|
* 扫描后补全:刺猬猫/菠萝包的**榜单页给不出字数/收藏**(刺猬猫完全没有,菠萝包只有前 2 名),
|
|
288
297
|
* 必须进书页取。默认开(state.autoEnrich !== false),只在整站扫描后跑,单榜扫描不跑。
|
|
@@ -753,16 +762,80 @@ export function apply(ctx, config) {
|
|
|
753
762
|
catch { /* 记日志本身失败也只能吞 */ }
|
|
754
763
|
}
|
|
755
764
|
}
|
|
756
|
-
/**
|
|
757
|
-
|
|
765
|
+
/**
|
|
766
|
+
* 今天算「已经跑过」的站。
|
|
767
|
+
*
|
|
768
|
+
* ★ 2026-10-17(使用者反馈:手动扫一次就把当天剩下的计划吞掉):旧实现只看「今天每个榜都有快照」,
|
|
769
|
+
* 于是 02:19 手动扫过的站,10:40 / 12:40 的计划时刻再也不会跑 —— 那天的「计划数据」其实是
|
|
770
|
+
* 早八竿子打不着的一次手动抓。现在的判据是**时刻**:
|
|
771
|
+
* ① 定时真的跑过(siteLastRun === today)⇒ 算跑过;
|
|
772
|
+
* ② 否则看该站今天最晚一次成功抓取的时刻(boardLastScan.at / 快照 mtime):
|
|
773
|
+
* **≥ 计划时刻**才算跑过(说明计划时刻之后已经有人抓了,不重复请求);
|
|
774
|
+
* 早于计划时刻 ⇒ 到点还要补跑一次。
|
|
775
|
+
* 用「最晚一次」而不是「每个榜都满足」是有意的:某个榜一直失败也不会让整站每 30 秒重跑一次。
|
|
776
|
+
*/
|
|
777
|
+
function sitesRanToday(sites, today, siteTimes) {
|
|
758
778
|
const st = readState();
|
|
759
779
|
const fst = new FileStore(root);
|
|
780
|
+
const times = siteTimes || st.siteTimes || DEFAULT_SITE_TIMES;
|
|
781
|
+
const bls = st.boardLastScan || {};
|
|
760
782
|
const out = [];
|
|
761
783
|
for (const s of sites) {
|
|
762
784
|
const bs = (st.boards || []).filter((b) => siteOfBoard(b) === s);
|
|
763
785
|
if (!bs.length)
|
|
764
786
|
continue;
|
|
765
|
-
if (
|
|
787
|
+
if ((st.siteLastRun || {})[s] === today) {
|
|
788
|
+
out.push(s);
|
|
789
|
+
continue;
|
|
790
|
+
}
|
|
791
|
+
const plan = times[s] || DEFAULT_SITE_TIMES[s] || DEFAULT_FALLBACK_TIME;
|
|
792
|
+
let lastHM = null;
|
|
793
|
+
for (const b of bs) {
|
|
794
|
+
const hit = bls[b];
|
|
795
|
+
let at = hit && hit.date === today && hit.outcome === 'ok' ? String(hit.at) : '';
|
|
796
|
+
if (!at) {
|
|
797
|
+
const mt = fst.snapshotMtime(b, today);
|
|
798
|
+
if (mt)
|
|
799
|
+
at = new Date(mt).toISOString();
|
|
800
|
+
}
|
|
801
|
+
if (!at)
|
|
802
|
+
continue;
|
|
803
|
+
const hm = hmOf(new Date(at));
|
|
804
|
+
if (!lastHM || hm > lastHM)
|
|
805
|
+
lastHM = hm;
|
|
806
|
+
}
|
|
807
|
+
if (lastHM && lastHM >= plan)
|
|
808
|
+
out.push(s);
|
|
809
|
+
}
|
|
810
|
+
return out;
|
|
811
|
+
}
|
|
812
|
+
/**
|
|
813
|
+
* ★ 2026-10-17(使用者问「兜底到底有没有生效」):今天**定时跑过但没跑成**的站。
|
|
814
|
+
*
|
|
815
|
+
* 为什么需要它:跑失败也会写 siteLastRun=today(防 30 秒一次无脑重试),于是 due 永远不会再排它,
|
|
816
|
+
* 而旧兜底分支只认「疑似未刷新」⇒ 一次失败 = 当天彻底没了。现在这类站进兜底队列,22:30 再试一次。
|
|
817
|
+
* 判据:该站今天所有榜里,没有任何一次「计划时刻之后」的成功抓取。
|
|
818
|
+
*/
|
|
819
|
+
function sitesFailedToday(sites, today, siteTimes) {
|
|
820
|
+
const st = readState();
|
|
821
|
+
const times = siteTimes || st.siteTimes || DEFAULT_SITE_TIMES;
|
|
822
|
+
const bls = st.boardLastScan || {};
|
|
823
|
+
const out = [];
|
|
824
|
+
for (const s of sites) {
|
|
825
|
+
if ((st.siteLastRun || {})[s] !== today)
|
|
826
|
+
continue;
|
|
827
|
+
const plan = times[s] || DEFAULT_SITE_TIMES[s] || DEFAULT_FALLBACK_TIME;
|
|
828
|
+
const bs = (st.boards || []).filter((b) => siteOfBoard(b) === s);
|
|
829
|
+
let latest = null;
|
|
830
|
+
for (const b of bs) {
|
|
831
|
+
const hit = bls[b];
|
|
832
|
+
if (!hit || hit.date !== today || hit.outcome !== 'ok')
|
|
833
|
+
continue;
|
|
834
|
+
const hm = hmOf(new Date(String(hit.at)));
|
|
835
|
+
if (!latest || hm > latest)
|
|
836
|
+
latest = hm;
|
|
837
|
+
}
|
|
838
|
+
if (!latest || latest < plan)
|
|
766
839
|
out.push(s);
|
|
767
840
|
}
|
|
768
841
|
return out;
|
|
@@ -780,7 +853,8 @@ export function apply(ctx, config) {
|
|
|
780
853
|
siteTimes: st.siteTimes || DEFAULT_SITE_TIMES,
|
|
781
854
|
siteLastRun: st.siteLastRun || {},
|
|
782
855
|
fallbackTime: st.fallbackTime || DEFAULT_FALLBACK_TIME,
|
|
783
|
-
ranToday: sitesRanToday(sites, localDate(new Date())),
|
|
856
|
+
ranToday: sitesRanToday(sites, localDate(new Date()), st.siteTimes || DEFAULT_SITE_TIMES),
|
|
857
|
+
failed: sitesFailedToday(sites, localDate(new Date()), st.siteTimes || DEFAULT_SITE_TIMES),
|
|
784
858
|
});
|
|
785
859
|
/**
|
|
786
860
|
* ★ 2026-10-16(疑问「关闭状态为什么显示今天已跑」):把「这个站今天抓过没、谁抓的、几点抓的」
|
|
@@ -846,7 +920,8 @@ export function apply(ctx, config) {
|
|
|
846
920
|
siteTimes: st.siteTimes || DEFAULT_SITE_TIMES,
|
|
847
921
|
siteLastRun: st.siteLastRun || {},
|
|
848
922
|
fallbackTime: st.fallbackTime || DEFAULT_FALLBACK_TIME,
|
|
849
|
-
ranToday: sitesRanToday(sites, today),
|
|
923
|
+
ranToday: sitesRanToday(sites, today, st.siteTimes || DEFAULT_SITE_TIMES),
|
|
924
|
+
failed: sitesFailedToday(sites, today, st.siteTimes || DEFAULT_SITE_TIMES),
|
|
850
925
|
stale: staleSites,
|
|
851
926
|
retried: st.siteRetry || {},
|
|
852
927
|
});
|
|
@@ -861,6 +936,15 @@ export function apply(ctx, config) {
|
|
|
861
936
|
const pend = readState().enrichPending || {};
|
|
862
937
|
if (!Object.keys(pend).length)
|
|
863
938
|
return;
|
|
939
|
+
/**
|
|
940
|
+
* ★ 2026-10-17(面板闪烁:每 30 秒闪一次):
|
|
941
|
+
* 条目还在、但**当日额度已试满**(tried >= 3)时,工人一启动就只会立刻 giveup,
|
|
942
|
+
* 而启动时已经先把 enrichRun 写成 active:true ⇒ 面板先显示「补全中 0/1 个榜」,
|
|
943
|
+
* 3 秒后写回 active:false ⇒ 又变「补全已尽力」。tick 30 秒一次 ⇒ 一直这样跳。
|
|
944
|
+
* 这里先问「还有没有能续跑的」,没有了就不起工人(不动 enrichRun,横幅保持静止)。
|
|
945
|
+
*/
|
|
946
|
+
if (retryablePendingCount() === 0)
|
|
947
|
+
return;
|
|
864
948
|
/**
|
|
865
949
|
* ★ 2026-10-17:交给后台工人(它自己会落进度、逐榜跑、跑完退出),
|
|
866
950
|
* 不再在这里同步阻塞一个 tick —— tick 每 30 秒一次,阻塞会让别的站到点跑不动。
|
|
@@ -891,6 +975,15 @@ export function apply(ctx, config) {
|
|
|
891
975
|
const slr = { ...(st2.siteLastRun || {}) };
|
|
892
976
|
slr[target] = today;
|
|
893
977
|
st2.siteLastRun = slr;
|
|
978
|
+
/**
|
|
979
|
+
* ★ 2026-10-17:分开记「定时那次成功的时刻」与「最近一次抓取(含手动)」——
|
|
980
|
+
* 只有日期的话,面板上「今天已抓(手动 11:43)」会让人以为计划 08:30 没跑。
|
|
981
|
+
*/
|
|
982
|
+
if (state === 'ok') {
|
|
983
|
+
const sla = { ...(st2.siteLastTimerAt || {}) };
|
|
984
|
+
sla[target] = startedAt;
|
|
985
|
+
st2.siteLastTimerAt = sla;
|
|
986
|
+
}
|
|
894
987
|
// ★ C:这是「疑似未刷新」的补跑 ⇒ 记下来,每站每天最多补跑一次
|
|
895
988
|
if (isRetryRun) {
|
|
896
989
|
const srt = { ...(st2.siteRetry || {}) };
|
|
@@ -1239,7 +1332,25 @@ export function apply(ctx, config) {
|
|
|
1239
1332
|
up: c ? c.up : null,
|
|
1240
1333
|
newCount: c ? c.new + c.rebound : null,
|
|
1241
1334
|
out: c ? c.out : null,
|
|
1242
|
-
|
|
1335
|
+
/**
|
|
1336
|
+
* ★ 2026-10-17(使用者反馈「为什么 20 个榜都显示 08:30」):以前取的是**整轮扫描记录**的
|
|
1337
|
+
* finishedAt ⇒ 所有榜共用同一时刻,看着像「按站抓取没生效」。改成三层:
|
|
1338
|
+
* ① 这一榜自己的 capturedAt(扫描成功时写);② 快照文件 mtime(老数据兜底);
|
|
1339
|
+
* ③ 都没有(本地派生榜 / 今天没抓到的榜)就留 null,面板显示「—」,不再拿别人的时间冒充。
|
|
1340
|
+
*/
|
|
1341
|
+
lastCapture: (function () {
|
|
1342
|
+
const own = b && b.capturedAt ? String(b.capturedAt) : null;
|
|
1343
|
+
if (own)
|
|
1344
|
+
return own;
|
|
1345
|
+
if (derived)
|
|
1346
|
+
return null;
|
|
1347
|
+
// ★ 老数据(没有 capturedAt):boardLastScan 里每个榜都记着「哪天的几点抓的、谁抓的」
|
|
1348
|
+
const hit = (st.boardLastScan || {})[boardId];
|
|
1349
|
+
if (hit && hit.date === latest && hit.at)
|
|
1350
|
+
return String(hit.at);
|
|
1351
|
+
const mt = latest ? store.snapshotMtime(boardId, latest) : null;
|
|
1352
|
+
return mt ? new Date(mt).toISOString() : null;
|
|
1353
|
+
})(),
|
|
1243
1354
|
note: derived ? '本地派生(0 请求,打开榜页时现算)' : b ? b.reason || null : snap ? null : '今天还没扫(或该榜抓取失败)',
|
|
1244
1355
|
extended: !!meta.extended,
|
|
1245
1356
|
source: meta.source || null,
|
|
@@ -2143,6 +2254,13 @@ export function apply(ctx, config) {
|
|
|
2143
2254
|
function startEnrichWorker(reason) {
|
|
2144
2255
|
if (timerState.enrichWorker)
|
|
2145
2256
|
return;
|
|
2257
|
+
/**
|
|
2258
|
+
* ★ 2026-10-17(同一毛病在另一个入口):任何调用点起工人前都先问「还有可续跑的榜吗」;
|
|
2259
|
+
* 没有就直接返回、**完全不碰 enrichRun** —— 否则每次起跑都会把 active 置真再立刻置假,
|
|
2260
|
+
* 面板横幅就跟着闪(30 秒一轮)。
|
|
2261
|
+
*/
|
|
2262
|
+
if (retryablePendingCount() === 0)
|
|
2263
|
+
return;
|
|
2146
2264
|
timerState.enrichWorker = true;
|
|
2147
2265
|
const startedAt = new Date().toISOString();
|
|
2148
2266
|
const st0 = readState();
|
|
@@ -2201,17 +2319,38 @@ export function apply(ctx, config) {
|
|
|
2201
2319
|
}
|
|
2202
2320
|
}
|
|
2203
2321
|
catch { /* 计数失败不阻塞 */ }
|
|
2322
|
+
let res = null;
|
|
2204
2323
|
try {
|
|
2205
2324
|
/**
|
|
2206
2325
|
* ★ 2026-10-17(审查续核 ⑥):单榜预算与「一轮总闸」取小 ⇒ 一轮真实请求数**不会**超总闸
|
|
2207
2326
|
* (单榜 24/40 都小于总闸 60,所以以前那个「最多冲到 84」其实到不了;写成 min 是让这个界显式)。
|
|
2208
2327
|
*/
|
|
2209
|
-
|
|
2210
|
-
requests += (
|
|
2328
|
+
res = await enrichBoard(b, false, Math.min(ENRICH_RUN_REQUEST_CAP - requests, enrichBudgetForBoard(b)));
|
|
2329
|
+
requests += (res && typeof res.requests === 'number') ? res.requests : 0;
|
|
2211
2330
|
}
|
|
2212
2331
|
catch (e) {
|
|
2213
2332
|
timerLog('后台补全失败 ' + b + ':' + String(e).slice(0, 100));
|
|
2214
2333
|
}
|
|
2334
|
+
/**
|
|
2335
|
+
* ★ 2026-10-17(额度被「能力缺口」烧掉):enrichBoard 明确说「这个榜暂不支持补全」时,
|
|
2336
|
+
* 这一轮**一个真实请求都没打**,不该记一次尝试 —— 否则一个没接上补全通道的榜
|
|
2337
|
+
* 3 次就把当天的额度烧完,从此每天都是「当日已试满、明天再续」,永远补不上。
|
|
2338
|
+
* 把刚才预扣的那一次退回去(日期对得上才退)。
|
|
2339
|
+
*/
|
|
2340
|
+
try {
|
|
2341
|
+
const err01 = res && res.ok === false ? String(res.error || '') : '';
|
|
2342
|
+
if (err01.indexOf('暂不支持') >= 0) {
|
|
2343
|
+
const s5 = readState();
|
|
2344
|
+
const p5 = { ...(s5.enrichPending || {}) };
|
|
2345
|
+
if (p5[b] && p5[b].date === latest && (p5[b].tried || 0) > 0) {
|
|
2346
|
+
p5[b] = { date: latest, tried: (p5[b].tried || 0) - 1 };
|
|
2347
|
+
s5.enrichPending = p5;
|
|
2348
|
+
writeState(s5);
|
|
2349
|
+
timerLog('补全通道不支持,退回一次尝试额度:' + b);
|
|
2350
|
+
}
|
|
2351
|
+
}
|
|
2352
|
+
}
|
|
2353
|
+
catch { /* 退额度失败不影响主流程 */ }
|
|
2215
2354
|
done += 1;
|
|
2216
2355
|
try {
|
|
2217
2356
|
const s3 = readState();
|
|
@@ -2972,7 +3111,7 @@ export function apply(ctx, config) {
|
|
|
2972
3111
|
const armed = syncTimer();
|
|
2973
3112
|
return send(200, {
|
|
2974
3113
|
ok: true, enabled: on, scanTime: stT.scanTime, siteTimes: stT.siteTimes, fallbackTime: stT.fallbackTime,
|
|
2975
|
-
siteLastRun: stT.siteLastRun || {}, plan: timerPlanNow(), armed,
|
|
3114
|
+
siteLastRun: stT.siteLastRun || {}, siteLastTimerAt: stT.siteLastTimerAt || {}, plan: timerPlanNow(), armed,
|
|
2976
3115
|
note: (on
|
|
2977
3116
|
? '定时已开启(按站分时):' + SITE_ORDER.map((s) => (SITE_CN[s] || s) + ' ' + ((stT.siteTimes || {})[s] || '—')).join('、') + ';当天没跑成的站到 ' + (stT.fallbackTime || DEFAULT_FALLBACK_TIME) + ' 补跑'
|
|
2978
3117
|
: '定时扫描已关闭(面板「立刻扫一次」仍可用)') + (on
|
|
@@ -2982,7 +3121,7 @@ export function apply(ctx, config) {
|
|
|
2982
3121
|
}
|
|
2983
3122
|
if (p === '/api/rank-scan/timer-plan') {
|
|
2984
3123
|
// 只读:现在这一刻会跑哪个站 / 为什么没跑(零请求,诊断与集成测试用)
|
|
2985
|
-
return send(200, { ok: true, plan: timerPlanNow(), siteLastRun: readState().siteLastRun || {} });
|
|
3124
|
+
return send(200, { ok: true, plan: timerPlanNow(), siteLastRun: readState().siteLastRun || {}, siteLastTimerAt: readState().siteLastTimerAt || {} });
|
|
2986
3125
|
}
|
|
2987
3126
|
if (p === '/api/rank-scan/depth') {
|
|
2988
3127
|
if (String(req.method || 'GET').toUpperCase() !== 'POST')
|
|
@@ -2997,6 +3136,42 @@ export function apply(ctx, config) {
|
|
|
2997
3136
|
writeState(st2);
|
|
2998
3137
|
return send(200, { ok: true, boardId, depth: n, note: '每榜取数已设为 ' + n + ' 条(下次扫描生效)' });
|
|
2999
3138
|
}
|
|
3139
|
+
/**
|
|
3140
|
+
* ★ 2026-10-17(数据正确性 P0):按日期直查的**落盘闸门**。
|
|
3141
|
+
* 背景:番茄/起点图的榜单页只给「当下」榜面 —— 对历史地址照样返回今天的榜。
|
|
3142
|
+
* 把这种内容写成「那天的快照」不是补数据,是不可回滚的污染:日期一旦被占,
|
|
3143
|
+
* 事后再也分不清哪几天的数据是假的(站点上取不回真值对照)。
|
|
3144
|
+
* 规则:
|
|
3145
|
+
* ① 写「今天」= 与日常扫描同一语义(当下的榜面本来就属于今天)⇒ 放行;
|
|
3146
|
+
* ② 写历史日期必须可核对:适配器用 contentDateFor 声明「数据日期 → 应当看到的内容日期」,
|
|
3147
|
+
* 且实际返回的 contentDate(页面自报日期)必须与之相等;
|
|
3148
|
+
* ③ 站没声明 / 页面没给日期 / 日期对不上 ⇒ 409 拒绝,一个字节都不写。
|
|
3149
|
+
*/
|
|
3150
|
+
const dayWriteVerdict = (site, boardId, date, res) => {
|
|
3151
|
+
const contentDate = (res && (res.contentDate || res.date)) || null;
|
|
3152
|
+
const expected = typeof site.contentDateFor === 'function' ? site.contentDateFor(boardId, date) : null;
|
|
3153
|
+
if (date === localDate(clock.now()))
|
|
3154
|
+
return { ok: true, contentDate: contentDate, expected: expected };
|
|
3155
|
+
if (expected == null) {
|
|
3156
|
+
return {
|
|
3157
|
+
ok: false, code: 'unsupported', contentDate: contentDate, expected: expected,
|
|
3158
|
+
error: '该站不提供可核对的历史榜面(站点对历史地址仍返回当下榜面)⇒ 拒绝把这次抓到的内容写成 ' + date + ' 的快照。历史只能来自当天真实跑过的那次抓取。',
|
|
3159
|
+
};
|
|
3160
|
+
}
|
|
3161
|
+
if (contentDate == null) {
|
|
3162
|
+
return {
|
|
3163
|
+
ok: false, code: 'unverifiable', contentDate: contentDate, expected: expected,
|
|
3164
|
+
error: '站点没给出内容日期,无法确认这份数据属于 ' + date + '(期望内容日期 ' + expected + ')⇒ 拒绝落盘。',
|
|
3165
|
+
};
|
|
3166
|
+
}
|
|
3167
|
+
if (contentDate !== expected) {
|
|
3168
|
+
return {
|
|
3169
|
+
ok: false, code: 'mismatch', contentDate: contentDate, expected: expected,
|
|
3170
|
+
error: '内容日期不一致:站点给的是 ' + contentDate + ',期望 ' + expected + '(数据日期 ' + date + ')⇒ 拒绝落盘(否则就是把当下的榜面记到过去日期名下)。',
|
|
3171
|
+
};
|
|
3172
|
+
}
|
|
3173
|
+
return { ok: true, contentDate: contentDate, expected: expected };
|
|
3174
|
+
};
|
|
3000
3175
|
if (p === '/api/rank-scan/day') {
|
|
3001
3176
|
if (String(req.method || 'GET').toUpperCase() !== 'POST')
|
|
3002
3177
|
return send(405, { error: 'POST only' });
|
|
@@ -3015,21 +3190,28 @@ export function apply(ctx, config) {
|
|
|
3015
3190
|
if (!boardId)
|
|
3016
3191
|
return send(400, { error: 'boardId 必填' });
|
|
3017
3192
|
const stDay = readState();
|
|
3018
|
-
const site =
|
|
3193
|
+
const site = serveSiteFor([boardId], stDay.depths || {})[0];
|
|
3019
3194
|
if (!site)
|
|
3020
3195
|
return send(400, { error: '没有这个站的适配器:' + boardId });
|
|
3021
3196
|
const target = new Date(date + 'T12:00:00+08:00');
|
|
3022
3197
|
const res = await site.fetchBoard(boardId, { now: () => target, signal: new AbortController().signal, requestTimeoutMs: 15000 });
|
|
3198
|
+
// ★ 先判定、后落盘:内容日期对不上时下面这个 writeSnapshot 一步都不该走到
|
|
3199
|
+
const verdict = dayWriteVerdict(site, boardId, date, res);
|
|
3200
|
+
if (!verdict.ok) {
|
|
3201
|
+
return send(409, {
|
|
3202
|
+
ok: false, code: verdict.code, error: verdict.error,
|
|
3203
|
+
boardId, date, contentDate: verdict.contentDate, expected: verdict.expected, saved: false,
|
|
3204
|
+
});
|
|
3205
|
+
}
|
|
3023
3206
|
if (body.save) {
|
|
3024
3207
|
const store3 = new FileStore(root);
|
|
3025
3208
|
await store3.writeSnapshot({ boardId, dataDate: date, metric: res.metric || 'value', rows: res.rows });
|
|
3026
3209
|
}
|
|
3027
|
-
const contentDate = res.date || null;
|
|
3028
3210
|
return send(200, {
|
|
3029
|
-
ok: true, boardId, date, saved: !!body.save, contentDate,
|
|
3211
|
+
ok: true, boardId, date, saved: !!body.save, contentDate: verdict.contentDate, expected: verdict.expected,
|
|
3030
3212
|
rowsAll: res.rows,
|
|
3031
3213
|
count: res.rows.length,
|
|
3032
|
-
note: '直查站点该日期(未落盘)' + (contentDate
|
|
3214
|
+
note: (body.save ? '已抓取并存入本地快照' : '直查站点该日期(未落盘)') + (verdict.contentDate ? ';内容日期 ' + verdict.contentDate : ''),
|
|
3033
3215
|
});
|
|
3034
3216
|
}
|
|
3035
3217
|
if (p === '/api/rank-scan/repair') {
|
|
@@ -3057,16 +3239,18 @@ export function apply(ctx, config) {
|
|
|
3057
3239
|
}
|
|
3058
3240
|
const b = String(body.boardId || 'qidiantu.shouding');
|
|
3059
3241
|
const st4 = readState();
|
|
3060
|
-
const site =
|
|
3242
|
+
const site = serveSiteFor([b], st4.depths || {})[0];
|
|
3061
3243
|
if (!site)
|
|
3062
3244
|
return send(400, { error: '没有这个站的适配器:' + b });
|
|
3063
3245
|
// 关键:clock 用**目标日期**,否则单日榜会取到今天的内容写到昨天名下
|
|
3064
3246
|
const target = new Date(date + 'T01:30:00+08:00');
|
|
3065
3247
|
const res = await site.fetchBoard(b, { now: () => target, signal: new AbortController().signal, requestTimeoutMs: 15000 });
|
|
3066
|
-
|
|
3067
|
-
|
|
3068
|
-
|
|
3248
|
+
// ★ 与 /day 同一道闸门:旧实现的 contentDate 判定形同虚设——没有任何适配器会返回它
|
|
3249
|
+
const verdictR = dayWriteVerdict(site, b, date, res);
|
|
3250
|
+
if (!verdictR.ok) {
|
|
3251
|
+
return send(409, { ok: false, code: verdictR.code, error: verdictR.error, boardId: b, date, contentDate: verdictR.contentDate, expected: verdictR.expected });
|
|
3069
3252
|
}
|
|
3253
|
+
const contentDate = verdictR.contentDate;
|
|
3070
3254
|
const store2 = new FileStore(root);
|
|
3071
3255
|
await store2.writeSnapshot({ boardId: b, dataDate: date, metric: res.metric || 'value', rows: res.rows });
|
|
3072
3256
|
// 同步当天 scan.json 的记录,保持「快照 = 记录」
|
|
@@ -3113,7 +3297,35 @@ export function apply(ctx, config) {
|
|
|
3113
3297
|
const b = q.get('boardId');
|
|
3114
3298
|
if (!b)
|
|
3115
3299
|
return send(400, { error: 'boardId 必填' });
|
|
3116
|
-
|
|
3300
|
+
const resE = await enrichBoard(b, forceQ);
|
|
3301
|
+
/**
|
|
3302
|
+
* ★ 2026-10-17:手动「补全本榜」补齐后要**把待办销掉** —— 以前只有后台工人那一圈会清,
|
|
3303
|
+
* 手动路径补完了待办还挂着 ⇒ 横幅永远显示「补全已尽力 N 个榜」,而数据其实已经齐了。
|
|
3304
|
+
*/
|
|
3305
|
+
try {
|
|
3306
|
+
if (resE && resE.ok) {
|
|
3307
|
+
const snapE = new FileStore(root).readSnapshot(latestDataDate(), b);
|
|
3308
|
+
if (!needsEnrichRows(b, (snapE && snapE.rows) || [])) {
|
|
3309
|
+
clearEnrichPending(b);
|
|
3310
|
+
/**
|
|
3311
|
+
* ★ 2026-10-17:销账之后把「补全进度」也归位 —— 否则 enrichRun 还记着上一轮的
|
|
3312
|
+
* { done:0, total:1 },面板横幅会拿它算出「还剩 1 个榜」,明明已经补齐了。
|
|
3313
|
+
*/
|
|
3314
|
+
try {
|
|
3315
|
+
const s9 = readState();
|
|
3316
|
+
const left9 = Object.keys((s9.enrichPending) || {}).length;
|
|
3317
|
+
if (!left9 && s9.enrichRun) {
|
|
3318
|
+
;
|
|
3319
|
+
s9.enrichRun = { ...s9.enrichRun, done: s9.enrichRun.total || 0, active: false, note: '已补齐(手动补全)' };
|
|
3320
|
+
writeState(s9);
|
|
3321
|
+
}
|
|
3322
|
+
}
|
|
3323
|
+
catch { /* 归位失败不影响本次结果 */ }
|
|
3324
|
+
}
|
|
3325
|
+
}
|
|
3326
|
+
}
|
|
3327
|
+
catch { /* 销账失败不影响本次结果 */ }
|
|
3328
|
+
return send(200, resE);
|
|
3117
3329
|
}
|
|
3118
3330
|
if (p === '/api/rank-scan/qidianEnrich') {
|
|
3119
3331
|
if (String(req.method || 'GET').toUpperCase() !== 'POST')
|