dsh-rank-scan 0.6.2 → 0.6.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 +4 -4
- package/lib/index.js +134 -16
- package/lib/index.js.map +1 -1
- package/lib/scan/freshness.js +55 -5
- package/lib/scan/freshness.js.map +1 -1
- package/lib/scan/guard.js +5 -0
- package/lib/scan/guard.js.map +1 -1
- package/lib/scan/schedule.js +41 -8
- package/lib/scan/schedule.js.map +1 -1
- package/lib/scan/store.js +19 -2
- package/lib/scan/store.js.map +1 -1
- package/lib/sites/qidiantu.js +4 -1
- package/lib/sites/qidiantu.js.map +1 -1
- package/lib/types/scan/freshness.d.ts +31 -0
- package/lib/types/scan/schedule.d.ts +21 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@ DeepSeek Harness 扫榜插件:定时 + 按需采集多站小说榜单,算变
|
|
|
18
18
|
|
|
19
19
|
```sh
|
|
20
20
|
dsh plugin --profile desktop add github:kilo-s/dsh-rank-scan
|
|
21
|
-
# 钉版本:github:kilo-s/dsh-rank-scan#v0.6.
|
|
21
|
+
# 钉版本:github:kilo-s/dsh-rank-scan#v0.6.4
|
|
22
22
|
```
|
|
23
23
|
|
|
24
24
|
仓库不含编译产物,这条命令会在安装时现场构建 `lib/`。首次可能被 pnpm 拦下构建脚本(它会打印要放行的键,加进 `allowBuilds` 后重跑即可),细节见 [docs/DEVELOPMENT.md](docs/DEVELOPMENT.md)。
|
|
@@ -37,14 +37,14 @@ dsh plugin --profile desktop add "<tgz 的完整路径>"
|
|
|
37
37
|
|
|
38
38
|
```sh
|
|
39
39
|
dsh plugin --profile desktop add dsh-rank-scan
|
|
40
|
-
# 钉版本:dsh-rank-scan@0.6.
|
|
40
|
+
# 钉版本:dsh-rank-scan@0.6.4
|
|
41
41
|
```
|
|
42
42
|
|
|
43
43
|
npm 上那份是 CI 从源码构建的(包内自带 `lib/`,发布带 `--provenance` 签名)——装的时候不用再编译,也不会被 pnpm 的 `allowBuilds` 拦下。面板的「检查更新」读的就是 npm 上的版本号。
|
|
44
44
|
|
|
45
45
|
**验证**:重开 DSH 后左侧栏会话列表下方应出现「扫榜」入口;或访问 `http://127.0.0.1:19387/api/rank-scan/health`,返回 `{ok:true,...}` 即通。
|
|
46
46
|
|
|
47
|
-
**更新**:重跑安装命令即可(链接直装取最新 `main`,registry 装取最新发布版;本版本为 **0.6.
|
|
47
|
+
**更新**:重跑安装命令即可(链接直装取最新 `main`,registry 装取最新发布版;本版本为 **0.6.4**);面板「设置」页底部会读 npm 上的版本号提示有没有新版,装了 [dsh-market](https://github.com/dsh-market/dsh-market) 的话还能就地更新。
|
|
48
48
|
|
|
49
49
|
**卸载**:`dsh plugin --profile desktop remove dsh-rank-scan`。数据目录 `~/.dsh/data/rank-scan` 会保留,要彻底清理自行删除;脚本化卸载与 patch 安全口径见 [docs/DEVELOPMENT.md](docs/DEVELOPMENT.md)。
|
|
50
50
|
|
|
@@ -85,7 +85,7 @@ npm 上那份是 CI 从源码构建的(包内自带 `lib/`,发布带 `--prov
|
|
|
85
85
|
### 定时扫描
|
|
86
86
|
|
|
87
87
|
- **默认开启**,但**安装当天不自动跑**(次日按时刻跑);面板「设置」页可关掉或改时刻,关掉后重载仍保留。
|
|
88
|
-
- 按站分时:每个站可以有自己的抓取时刻,兜底时刻 22:30
|
|
88
|
+
- 按站分时:每个站可以有自己的抓取时刻,兜底时刻 22:30。新安装的默认时刻:起点 01:30、番茄 08:30、刺猬猫 10:40、菠萝包 14:30、起点图 21:30(2026-10-30 起)。已有安装保留已保存的时刻,升级不覆盖 —— 只有某个站仍是旧默认值(菠萝包 09:30 / 起点图 12:40)时才随升级自动改用新时刻。
|
|
89
89
|
- 同一时刻只有一轮扫描(定时与手动共用一把锁,冲突时手动请求返回 409)。
|
|
90
90
|
- 诊断日志:`<dataDir>/state/timer.log`(接线 / 迁移 / 每轮开始结束各一行)。
|
|
91
91
|
|
package/lib/index.js
CHANGED
|
@@ -39,7 +39,7 @@ import { minRequestIntervalMs, setMinRequestIntervalMs as applyRequestInterval }
|
|
|
39
39
|
*/
|
|
40
40
|
import { readOwnVersion, probeMarket, fetchNpmLatest, normalizeOperation, buildUpdateView } from './scan/update.js';
|
|
41
41
|
import { assertDataDate, dirSize, historyFor, listDataDates, listSlim, normalizeRetention, previousDataDate, readSlim, runRetention, sweepTmp, writeReport, writeSlim, } from './scan/files.js';
|
|
42
|
-
import { DEFAULT_FALLBACK_TIME, DEFAULT_SITE_TIMES, hmOf, planSiteRuns, SITE_ORDER, siteOfBoard, validTime } from './scan/schedule.js';
|
|
42
|
+
import { DEFAULT_FALLBACK_TIME, DEFAULT_SITE_TIMES, hmOf, planSiteRuns, RETRY_COOLDOWN_MIN, SITE_ORDER, siteOfBoard, validTime } from './scan/schedule.js';
|
|
43
43
|
import { cacheStats, cachedBook, clearCache, putCachedBooks } from './scan/qidian-cache.js';
|
|
44
44
|
import { assignCachedStats, cacheStats as bookCacheStats, cachedEntry, putEntries } from './scan/book-cache.js';
|
|
45
45
|
export const name = 'dsh-rank-scan';
|
|
@@ -63,6 +63,21 @@ export const name = 'dsh-rank-scan';
|
|
|
63
63
|
*/
|
|
64
64
|
export const inject = ['timer', 'webServer'];
|
|
65
65
|
const pad2 = (n) => String(n).padStart(2, '0');
|
|
66
|
+
/**
|
|
67
|
+
* ★ 2026-10-30(review 修):**配置架构版本号只在这里定义一次**。
|
|
68
|
+
* 以前迁移写 7、recordRun 仍写 6 ⇒ 每轮定时跑完都把版本降回 6,下次启动又跑一遍 v7 迁移;
|
|
69
|
+
* 使用者若刻意把菠萝包调回 09:30,会被再改掉一次 —— 与「调过的不动」自相矛盾。
|
|
70
|
+
*/
|
|
71
|
+
const TIMER_SCHEMA_V = 7;
|
|
72
|
+
/**
|
|
73
|
+
* ★ 2026-11-02(审查 M1):boardId 会直入快照路径拼接
|
|
74
|
+
* (store.readSnapshot/writeSnapshot 的 join(root, dataDate, boardId + '.json')),
|
|
75
|
+
* 而它来自 HTTP query/body 与持久化配置 —— 未校验时 '../../x' 可读出数据根之外的任意 .json,
|
|
76
|
+
* /select 还会把恶意 boardId 持久化(之后每次 /overview 自动触发一次穿越读)。
|
|
77
|
+
* 只放行「字母数字开头 + 字母数字/./_/-」⇒ 无路径分隔符、无 '..' 段。store 层另有兜底。
|
|
78
|
+
*/
|
|
79
|
+
const BOARD_ID_SAFE = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
|
|
80
|
+
const isValidBoardId = (b) => BOARD_ID_SAFE.test(b);
|
|
66
81
|
function defaultState() {
|
|
67
82
|
return {
|
|
68
83
|
scanTime: '01:30',
|
|
@@ -76,6 +91,12 @@ function defaultState() {
|
|
|
76
91
|
siteLastRun: {},
|
|
77
92
|
/** ★ 2026-10-17:每站**定时**那次跑成功的时刻(ISO)。siteLastRun 只有日期,面板要显示「定时 08:30」 */
|
|
78
93
|
siteLastTimerAt: {},
|
|
94
|
+
/**
|
|
95
|
+
* ★ 2026-10-30:每站**最近一次尝试**的时刻(ISO),**成功与失败都记**。
|
|
96
|
+
* 失败冷却(schedule.ts 的 RETRY_COOLDOWN_MIN)靠它算:siteLastTimerAt 只在成功时写,
|
|
97
|
+
* 整站抛错/宿主机刚醒时它不落地 ⇒ 会白等兜底 22:30。
|
|
98
|
+
*/
|
|
99
|
+
siteLastAttemptAt: {},
|
|
79
100
|
/** 每个榜最近一次扫描(含手动):面板可显示「这个榜上次什么时候抓的」 */
|
|
80
101
|
boardLastScan: {},
|
|
81
102
|
/**
|
|
@@ -440,6 +461,8 @@ export function apply(ctx, config) {
|
|
|
440
461
|
previousRows: pd ? (pd.rows || []) : null,
|
|
441
462
|
currentPeriodKey: periodKeyFromRows(nx.rows || []),
|
|
442
463
|
previousPeriodKey: pd ? periodKeyFromRows(pd.rows || []) : null,
|
|
464
|
+
// ★ 2026-10-30:跨日版本复用(菠萝包旧代隔天复用回来时,只跟上一版比会漏)
|
|
465
|
+
history: recentTrustedVersions(b.boardId, rec.dataDate, 7),
|
|
443
466
|
});
|
|
444
467
|
/**
|
|
445
468
|
* ★ 2026-10-25(换期 ≠ 换榜/降级):换榜判据必须先问「是不是同一期」。
|
|
@@ -952,6 +975,31 @@ export function apply(ctx, config) {
|
|
|
952
975
|
}
|
|
953
976
|
return out;
|
|
954
977
|
}
|
|
978
|
+
/**
|
|
979
|
+
* ★ 2026-10-30:每站**今天最后一次尝试**距今多少分钟(失败冷却用:冷却到就当天补跑,不必等 22:30)。
|
|
980
|
+
* 取三者里最晚的一个:siteLastAttemptAt(**成功/失败都记**,2026-10-30 新增)→ siteLastTimerAt(只在成功时写)→
|
|
981
|
+
* boardLastScan.at(每次尝试都写,outcome = 五态)。所以「整站抛错、榜页还没落盘」这类失败也算一次尝试,
|
|
982
|
+
* 同时不会把「早上那次手动扫描」误当成「刚刚失败」⇒ 冷却既不会被绕过,也不会把失败站漏掉。
|
|
983
|
+
*/
|
|
984
|
+
function minutesSinceAttemptAll(sites, today) {
|
|
985
|
+
const st = readState();
|
|
986
|
+
const bls = st.boardLastScan || {};
|
|
987
|
+
const now = clock.now().getTime();
|
|
988
|
+
const out = {};
|
|
989
|
+
for (const s of sites) {
|
|
990
|
+
// ★ 2026-10-30:优先用「最近一次尝试」的时刻(成功/失败都记),缺失才回落到「定时成功时刻」
|
|
991
|
+
let at = String((st.siteLastAttemptAt || {})[s] || (st.siteLastTimerAt || {})[s] || '');
|
|
992
|
+
for (const b of (st.boards || []).filter((x) => siteOfBoard(x) === s)) {
|
|
993
|
+
const hit = bls[b];
|
|
994
|
+
if (hit && hit.date === today && String(hit.at) > at)
|
|
995
|
+
at = String(hit.at);
|
|
996
|
+
}
|
|
997
|
+
const ms = at ? now - new Date(at).getTime() : NaN;
|
|
998
|
+
if (Number.isFinite(ms) && ms >= 0)
|
|
999
|
+
out[s] = Math.round(ms / 60000);
|
|
1000
|
+
}
|
|
1001
|
+
return out;
|
|
1002
|
+
}
|
|
955
1003
|
/** 站 id → 中文名(面板/日志用) */
|
|
956
1004
|
const SITE_CN = { qidian: '起点', qidiantu: '起点图', ciweimao: '刺猬猫', sfacg: '菠萝包', fanqie: '番茄' };
|
|
957
1005
|
/** 现在这一刻的调度计划(只读;面板展示 + 集成测试都用它,零请求) */
|
|
@@ -969,6 +1017,7 @@ export function apply(ctx, config) {
|
|
|
969
1017
|
failed: sitesFailedToday(sites, localDate(new Date()), st.siteTimes || DEFAULT_SITE_TIMES),
|
|
970
1018
|
retried: st.siteRetry || {},
|
|
971
1019
|
stale: SITE_ORDER.filter((s) => Object.keys(st.staleFlag || {}).some((b) => siteOfBoard(b) === s && st.staleFlag[b]?.date === localDate(new Date()))),
|
|
1020
|
+
minutesSinceAttempt: minutesSinceAttemptAll(sites, localDate(new Date())),
|
|
972
1021
|
});
|
|
973
1022
|
/**
|
|
974
1023
|
* ★ 2026-10-16(疑问「关闭状态为什么显示今天已跑」):把「这个站今天抓过没、谁抓的、几点抓的」
|
|
@@ -1038,6 +1087,7 @@ export function apply(ctx, config) {
|
|
|
1038
1087
|
failed: sitesFailedToday(sites, today, st.siteTimes || DEFAULT_SITE_TIMES),
|
|
1039
1088
|
stale: staleSites,
|
|
1040
1089
|
retried: st.siteRetry || {},
|
|
1090
|
+
minutesSinceAttempt: minutesSinceAttemptAll(sites, today),
|
|
1041
1091
|
});
|
|
1042
1092
|
const target = plan.due[0] || plan.fallback[0];
|
|
1043
1093
|
if (!target) {
|
|
@@ -1084,7 +1134,7 @@ export function apply(ctx, config) {
|
|
|
1084
1134
|
st2.lastTimerRunAt = startedAt;
|
|
1085
1135
|
st2.lastTimerState = state;
|
|
1086
1136
|
st2.lastTimerNote = note.slice(0, 300);
|
|
1087
|
-
st2.timerSchemaV =
|
|
1137
|
+
st2.timerSchemaV = Math.max(TIMER_SCHEMA_V, Number(st2.timerSchemaV) || 0);
|
|
1088
1138
|
// ★ 按站分时:记「这个站今天跑过了」,下一个 tick 才会轮到别的站
|
|
1089
1139
|
const slr = { ...(st2.siteLastRun || {}) };
|
|
1090
1140
|
slr[target] = today;
|
|
@@ -1093,6 +1143,10 @@ export function apply(ctx, config) {
|
|
|
1093
1143
|
* ★ 2026-10-17:分开记「定时那次成功的时刻」与「最近一次抓取(含手动)」——
|
|
1094
1144
|
* 只有日期的话,面板上「今天已抓(手动 11:43)」会让人以为计划 08:30 没跑。
|
|
1095
1145
|
*/
|
|
1146
|
+
// ★ 2026-10-30:**每次都记尝试时刻**(成功/失败都记)—— 失败冷却靠它算
|
|
1147
|
+
const slat = { ...(st2.siteLastAttemptAt || {}) };
|
|
1148
|
+
slat[target] = startedAt;
|
|
1149
|
+
st2.siteLastAttemptAt = slat;
|
|
1096
1150
|
if (state === 'ok') {
|
|
1097
1151
|
const sla = { ...(st2.siteLastTimerAt || {}) };
|
|
1098
1152
|
sla[target] = startedAt;
|
|
@@ -1152,7 +1206,7 @@ export function apply(ctx, config) {
|
|
|
1152
1206
|
// v6(2026-10-16):补 staleFlag/siteRetry/installedAt/按站分时(**不翻开关**)
|
|
1153
1207
|
const cur1 = readJson(statePath, {});
|
|
1154
1208
|
// v6(2026-10-16):补 staleFlag/siteRetry/installedAt(老配置不视作「安装当天」、不翻开关)
|
|
1155
|
-
if (cur1 && cur1.timerSchemaV
|
|
1209
|
+
if (cur1 && !(Number(cur1.timerSchemaV) >= 6)) {
|
|
1156
1210
|
const st1 = readState();
|
|
1157
1211
|
st1.siteTimes = { ...DEFAULT_SITE_TIMES, ...(st1.siteTimes || {}) };
|
|
1158
1212
|
st1.fallbackTime = st1.fallbackTime || DEFAULT_FALLBACK_TIME;
|
|
@@ -1173,6 +1227,29 @@ export function apply(ctx, config) {
|
|
|
1173
1227
|
writeState(st1);
|
|
1174
1228
|
timerLog('v4 迁移:按站分时 = ' + JSON.stringify(st1.siteTimes) + '(兜底 ' + st1.fallbackTime + ';installedAt=' + st1.installedAt + ')');
|
|
1175
1229
|
}
|
|
1230
|
+
/**
|
|
1231
|
+
* v7(2026-10-30):**按站分时改点** —— 菠萝包 09:30→14:30(首页整代对象,09:30 踩在换代的未测窗口里)、
|
|
1232
|
+
* 起点图 12:40→21:30(首订数值要到 首V+24h 才收盘,12:40 抓有 ~37% 未收盘)。
|
|
1233
|
+
* 只改**仍是旧默认值**的站:使用者自己调过的时刻一律不动。
|
|
1234
|
+
*/
|
|
1235
|
+
const cur7 = readJson(statePath, {});
|
|
1236
|
+
if (cur7 && !(Number(cur7.timerSchemaV) >= TIMER_SCHEMA_V)) {
|
|
1237
|
+
const st7 = readState();
|
|
1238
|
+
const OLD = { sfacg: '09:30', qidiantu: '12:40' };
|
|
1239
|
+
const defs = DEFAULT_SITE_TIMES;
|
|
1240
|
+
const times = { ...defs, ...(st7.siteTimes || {}) };
|
|
1241
|
+
const moved = [];
|
|
1242
|
+
for (const s of Object.keys(OLD)) {
|
|
1243
|
+
if (times[s] === OLD[s]) {
|
|
1244
|
+
times[s] = defs[s];
|
|
1245
|
+
moved.push(SITE_CN[s] || s);
|
|
1246
|
+
}
|
|
1247
|
+
}
|
|
1248
|
+
st7.siteTimes = times;
|
|
1249
|
+
st7.timerSchemaV = TIMER_SCHEMA_V;
|
|
1250
|
+
writeState(st7);
|
|
1251
|
+
timerLog('v7 迁移:按站分时改点(只改仍是旧默认值的站)' + (moved.length ? ':' + moved.join('、') : '(无需改)') + ' ⇒ ' + JSON.stringify(times));
|
|
1252
|
+
}
|
|
1176
1253
|
}
|
|
1177
1254
|
catch { /* 迁移失败不该挡住接线 */ }
|
|
1178
1255
|
timerApi = t;
|
|
@@ -1221,6 +1298,27 @@ export function apply(ctx, config) {
|
|
|
1221
1298
|
return false;
|
|
1222
1299
|
}
|
|
1223
1300
|
}
|
|
1301
|
+
/**
|
|
1302
|
+
* ★ 2026-10-30:该榜最近 N 次**可信**快照(新→旧、不含当天),供「跨日版本复用」判据用。
|
|
1303
|
+
* N 按快照次数而不是日历天:抓失败/关机造成的缺日不该白占窗口。
|
|
1304
|
+
*/
|
|
1305
|
+
function recentTrustedVersions(boardId, date, n = 7) {
|
|
1306
|
+
const st = new FileStore(root);
|
|
1307
|
+
const out = [];
|
|
1308
|
+
const ds = listDataDates(root);
|
|
1309
|
+
for (let k = ds.length - 1; k >= 0 && out.length < n; k--) {
|
|
1310
|
+
const d = ds[k];
|
|
1311
|
+
if (d >= date)
|
|
1312
|
+
continue;
|
|
1313
|
+
if (st.isUntrusted(d, boardId))
|
|
1314
|
+
continue;
|
|
1315
|
+
const s = st.readSnapshot(d, boardId);
|
|
1316
|
+
if (!s || !(s.rows || []).length)
|
|
1317
|
+
continue;
|
|
1318
|
+
out.push({ date: d, rows: s.rows, periodKey: periodKeyFromRows(s.rows) });
|
|
1319
|
+
}
|
|
1320
|
+
return out;
|
|
1321
|
+
}
|
|
1224
1322
|
/**
|
|
1225
1323
|
* ★ 工作包 A:**该榜自己的上一次可信成功数据日**(跨过缺日、跨过被拒快照)。
|
|
1226
1324
|
* 旧口径只看「全局上一数据日期」:该榜那天没跑成功就判「首次采集」⇒ 变化整列空、
|
|
@@ -3574,8 +3672,8 @@ export function apply(ctx, config) {
|
|
|
3574
3672
|
return send(200, await panelOverview());
|
|
3575
3673
|
if (p === '/api/rank-scan/board') {
|
|
3576
3674
|
const b = q.get('boardId');
|
|
3577
|
-
if (!b)
|
|
3578
|
-
return send(400, { error: 'boardId
|
|
3675
|
+
if (!b || !isValidBoardId(b))
|
|
3676
|
+
return send(400, { error: 'boardId 必填且只能是字母、数字、点、下划线、连字符' });
|
|
3579
3677
|
return send(200, await panelBoard(b, q.get('date') || undefined, q.get('sort') || undefined, Number(q.get('limit') || 0)));
|
|
3580
3678
|
}
|
|
3581
3679
|
if (p === '/api/rank-scan/changes')
|
|
@@ -3587,6 +3685,9 @@ export function apply(ctx, config) {
|
|
|
3587
3685
|
const st3 = readState();
|
|
3588
3686
|
if (Array.isArray(body.captures)) {
|
|
3589
3687
|
const posted = body.captures.map(String);
|
|
3688
|
+
// ★ 审查 M1:boardId 直入快照路径 ⇒ 非法字符(路径分隔符/..)直接拒,不持久化
|
|
3689
|
+
if (posted.some((b) => !isValidBoardId(b)))
|
|
3690
|
+
return send(400, { error: 'boardId 含非法字符(只允许字母、数字、点、下划线、连字符)' });
|
|
3590
3691
|
// 面板只能管清单内的榜;清单外的既有抓取项原样保留(防止「保存丢榜」)
|
|
3591
3692
|
const known = new Set(catalog().boards.map((b) => b.boardId));
|
|
3592
3693
|
const keep = st3.boards.filter((b) => !known.has(b));
|
|
@@ -3594,8 +3695,12 @@ export function apply(ctx, config) {
|
|
|
3594
3695
|
// 口径:抓了就要显示 ⇒ 显示集跟随抓取集(派生榜随番茄开关自动进出)
|
|
3595
3696
|
st3.display = st3.boards.filter((b) => !b.startsWith('fanqie.derived.'));
|
|
3596
3697
|
}
|
|
3597
|
-
if (Array.isArray(body.displays))
|
|
3598
|
-
|
|
3698
|
+
if (Array.isArray(body.displays)) {
|
|
3699
|
+
const disp = body.displays.map(String);
|
|
3700
|
+
if (disp.some((b) => !isValidBoardId(b)))
|
|
3701
|
+
return send(400, { error: 'boardId 含非法字符(只允许字母、数字、点、下划线、连字符)' });
|
|
3702
|
+
st3.display = disp;
|
|
3703
|
+
}
|
|
3599
3704
|
if (typeof body.autoEnrich === 'boolean')
|
|
3600
3705
|
st3.autoEnrich = body.autoEnrich;
|
|
3601
3706
|
if (typeof body.qidianEnrich === 'boolean')
|
|
@@ -3646,7 +3751,7 @@ export function apply(ctx, config) {
|
|
|
3646
3751
|
return send(400, { error: '兜底时间格式应为 HH:mm' });
|
|
3647
3752
|
stT.fallbackTime = body.fallbackTime;
|
|
3648
3753
|
}
|
|
3649
|
-
stT.timerSchemaV =
|
|
3754
|
+
stT.timerSchemaV = Math.max(TIMER_SCHEMA_V, Number(stT.timerSchemaV) || 0);
|
|
3650
3755
|
writeState(stT);
|
|
3651
3756
|
const on = stT.timerEnabled === true;
|
|
3652
3757
|
// ★ 票 25:开关变化立刻接/断,不用等重启
|
|
@@ -3655,7 +3760,7 @@ export function apply(ctx, config) {
|
|
|
3655
3760
|
ok: true, enabled: on, scanTime: stT.scanTime, siteTimes: stT.siteTimes, fallbackTime: stT.fallbackTime,
|
|
3656
3761
|
siteLastRun: stT.siteLastRun || {}, siteLastTimerAt: stT.siteLastTimerAt || {}, plan: timerPlanNow(), armed,
|
|
3657
3762
|
note: (on
|
|
3658
|
-
? '定时已开启(按站分时):' + SITE_ORDER.map((s) => (SITE_CN[s] || s) + ' ' + ((stT.siteTimes || {})[s] || '—')).join('、') + '
|
|
3763
|
+
? '定时已开启(按站分时):' + SITE_ORDER.map((s) => (SITE_CN[s] || s) + ' ' + ((stT.siteTimes || {})[s] || '—')).join('、') + ';当天没跑成的站冷却 ' + RETRY_COOLDOWN_MIN + ' 分钟后补跑一次(最晚 ' + (stT.fallbackTime || DEFAULT_FALLBACK_TIME) + ')'
|
|
3659
3764
|
: '定时扫描已关闭(面板「立刻扫一次」仍可用)') + (on
|
|
3660
3765
|
? (armed ? ';定时器已接线' : ';注意:宿主 timer 服务不可用,暂未接线')
|
|
3661
3766
|
: ';定时器已断开'),
|
|
@@ -3671,8 +3776,8 @@ export function apply(ctx, config) {
|
|
|
3671
3776
|
const body = await readBody(req);
|
|
3672
3777
|
const boardId = String(body.boardId || '');
|
|
3673
3778
|
const n = Math.max(1, Math.min(100, Number(body.depth) || 10));
|
|
3674
|
-
if (!boardId)
|
|
3675
|
-
return send(400, { error: 'boardId
|
|
3779
|
+
if (!boardId || !isValidBoardId(boardId))
|
|
3780
|
+
return send(400, { error: 'boardId 必填且只能是字母、数字、点、下划线、连字符' });
|
|
3676
3781
|
const st2 = readState();
|
|
3677
3782
|
st2.depths = { ...(st2.depths || {}), [boardId]: n };
|
|
3678
3783
|
writeState(st2);
|
|
@@ -3729,8 +3834,8 @@ export function apply(ctx, config) {
|
|
|
3729
3834
|
catch (e) {
|
|
3730
3835
|
return send(400, { error: e instanceof Error ? e.message : String(e) });
|
|
3731
3836
|
}
|
|
3732
|
-
if (!boardId)
|
|
3733
|
-
return send(400, { error: 'boardId
|
|
3837
|
+
if (!boardId || !isValidBoardId(boardId))
|
|
3838
|
+
return send(400, { error: 'boardId 必填且只能是字母、数字、点、下划线、连字符' });
|
|
3734
3839
|
const stDay = readState();
|
|
3735
3840
|
const site = serveSiteFor([boardId], stDay.depths || {})[0];
|
|
3736
3841
|
if (!site)
|
|
@@ -3783,6 +3888,8 @@ export function apply(ctx, config) {
|
|
|
3783
3888
|
return send(200, { ok: true, dropped: date, gone: !existsSync(dir) });
|
|
3784
3889
|
}
|
|
3785
3890
|
const b = String(body.boardId || 'qidiantu.shouding');
|
|
3891
|
+
if (!isValidBoardId(b))
|
|
3892
|
+
return send(400, { error: 'boardId 含非法字符(只允许字母、数字、点、下划线、连字符)' });
|
|
3786
3893
|
const st4 = readState();
|
|
3787
3894
|
const site = serveSiteFor([b], st4.depths || {})[0];
|
|
3788
3895
|
if (!site)
|
|
@@ -3842,8 +3949,8 @@ export function apply(ctx, config) {
|
|
|
3842
3949
|
if (String(req.method || 'GET').toUpperCase() !== 'POST')
|
|
3843
3950
|
return send(405, { error: 'POST only' });
|
|
3844
3951
|
const b = q.get('boardId');
|
|
3845
|
-
if (!b)
|
|
3846
|
-
return send(400, { error: 'boardId
|
|
3952
|
+
if (!b || !isValidBoardId(b))
|
|
3953
|
+
return send(400, { error: 'boardId 必填且只能是字母、数字、点、下划线、连字符' });
|
|
3847
3954
|
const resE = await enrichBoard(b, forceQ);
|
|
3848
3955
|
/**
|
|
3849
3956
|
* ★ 2026-10-17:手动「补全本榜」补齐后要**把待办销掉** —— 以前只有后台工人那一圈会清,
|
|
@@ -3879,6 +3986,8 @@ export function apply(ctx, config) {
|
|
|
3879
3986
|
return send(405, { error: 'POST only' });
|
|
3880
3987
|
const forceQ = q.get('force') === '1' || q.get('force') === 'true';
|
|
3881
3988
|
const bid = q.get('boardId');
|
|
3989
|
+
if (bid && !isValidBoardId(bid))
|
|
3990
|
+
return send(400, { error: 'boardId 含非法字符(只允许字母、数字、点、下划线、连字符)' });
|
|
3882
3991
|
if (bid)
|
|
3883
3992
|
return send(200, await qidianEnrichBoard(bid, forceQ));
|
|
3884
3993
|
// 不带 boardId = 把抓取集里的起点榜逐个补(仍受每榜请求上限保护)
|
|
@@ -4017,6 +4126,9 @@ export function apply(ctx, config) {
|
|
|
4017
4126
|
if (action === 'add') {
|
|
4018
4127
|
let row = body.row || null;
|
|
4019
4128
|
let boardId = String(body.boardId || '');
|
|
4129
|
+
// ★ 审查 M1:boardId 会用于 readSnapshot 路径拼接 ⇒ 先卡格式
|
|
4130
|
+
if (boardId && !isValidBoardId(boardId))
|
|
4131
|
+
return send(400, { error: 'boardId 含非法字符(只允许字母、数字、点、下划线、连字符)' });
|
|
4020
4132
|
let dataDate = String(body.dataDate || '');
|
|
4021
4133
|
/**
|
|
4022
4134
|
* ★ 只给了 bookKey 的情况(「变化集」就是这么调用的):去本地快照里把这本书找出来,
|
|
@@ -4202,7 +4314,13 @@ export function apply(ctx, config) {
|
|
|
4202
4314
|
if (String(req.method || 'GET').toUpperCase() !== 'POST')
|
|
4203
4315
|
return send(405, { error: 'POST only' });
|
|
4204
4316
|
const body3 = await readBody(req);
|
|
4205
|
-
|
|
4317
|
+
// ★ 2026-11-02(审查 M2):与 export-file 同一道白名单 —— 只允许用户目录内的路径,
|
|
4318
|
+
// 且**先校验再 existsSync**:UNC 路径(\\host\share)光 existsSync 就会发起 SMB 认证,
|
|
4319
|
+
// 把本地 NTLM 哈希发给攻击者主机。
|
|
4320
|
+
const dir = resolve(String(body3.path || '').trim() || join(homedir(), 'Documents', 'rank-scan-export'));
|
|
4321
|
+
const relF = relative(resolve(homedir()), dir);
|
|
4322
|
+
if (!relF || relF === '..' || relF.startsWith('..' + (process.platform === 'win32' ? '\\' : '/')) || isAbsolute(relF))
|
|
4323
|
+
return send(400, { error: '只允许打开用户目录内的文件夹' });
|
|
4206
4324
|
if (!existsSync(dir))
|
|
4207
4325
|
return send(400, { error: '目录还不存在:' + dir + '(先导出一次就会创建)' });
|
|
4208
4326
|
const cmd = process.platform === 'win32' ? 'explorer.exe' : process.platform === 'darwin' ? 'open' : 'xdg-open';
|