dsh-rank-scan 0.6.3 → 0.6.5

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 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.3
21
+ # 钉版本:github:kilo-s/dsh-rank-scan#v0.6.5
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.3
40
+ # 钉版本:dsh-rank-scan@0.6.5
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.3**);面板「设置」页底部会读 npm 上的版本号提示有没有新版,装了 [dsh-market](https://github.com/dsh-market/dsh-market) 的话还能就地更新。
47
+ **更新**:重跑安装命令即可(链接直装取最新 `main`,registry 装取最新发布版;本版本为 **0.6.5**);面板「设置」页底部会读 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
 
package/lib/client.js CHANGED
@@ -1112,6 +1112,39 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
1112
1112
  return (i === 0 ? String(Math.round(v)) : v.toFixed(1)) + ' ' + u[i]
1113
1113
  }
1114
1114
 
1115
+ /**
1116
+ * 概览「变化」列(2026-11-06 统一涨跌色):
1117
+ * 宿主旧实现只给拼好的字符串('↑3' / '↓-2'),客户端无法判正负 ⇒ 这一列从来没有颜色,
1118
+ * 下降还叠了负号;而榜单页同一件事是绿/红。现在宿主同时给 deltaNum,这里按数值上色,
1119
+ * 文案与榜单页「变化」列同构:↑2 绿 / ↓2 红 / 0 灰 / 新入榜「+ 新」/ 回榜 / 退榜「→ 榜外」。
1120
+ * 兼容只有字符串的老宿主:从 '↑3' / '↓-2' 反解数值;解不出就原样显示(不编颜色)。
1121
+ */
1122
+ function changeDeltaNode(group, it) {
1123
+ const row = it || {}
1124
+ let n = typeof row.deltaNum === 'number' && Number.isFinite(row.deltaNum) ? row.deltaNum : null
1125
+ const raw = row.delta == null ? '' : String(row.delta)
1126
+ if (n == null && raw) {
1127
+ const m = raw.match(/^([↑↓])\s*(-?\d+(?:\.\d+)?)$/)
1128
+ if (m) n = (m[1] === '↓' ? -1 : 1) * Math.abs(Number(m[2]))
1129
+ }
1130
+ if (group === '新入榜') return h('span', { style: C.up }, '+ 新')
1131
+ if (group === '回榜') return h('span', { style: C.muted }, '回榜')
1132
+ if (group === '退榜') return h('span', { style: C.down }, '→ 榜外')
1133
+ if (n == null) return dash(raw)
1134
+ /**
1135
+ * ★ 数值型榜(番茄在读 / 起点图首订这类):上升 = 数值涨,**不是名次**,
1136
+ * 写成 ↑21664 会被读成「掉了两万多名」⇒ 改用带千分位的 +/- 写法。
1137
+ */
1138
+ if (row.metric === 'value') {
1139
+ if (n > 0) return h('span', { style: C.up }, '+' + fmtRead(n))
1140
+ if (n < 0) return h('span', { style: C.down }, '-' + fmtRead(Math.abs(n)))
1141
+ return h('span', { style: C.muted }, '0')
1142
+ }
1143
+ if (n > 0) return h('span', { style: C.up }, '↑' + n)
1144
+ if (n < 0) return h('span', { style: C.down }, '↓' + Math.abs(n))
1145
+ return h('span', { style: C.muted }, '0')
1146
+ }
1147
+
1115
1148
  /**
1116
1149
  * 概览:先回答「今天有什么需要看」——
1117
1150
  * ① 需要处理(**仅有问题时出现**:榜名 + 影响 + 可执行动作)
@@ -1502,7 +1535,7 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
1502
1535
  h('span', { style: { flex: '1 1 auto', minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }, title: e.it.title }, e.it.title),
1503
1536
  h('span', { style: { flex: '0 0 auto' }, onClick: function (ev) { ev.stopPropagation() } },
1504
1537
  h(BookmarkStar, { bookKey: bookKeyOf(e.it.boardId, e.it.title), boardId: e.it.boardId, row: null, title: e.it.title })),
1505
- h('span', { style: { ...C.num, flex: '0 0 auto' }, title: '名次变化' }, dash(e.it.delta))),
1538
+ h('span', { style: { ...C.num, flex: '0 0 auto' }, title: e.it.metric === 'value' ? '数值变化(本地环比)' : '名次变化' }, changeDeltaNode(e.group, e.it))),
1506
1539
  h('div', { style: { ...C.muted, marginTop: '1px', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }, e.it.boardName))
1507
1540
  }))
1508
1541
  }))
@@ -1524,7 +1557,7 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
1524
1557
  h('td', { style: { ...C.td, minWidth: '140px' } }, e.it.title, ' ',
1525
1558
  h('span', { onClick: function (ev) { ev.stopPropagation() } },
1526
1559
  h(BookmarkStar, { bookKey: bookKeyOf(e.it.boardId, e.it.title), boardId: e.it.boardId, row: null, title: e.it.title }))),
1527
- h('td', { style: { ...C.td, ...C.num } }, dash(e.it.delta)))
1560
+ h('td', { style: { ...C.td, ...C.num } }, changeDeltaNode(e.group, e.it)))
1528
1561
  })
1529
1562
  return [head].concat(body)
1530
1563
  })))) : null,
@@ -2241,8 +2274,9 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
2241
2274
  if (r.deltaGroup === 'rebound') return '回榜'
2242
2275
  // B2:「算不出」也是弱信息,用 muted;只有真涨跌与「+新」用全色
2243
2276
  if (r.delta === null || r.delta === undefined) return h('span', { style: C.muted }, '—')
2244
- if (r.delta > 0) return h('span', { style: C.up }, '↑ ' + r.delta)
2245
- if (r.delta < 0) return h('span', { style: C.down }, '↓ ' + Math.abs(r.delta))
2277
+ // ★ 2026-11-06:箭头与数字之间不留空格 —— 与概览「变化」列同一写法(↑3 / ↓2)
2278
+ if (r.delta > 0) return h('span', { style: C.up }, '↑' + r.delta)
2279
+ if (r.delta < 0) return h('span', { style: C.down }, '↓' + Math.abs(r.delta))
2246
2280
  // B2:持平仍然是「0」(语义不变),只是不再抢眼
2247
2281
  return h('span', { style: C.muted }, '0')
2248
2282
  }
@@ -2888,6 +2922,31 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
2888
2922
  return cur === key ? '' : key
2889
2923
  }
2890
2924
  const normalizeSortPref = function (v) { return v === 'rank' ? '' : (v || '') }
2925
+ /**
2926
+ * ★ 2026-11-06:排序偏好是否仍在该榜的**可选项**里。
2927
+ * 番茄这一轮去掉了「在读」排序项,但 localStorage 里还留着旧偏好 'read' ⇒
2928
+ * 下拉里找不到这个选项(显示空白),表格却仍按在读排 —— 看起来像排序坏了。
2929
+ * 判据只认宿主回传的 sortOptions:不在里面就回落默认(空串)。
2930
+ */
2931
+ const sortValueValid = function (v, sortOptions) {
2932
+ if (!v) return true
2933
+ return (sortOptions || []).some(function (o) { return o && o.value === v })
2934
+ }
2935
+ /**
2936
+ * 最近的滚动容器(面板 body;overflow auto/scroll 且真的能滚)。找不到就退回 document.scrollingElement。
2937
+ * ★ 2026-11-06:排序后「要不要把表头拉回来」要用它算可视区上沿,别再假设容器在页面顶部。
2938
+ */
2939
+ const scrollParentOf = function (node) {
2940
+ let el = node && node.parentElement
2941
+ while (el && el !== document.body) {
2942
+ const cs = getComputedStyle(el)
2943
+ const oy = cs && cs.overflowY
2944
+ if ((oy === 'auto' || oy === 'scroll') && el.scrollHeight > el.clientHeight + 4) return el
2945
+ el = el.parentElement
2946
+ }
2947
+ return document.scrollingElement || null
2948
+ }
2949
+
2891
2950
  /** 只给行号,详情行不参与;n 是数据行数量 */
2892
2951
  const nextRowIdx = function (i, key, n) {
2893
2952
  const last = Math.max(0, Number(n) - 1)
@@ -2963,7 +3022,7 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
2963
3022
  }
2964
3023
 
2965
3024
  // 离线测试缝:只暴露第六步的纯函数,不改变运行路径
2966
- window.__rankScanBoardTableTest = { sortableCols: sortableCols, nextSort: nextSort, nextRowIdx: nextRowIdx, normalizeSortPref: normalizeSortPref }
3025
+ window.__rankScanBoardTableTest = { sortableCols: sortableCols, nextSort: nextSort, nextRowIdx: nextRowIdx, normalizeSortPref: normalizeSortPref, sortValueValid: sortValueValid }
2967
3026
 
2968
3027
  function BoardTab(props) {
2969
3028
  const ov = props.ov
@@ -3135,10 +3194,29 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
3135
3194
  if (!sortJumpRef.current) return
3136
3195
  sortJumpRef.current = false
3137
3196
  const el = listRef.current
3138
- if (el && el.scrollIntoView) {
3139
- try { el.scrollIntoView({ block: 'start' }) } catch (e) {}
3140
- }
3197
+ if (!el || !el.getBoundingClientRect) return
3198
+ /**
3199
+ * ★ 2026-11-06(使用者反馈「排序一点就跳到下面去」):
3200
+ * 旧实现是**无条件** el.scrollIntoView({ block: 'start' }) —— 表头被顶到滚动容器顶部,
3201
+ * 于是标题/工具条整段被推出可视区,看着像「点一下就被甩到下面一屏」。
3202
+ * 本意只是「用户在列表深处换排序、表头已经看不见」时把表头拉回来;
3203
+ * 表头本来就在视野里就**保持原位不动**。
3204
+ */
3205
+ const scroller = scrollParentOf(el)
3206
+ const viewTop = scroller && scroller.getBoundingClientRect ? scroller.getBoundingClientRect().top : 0
3207
+ if (el.getBoundingClientRect().top >= viewTop - 1) return
3208
+ try { el.scrollIntoView({ block: 'start' }) } catch (e) {}
3141
3209
  }, [ss])
3210
+ /**
3211
+ * ★ 2026-11-06:榜换了、或排序项被删掉(番茄去掉「在读」)时,清掉已失效的旧偏好;
3212
+ * 否则下拉里找不到该值(显示空白),表格却还按旧键在排 —— 看起来像排序失效。
3213
+ */
3214
+ React.useEffect(function () {
3215
+ if (!data || data.boardId !== bt) return
3216
+ if (sortValueValid(ss, data.sortOptions)) return
3217
+ setSs('')
3218
+ try { sel.setPref(bt, 'sort', '') } catch (e) {}
3219
+ }, [data, bt, ss])
3142
3220
  React.useEffect(function () {
3143
3221
  if (pick || focusBackRef.current == null) return
3144
3222
  const idx = focusBackRef.current
@@ -4008,7 +4086,7 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
4008
4086
  bmPage: BM_PAGE,
4009
4087
  bmSortKey: BM_SORT_KEY,
4010
4088
  bmSortOptions: BM_SORT_OPTIONS,
4011
- helpers: { cell: cell, metaDot: metaDot, cleanDesc: cleanDesc, fmtStamp: fmtStamp, revOf: revOf, statusText: statusText, scanLabel: scanLabel, pollDelay: pollDelay, canDayQuery: canDayQuery, fitColumns: fitColumns, colPrio: colPrio, mdOf: mdOf, boardLabel: boardLabel, rememberBoardNames: rememberBoardNames },
4089
+ helpers: { cell: cell, metaDot: metaDot, cleanDesc: cleanDesc, fmtStamp: fmtStamp, revOf: revOf, statusText: statusText, scanLabel: scanLabel, pollDelay: pollDelay, canDayQuery: canDayQuery, fitColumns: fitColumns, colPrio: colPrio, mdOf: mdOf, boardLabel: boardLabel, rememberBoardNames: rememberBoardNames, changeDeltaNode: changeDeltaNode },
4012
4090
  components: { Overview: Overview, BoardTab: BoardTab, BookmarksTab: BookmarksTab, SettingsTab: SettingsTab, PopMenu: PopMenu, Panel: Panel, ToastHost: ToastHost, StatCard: StatCard, SectionHeader: SectionHeader },
4013
4091
  nextPlanOf: nextPlanOf,
4014
4092
  toast: toast, toastStore: toastStore, lastNote: lastNote, settingsDiff: settingsDiff,
package/lib/index.js CHANGED
@@ -69,6 +69,15 @@ const pad2 = (n) => String(n).padStart(2, '0');
69
69
  * 使用者若刻意把菠萝包调回 09:30,会被再改掉一次 —— 与「调过的不动」自相矛盾。
70
70
  */
71
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);
72
81
  function defaultState() {
73
82
  return {
74
83
  scanTime: '01:30',
@@ -1836,6 +1845,9 @@ export function apply(ctx, config) {
1836
1845
  // 番茄:在读在 extra 里(行 value 是「今日涨幅」,不是在读)
1837
1846
  if (key === 'read')
1838
1847
  return typeof ex.read === 'number' ? ex.read : null;
1848
+ // ★ 2026-11-06:番茄「在读变化」参与排序(缺前值 ⇒ null,由 compareDesc 压到最后)
1849
+ if (key === 'readDelta')
1850
+ return typeof ex.valueDelta === 'number' ? ex.valueDelta : null;
1839
1851
  // 三江:期初收藏 / 今日增量 / 期累计(都在 extra)
1840
1852
  if (key === 'collectBase' || key === 'dailyDelta' || key === 'periodTotal') {
1841
1853
  return typeof ex[key] === 'number' ? ex[key] : null;
@@ -1865,8 +1877,33 @@ export function apply(ctx, config) {
1865
1877
  { value: 'periodTotal', label: '期累计增量' },
1866
1878
  ];
1867
1879
  }
1880
+ /**
1881
+ * ★ 2026-11-06(使用者定):番茄新书榜的排序项按「当天看得懂的变化」重排:
1882
+ * 默认(名次)→ 在读变化 → 名次变化 → 字数。
1883
+ * · 去掉「在读」排序:在读是累计值,按它排等于把榜单换成另一张榜,且番茄在读日间会回落/修正;
1884
+ * · 「变化(本地环比)」改名「名次变化」:番茄这列本来就是名次差(名次型榜),不是数值差;
1885
+ * · 字数挪到最后:它是作品属性,不是「今天发生了什么」。
1886
+ * 在读周榜是派生榜,走上面自己的那套,不受影响。
1887
+ */
1888
+ if (meta.site === 'fanqie' && !boardId.startsWith('fanqie.derived.')) {
1889
+ const fanOpts = [
1890
+ { value: '', label: '默认(名次)' },
1891
+ { value: 'readDelta', label: '在读变化' },
1892
+ { value: 'delta', label: '名次变化' },
1893
+ { value: 'words', label: '字数' },
1894
+ ];
1895
+ const fanKeys = new Set(applyColumnPolicy(columnsFor(meta, { hasBaseline: flags.hasHistory, hasHistory: flags.hasHistory }), boardId).map((c) => c.key));
1896
+ return fanOpts.filter((o) => !o.value || fanKeys.has(o.value));
1897
+ }
1868
1898
  const main = mainLabelOf(boardId, meta);
1869
1899
  const opts = [{ value: '', label: '默认(名次)' }];
1900
+ /**
1901
+ * ★ 2026-11-06(使用者定):起点 / 刺猬猫 / 菠萝包 —— 默认(名次)后面紧跟「名次变化」。
1902
+ * 这三站是名次型榜,「变化」列一直在(prevRank − curRank),但以前没进排序下拉。
1903
+ * 批次榜(刺猬猫首订(约))没有「变化」列 ⇒ 末尾的列存在性过滤会自动剔除这一项。
1904
+ */
1905
+ if (meta.site === 'qidian' || meta.site === 'ciweimao' || meta.site === 'sfacg')
1906
+ opts.push({ value: 'delta', label: '名次变化' });
1870
1907
  // 列名口径:番茄主指标列叫 read(不是 value),排序值必须对上列 key 才不会被客户端过滤掉
1871
1908
  const mainKey = meta.site === 'fanqie' && !boardId.startsWith('fanqie.derived.') ? 'read' : 'value';
1872
1909
  if (meta.metric === 'value')
@@ -2435,8 +2472,17 @@ export function apply(ctx, config) {
2435
2472
  excluded.push({ boardId, reason: '新期不可比(不参与变化)' });
2436
2473
  continue;
2437
2474
  }
2438
- const push = (group, list, sign) => {
2439
- for (const e of list || [])
2475
+ /**
2476
+ * ★ 2026-11-06(使用者反馈「概览的变化箭头没有颜色」):
2477
+ * 以前宿主只回传**拼好的字符串**('↑3' / '↓-2'),客户端拿不到数值 ⇒ 概览「变化」列
2478
+ * 从来没有涨跌色;下降还叠了负号('↓-2');新入榜/回榜/退榜的 '第' '→ 榜外' 前缀
2479
+ * 更是死代码(这三组的 delta 恒为 null,走不到拼前缀的分支)。
2480
+ * 现在:① 一起回传 deltaNum(面板按正负上色);② 文本孪生做规范化(下降取绝对值);
2481
+ * ③ 三个无差值的分组不再拼前缀,文案交给面板按 group 出(与榜单页同构)。
2482
+ */
2483
+ const push = (group, list) => {
2484
+ for (const e of list || []) {
2485
+ const n = typeof e.delta === 'number' && Number.isFinite(e.delta) ? e.delta : null;
2440
2486
  entries.push({
2441
2487
  site: meta.site,
2442
2488
  siteName: meta.siteName,
@@ -2446,15 +2492,21 @@ export function apply(ctx, config) {
2446
2492
  baselineDate: d.baselineDate,
2447
2493
  group,
2448
2494
  title: e.title,
2449
- delta: e.delta == null ? '' : sign + String(e.delta),
2495
+ /** 面板上色用的**数值**(缺失 = null,不补 0) */
2496
+ deltaNum: n,
2497
+ /** 榜的指标类型:rank ⇒ 名次变化(↑↓);value ⇒ 数值变化(+/-,番茄/起点图这类),面板据此换写法 */
2498
+ metric: meta.metric,
2499
+ /** 文本孪生:↑3 / ↓2(下降只留绝对值);无差值的分组给空串,由面板按 group 出文案 */
2500
+ delta: n == null ? '' : group === '下降' ? '↓' + Math.abs(n) : group === '上升' ? '↑' + n : String(n),
2450
2501
  days: e.days == null ? null : e.days,
2451
2502
  });
2503
+ }
2452
2504
  };
2453
- push('新入榜', d.newEntry, '第');
2454
- push('回榜', d.rebound, '回榜第');
2455
- push('上升', d.up, '↑');
2456
- push('下降', d.down, '↓');
2457
- push('退榜', d.out, '→ 榜外');
2505
+ push('新入榜', d.newEntry);
2506
+ push('回榜', d.rebound);
2507
+ push('上升', d.up);
2508
+ push('下降', d.down);
2509
+ push('退榜', d.out);
2458
2510
  }
2459
2511
  return {
2460
2512
  date: useDate,
@@ -3663,8 +3715,8 @@ export function apply(ctx, config) {
3663
3715
  return send(200, await panelOverview());
3664
3716
  if (p === '/api/rank-scan/board') {
3665
3717
  const b = q.get('boardId');
3666
- if (!b)
3667
- return send(400, { error: 'boardId 必填' });
3718
+ if (!b || !isValidBoardId(b))
3719
+ return send(400, { error: 'boardId 必填且只能是字母、数字、点、下划线、连字符' });
3668
3720
  return send(200, await panelBoard(b, q.get('date') || undefined, q.get('sort') || undefined, Number(q.get('limit') || 0)));
3669
3721
  }
3670
3722
  if (p === '/api/rank-scan/changes')
@@ -3676,6 +3728,9 @@ export function apply(ctx, config) {
3676
3728
  const st3 = readState();
3677
3729
  if (Array.isArray(body.captures)) {
3678
3730
  const posted = body.captures.map(String);
3731
+ // ★ 审查 M1:boardId 直入快照路径 ⇒ 非法字符(路径分隔符/..)直接拒,不持久化
3732
+ if (posted.some((b) => !isValidBoardId(b)))
3733
+ return send(400, { error: 'boardId 含非法字符(只允许字母、数字、点、下划线、连字符)' });
3679
3734
  // 面板只能管清单内的榜;清单外的既有抓取项原样保留(防止「保存丢榜」)
3680
3735
  const known = new Set(catalog().boards.map((b) => b.boardId));
3681
3736
  const keep = st3.boards.filter((b) => !known.has(b));
@@ -3683,8 +3738,12 @@ export function apply(ctx, config) {
3683
3738
  // 口径:抓了就要显示 ⇒ 显示集跟随抓取集(派生榜随番茄开关自动进出)
3684
3739
  st3.display = st3.boards.filter((b) => !b.startsWith('fanqie.derived.'));
3685
3740
  }
3686
- if (Array.isArray(body.displays))
3687
- st3.display = body.displays.map(String);
3741
+ if (Array.isArray(body.displays)) {
3742
+ const disp = body.displays.map(String);
3743
+ if (disp.some((b) => !isValidBoardId(b)))
3744
+ return send(400, { error: 'boardId 含非法字符(只允许字母、数字、点、下划线、连字符)' });
3745
+ st3.display = disp;
3746
+ }
3688
3747
  if (typeof body.autoEnrich === 'boolean')
3689
3748
  st3.autoEnrich = body.autoEnrich;
3690
3749
  if (typeof body.qidianEnrich === 'boolean')
@@ -3760,8 +3819,8 @@ export function apply(ctx, config) {
3760
3819
  const body = await readBody(req);
3761
3820
  const boardId = String(body.boardId || '');
3762
3821
  const n = Math.max(1, Math.min(100, Number(body.depth) || 10));
3763
- if (!boardId)
3764
- return send(400, { error: 'boardId 必填' });
3822
+ if (!boardId || !isValidBoardId(boardId))
3823
+ return send(400, { error: 'boardId 必填且只能是字母、数字、点、下划线、连字符' });
3765
3824
  const st2 = readState();
3766
3825
  st2.depths = { ...(st2.depths || {}), [boardId]: n };
3767
3826
  writeState(st2);
@@ -3818,8 +3877,8 @@ export function apply(ctx, config) {
3818
3877
  catch (e) {
3819
3878
  return send(400, { error: e instanceof Error ? e.message : String(e) });
3820
3879
  }
3821
- if (!boardId)
3822
- return send(400, { error: 'boardId 必填' });
3880
+ if (!boardId || !isValidBoardId(boardId))
3881
+ return send(400, { error: 'boardId 必填且只能是字母、数字、点、下划线、连字符' });
3823
3882
  const stDay = readState();
3824
3883
  const site = serveSiteFor([boardId], stDay.depths || {})[0];
3825
3884
  if (!site)
@@ -3872,6 +3931,8 @@ export function apply(ctx, config) {
3872
3931
  return send(200, { ok: true, dropped: date, gone: !existsSync(dir) });
3873
3932
  }
3874
3933
  const b = String(body.boardId || 'qidiantu.shouding');
3934
+ if (!isValidBoardId(b))
3935
+ return send(400, { error: 'boardId 含非法字符(只允许字母、数字、点、下划线、连字符)' });
3875
3936
  const st4 = readState();
3876
3937
  const site = serveSiteFor([b], st4.depths || {})[0];
3877
3938
  if (!site)
@@ -3931,8 +3992,8 @@ export function apply(ctx, config) {
3931
3992
  if (String(req.method || 'GET').toUpperCase() !== 'POST')
3932
3993
  return send(405, { error: 'POST only' });
3933
3994
  const b = q.get('boardId');
3934
- if (!b)
3935
- return send(400, { error: 'boardId 必填' });
3995
+ if (!b || !isValidBoardId(b))
3996
+ return send(400, { error: 'boardId 必填且只能是字母、数字、点、下划线、连字符' });
3936
3997
  const resE = await enrichBoard(b, forceQ);
3937
3998
  /**
3938
3999
  * ★ 2026-10-17:手动「补全本榜」补齐后要**把待办销掉** —— 以前只有后台工人那一圈会清,
@@ -3968,6 +4029,8 @@ export function apply(ctx, config) {
3968
4029
  return send(405, { error: 'POST only' });
3969
4030
  const forceQ = q.get('force') === '1' || q.get('force') === 'true';
3970
4031
  const bid = q.get('boardId');
4032
+ if (bid && !isValidBoardId(bid))
4033
+ return send(400, { error: 'boardId 含非法字符(只允许字母、数字、点、下划线、连字符)' });
3971
4034
  if (bid)
3972
4035
  return send(200, await qidianEnrichBoard(bid, forceQ));
3973
4036
  // 不带 boardId = 把抓取集里的起点榜逐个补(仍受每榜请求上限保护)
@@ -4106,6 +4169,9 @@ export function apply(ctx, config) {
4106
4169
  if (action === 'add') {
4107
4170
  let row = body.row || null;
4108
4171
  let boardId = String(body.boardId || '');
4172
+ // ★ 审查 M1:boardId 会用于 readSnapshot 路径拼接 ⇒ 先卡格式
4173
+ if (boardId && !isValidBoardId(boardId))
4174
+ return send(400, { error: 'boardId 含非法字符(只允许字母、数字、点、下划线、连字符)' });
4109
4175
  let dataDate = String(body.dataDate || '');
4110
4176
  /**
4111
4177
  * ★ 只给了 bookKey 的情况(「变化集」就是这么调用的):去本地快照里把这本书找出来,
@@ -4291,7 +4357,13 @@ export function apply(ctx, config) {
4291
4357
  if (String(req.method || 'GET').toUpperCase() !== 'POST')
4292
4358
  return send(405, { error: 'POST only' });
4293
4359
  const body3 = await readBody(req);
4294
- const dir = String(body3.path || '').trim() || join(homedir(), 'Documents', 'rank-scan-export');
4360
+ // ★ 2026-11-02(审查 M2):与 export-file 同一道白名单 —— 只允许用户目录内的路径,
4361
+ // 且**先校验再 existsSync**:UNC 路径(\\host\share)光 existsSync 就会发起 SMB 认证,
4362
+ // 把本地 NTLM 哈希发给攻击者主机。
4363
+ const dir = resolve(String(body3.path || '').trim() || join(homedir(), 'Documents', 'rank-scan-export'));
4364
+ const relF = relative(resolve(homedir()), dir);
4365
+ if (!relF || relF === '..' || relF.startsWith('..' + (process.platform === 'win32' ? '\\' : '/')) || isAbsolute(relF))
4366
+ return send(400, { error: '只允许打开用户目录内的文件夹' });
4295
4367
  if (!existsSync(dir))
4296
4368
  return send(400, { error: '目录还不存在:' + dir + '(先导出一次就会创建)' });
4297
4369
  const cmd = process.platform === 'win32' ? 'explorer.exe' : process.platform === 'darwin' ? 'open' : 'xdg-open';