dsh-rank-scan 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/lib/client.js +408 -125
- 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.4.
|
|
21
|
+
# 钉版本:github:kilo-s/dsh-rank-scan#v0.4.1
|
|
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.4.
|
|
40
|
+
# 钉版本:dsh-rank-scan@0.4.1
|
|
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.4.
|
|
47
|
+
**更新**:重跑安装命令即可(链接直装取最新 `main`,registry 装取最新发布版;本版本为 **0.4.1**);面板「设置」页底部会读 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
|
@@ -207,6 +207,15 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
|
|
|
207
207
|
'.rs-banner.is-warn{border-color:' + T.warn + ';background:' + wash(T.warn, 10) + '}',
|
|
208
208
|
'.rs-banner.is-error{border-color:' + T.bad + ';background:' + wash(T.bad, 8) + '}',
|
|
209
209
|
'.rs-banner .rs-banner-body{flex:1 1 100%;min-width:0}',
|
|
210
|
+
'.rs-toasts{position:absolute;right:12px;top:64px;bottom:auto;z-index:95;display:flex;flex-direction:column;gap:6px;max-width:min(380px,calc(100% - 24px));max-height:calc(100% - 80px);overflow:auto;pointer-events:none}',
|
|
211
|
+
'.rs-toast{pointer-events:auto;display:flex;align-items:flex-start;gap:8px;padding:7px 9px;border-radius:' + T.r.s + ';border:1px solid;border-left-width:3px;background:' + T.surface + ';color:' + T.fg + ';box-shadow:' + T.shadowMenu + ';font-size:' + T.fs.s + ';line-height:1.45}',
|
|
212
|
+
'.rs-toast.is-info{border-color:' + T.accent + ';background-image:linear-gradient(' + wash(T.accent, 10) + ',' + wash(T.accent, 10) + ')}',
|
|
213
|
+
'.rs-toast.is-warn{border-color:' + T.warn + ';background-image:linear-gradient(' + wash(T.warn, 12) + ',' + wash(T.warn, 12) + ')}',
|
|
214
|
+
'.rs-toast.is-error{border-color:' + T.bad + ';background-image:linear-gradient(' + wash(T.bad, 10) + ',' + wash(T.bad, 10) + ')}',
|
|
215
|
+
'.rs-toast.is-success{border-color:' + T.ok + ';background-image:linear-gradient(' + wash(T.ok, 10) + ',' + wash(T.ok, 10) + ')}',
|
|
216
|
+
'.rs-toast-text{flex:1 1 auto;min-width:0;white-space:pre-wrap;word-break:break-word}',
|
|
217
|
+
'.rs-toast-x{border:none;background:transparent;color:inherit;cursor:pointer;font-size:14px;line-height:1;padding:0 2px;font-family:inherit}',
|
|
218
|
+
'.rs-toast-x:focus-visible{outline:2px solid ' + T.accent + ';outline-offset:1px}',
|
|
210
219
|
'[data-rank-scan-win] tbody tr:hover td{background:' + T.subtle + '}',
|
|
211
220
|
'[data-rank-scan-win] a:focus-visible{outline:2px solid ' + T.accent + ';outline-offset:1px}',
|
|
212
221
|
].join('\n')
|
|
@@ -260,6 +269,91 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
|
|
|
260
269
|
return h('div', { className: 'rs-banner is-' + (props.tone || 'info'), role: role },
|
|
261
270
|
props.title ? h('strong', null, props.title) : null, props.children)
|
|
262
271
|
}
|
|
272
|
+
/**
|
|
273
|
+
* Toast:模块级队列,任何页签直接 toast(tone, text),不必层层传 props。
|
|
274
|
+
* success/info/warn 4 秒自动消失;error 常驻,带关闭按钮。最多同时 3 条。
|
|
275
|
+
*/
|
|
276
|
+
const TOAST_MAX = 3
|
|
277
|
+
const toastStore = (function () {
|
|
278
|
+
const subs = new Set()
|
|
279
|
+
const timers = new Map()
|
|
280
|
+
let items = []
|
|
281
|
+
let seq = 0
|
|
282
|
+
const emit = function () { subs.forEach(function (f) { try { f(items.slice()) } catch (e) {} }) }
|
|
283
|
+
const drop = function (id) {
|
|
284
|
+
items = items.filter(function (t) { return t.id !== id })
|
|
285
|
+
const tm = timers.get(id)
|
|
286
|
+
if (tm) { clearTimeout(tm); timers.delete(id) }
|
|
287
|
+
emit()
|
|
288
|
+
}
|
|
289
|
+
const arm = function (t) {
|
|
290
|
+
if (t.tone === 'error') return
|
|
291
|
+
const tm = setTimeout(function () { drop(t.id) }, t.ms || 4000)
|
|
292
|
+
timers.set(t.id, tm)
|
|
293
|
+
}
|
|
294
|
+
const push = function (tone, text, opts) {
|
|
295
|
+
const o = opts || {}
|
|
296
|
+
const t = { id: 'toast-' + (++seq), tone: tone || 'info', text: String(text == null ? '' : text), ms: o.ms || 4000 }
|
|
297
|
+
items = items.concat(t)
|
|
298
|
+
while (items.length > (o.max || TOAST_MAX)) {
|
|
299
|
+
const old = items.shift()
|
|
300
|
+
const tm = timers.get(old.id)
|
|
301
|
+
if (tm) { clearTimeout(tm); timers.delete(old.id) }
|
|
302
|
+
}
|
|
303
|
+
emit()
|
|
304
|
+
arm(t)
|
|
305
|
+
return t.id
|
|
306
|
+
}
|
|
307
|
+
const pause = function (id) { const tm = timers.get(id); if (tm) { clearTimeout(tm); timers.delete(id) } }
|
|
308
|
+
const resume = function (id) { const t = items.filter(function (x) { return x.id === id })[0]; if (t) arm(t) }
|
|
309
|
+
return {
|
|
310
|
+
push: push,
|
|
311
|
+
remove: drop,
|
|
312
|
+
pause: pause,
|
|
313
|
+
resume: resume,
|
|
314
|
+
get: function () { return items.slice() },
|
|
315
|
+
subscribe: function (f) { subs.add(f); return function () { subs.delete(f) } },
|
|
316
|
+
}
|
|
317
|
+
})()
|
|
318
|
+
/** 最近一条提示:诊断复制与「最近提示」用(不进 Toast 的纯状态文字不会进来) */
|
|
319
|
+
const lastNote = (function () {
|
|
320
|
+
let v = ''
|
|
321
|
+
const subs = new Set()
|
|
322
|
+
return {
|
|
323
|
+
get: function () { return v },
|
|
324
|
+
set: function (s) { v = String(s == null ? '' : s); subs.forEach(function (f) { try { f(v) } catch (e) {} }) },
|
|
325
|
+
subscribe: function (f) { subs.add(f); return function () { subs.delete(f) } },
|
|
326
|
+
}
|
|
327
|
+
})()
|
|
328
|
+
const toast = function (tone, text, opts) {
|
|
329
|
+
const s = String(text == null ? '' : text)
|
|
330
|
+
lastNote.set(s)
|
|
331
|
+
return toastStore.push(tone, s, opts)
|
|
332
|
+
}
|
|
333
|
+
function useLastNote() {
|
|
334
|
+
const [v, setV] = React.useState(lastNote.get())
|
|
335
|
+
React.useEffect(function () { return lastNote.subscribe(setV) }, [])
|
|
336
|
+
return v
|
|
337
|
+
}
|
|
338
|
+
function ToastHost() {
|
|
339
|
+
const [items, setItems] = React.useState(toastStore.get())
|
|
340
|
+
React.useEffect(function () { return toastStore.subscribe(setItems) }, [])
|
|
341
|
+
if (!items.length) return null
|
|
342
|
+
return h('div', { className: 'rs-toasts' },
|
|
343
|
+
items.map(function (t) {
|
|
344
|
+
return h('div', {
|
|
345
|
+
key: t.id,
|
|
346
|
+
className: 'rs-toast is-' + t.tone,
|
|
347
|
+
role: t.tone === 'error' ? 'alert' : 'status',
|
|
348
|
+
onMouseEnter: function () { toastStore.pause(t.id) },
|
|
349
|
+
onMouseLeave: function () { toastStore.resume(t.id) },
|
|
350
|
+
},
|
|
351
|
+
h('span', { className: 'rs-toast-text' }, t.text),
|
|
352
|
+
t.tone === 'error'
|
|
353
|
+
? h('button', { className: 'rs-toast-x', onClick: function () { toastStore.remove(t.id) }, 'aria-label': '关闭提示', title: '关闭' }, '×')
|
|
354
|
+
: null)
|
|
355
|
+
}))
|
|
356
|
+
}
|
|
263
357
|
/**
|
|
264
358
|
* ★ 2026-10-17(易用性 P0):哪些列算「数字列」—— 只有它们套 C.num(不折行 + 等宽数字)。
|
|
265
359
|
* 书名/作者/分类这类文本列仍允许换行,否则长书名会把整张表撑宽。
|
|
@@ -1294,13 +1388,76 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
|
|
|
1294
1388
|
* · 扫描计划:开关即时生效(旁边写明开/关;失败回退),时刻改动走「保存计划」
|
|
1295
1389
|
* · 全站补全从榜单页挪到这里(按站「更多」),榜单页只保留「补全缺失字段」
|
|
1296
1390
|
*/
|
|
1391
|
+
/**
|
|
1392
|
+
* 设置草稿 vs 已保存快照的差异(纯函数)。
|
|
1393
|
+
* captures 按集合比较(顺序不算变化);siteTimes 按字段比较。返回人类可读的分组名;空数组 = 干净。
|
|
1394
|
+
*/
|
|
1395
|
+
const settingsDiff = function (saved, draft) {
|
|
1396
|
+
const out = []
|
|
1397
|
+
if (!saved || !draft) return out
|
|
1398
|
+
const a = Array.isArray(saved.captures) ? saved.captures.slice().sort() : []
|
|
1399
|
+
const b = Array.isArray(draft.captures) ? draft.captures.slice().sort() : []
|
|
1400
|
+
if (a.length !== b.length || a.some(function (x, i) { return x !== b[i] })) out.push('抓取范围')
|
|
1401
|
+
if (!!saved.autoEnrich !== !!draft.autoEnrich) out.push('自动补全')
|
|
1402
|
+
if (!!saved.qidianEnrich !== !!draft.qidianEnrich) out.push('起点收藏补全')
|
|
1403
|
+
if (Number(saved.requestIntervalMs) !== Number(draft.requestIntervalMs)) out.push('请求间隔')
|
|
1404
|
+
const st = saved.siteTimes || {}
|
|
1405
|
+
const dt = draft.siteTimes || {}
|
|
1406
|
+
const keys = Object.keys(Object.assign({}, st, dt))
|
|
1407
|
+
if (keys.some(function (k) { return String(st[k] || '') !== String(dt[k] || '') })) out.push('计划时刻')
|
|
1408
|
+
if (String(saved.fallbackTime || '') !== String(draft.fallbackTime || '')) out.push('兜底时刻')
|
|
1409
|
+
// 保留天数在 /overview 到达前是未知(null):先不参与 diff,避免把「读取中」误判成改动
|
|
1410
|
+
if (saved.retentionDays != null && draft.retentionDays != null && String(saved.retentionDays) !== String(draft.retentionDays)) out.push('保留天数')
|
|
1411
|
+
return out
|
|
1412
|
+
}
|
|
1413
|
+
const daysOf = function (v) { return v === 'forever' ? Infinity : Number(v) }
|
|
1414
|
+
/** 只有两边都已知且草稿更短才算「会删数据」;未知时绝不弹删除确认 */
|
|
1415
|
+
const retentionShortensOf = function (saved, draft) {
|
|
1416
|
+
if (!saved || !draft) return false
|
|
1417
|
+
if (saved.retentionDays == null || draft.retentionDays == null) return false
|
|
1418
|
+
return daysOf(draft.retentionDays) < daysOf(saved.retentionDays)
|
|
1419
|
+
}
|
|
1420
|
+
/** 从 /catalog + overview 生成「已保存」快照 */
|
|
1421
|
+
const settingsSavedFrom = function (c, ov) {
|
|
1422
|
+
const t = (c && c.timer) || {}
|
|
1423
|
+
const rd = ov && ov.storage && (typeof ov.storage.retentionDays === 'number' || ov.storage.retentionDays === 'forever') ? ov.storage.retentionDays : null
|
|
1424
|
+
return {
|
|
1425
|
+
captures: ((c && c.captures) || []).slice(),
|
|
1426
|
+
autoEnrich: !(c && c.autoEnrich === false),
|
|
1427
|
+
qidianEnrich: !!(c && c.qidian && c.qidian.enrich),
|
|
1428
|
+
requestIntervalMs: c && typeof c.requestIntervalMs === 'number' ? c.requestIntervalMs : 1000,
|
|
1429
|
+
siteTimes: Object.assign({}, (t && t.siteTimes) || {}),
|
|
1430
|
+
fallbackTime: (t && t.fallbackTime) || '22:30',
|
|
1431
|
+
retentionDays: rd,
|
|
1432
|
+
}
|
|
1433
|
+
}
|
|
1434
|
+
/** 旧草稿(picked/times/fall)→ 新草稿形状;缺失字段回落到已保存快照 */
|
|
1435
|
+
const settingsDraftFrom = function (d, saved) {
|
|
1436
|
+
const sv = saved || {}
|
|
1437
|
+
return {
|
|
1438
|
+
captures: Array.isArray(d.captures) ? d.captures.slice() : (Array.isArray(d.picked) ? d.picked.slice() : (sv.captures || []).slice()),
|
|
1439
|
+
autoEnrich: typeof d.autoEnrich === 'boolean' ? d.autoEnrich : !!sv.autoEnrich,
|
|
1440
|
+
qidianEnrich: typeof d.qidianEnrich === 'boolean' ? d.qidianEnrich : !!sv.qidianEnrich,
|
|
1441
|
+
requestIntervalMs: typeof d.requestIntervalMs === 'number' ? d.requestIntervalMs : (typeof sv.requestIntervalMs === 'number' ? sv.requestIntervalMs : 1000),
|
|
1442
|
+
siteTimes: d.siteTimes && typeof d.siteTimes === 'object' ? Object.assign({}, d.siteTimes) : (d.times && typeof d.times === 'object' ? Object.assign({}, d.times) : Object.assign({}, sv.siteTimes || {})),
|
|
1443
|
+
fallbackTime: typeof d.fallbackTime === 'string' ? d.fallbackTime : (typeof d.fall === 'string' ? d.fall : (sv.fallbackTime || '22:30')),
|
|
1444
|
+
retentionDays: (typeof d.retentionDays === 'number' || d.retentionDays === 'forever') ? d.retentionDays : (sv.retentionDays == null ? null : sv.retentionDays),
|
|
1445
|
+
}
|
|
1446
|
+
}
|
|
1447
|
+
/**
|
|
1448
|
+
* 设置页保存语义(0.4.1):
|
|
1449
|
+
* · 即时生效:只有「定时扫描」开关(乐观置位 + 失败回滚,结果走 Toast)。
|
|
1450
|
+
* · 草稿 + 底栏保存:抓取范围、自动补全、起点收藏补全、请求间隔、各站计划时刻、兜底时刻、保留天数。
|
|
1451
|
+
* · 动作按钮(不是设置,点了就做):补全起点收藏、清空书页缓存、补齐该站缺失字段、复制诊断、检查更新;
|
|
1452
|
+
* 保持原行为,结果走 Toast。
|
|
1453
|
+
*/
|
|
1297
1454
|
function SettingsTab(props) {
|
|
1298
1455
|
const ov = props.ov
|
|
1456
|
+
const ovRef = React.useRef(ov)
|
|
1457
|
+
ovRef.current = ov
|
|
1299
1458
|
const [cat, setCat] = React.useState(null)
|
|
1300
1459
|
const [picked, setPicked] = React.useState(null)
|
|
1301
|
-
const [note, setNote] = React.useState(null)
|
|
1302
1460
|
const [busy, setBusy] = React.useState(false)
|
|
1303
|
-
const [dirty, setDirty] = React.useState(false)
|
|
1304
1461
|
const [autoEnrich, setAutoEnrich] = React.useState(true)
|
|
1305
1462
|
const [qdEnrich, setQdEnrich] = React.useState(false)
|
|
1306
1463
|
const [qdCache, setQdCache] = React.useState(null)
|
|
@@ -1308,40 +1465,75 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
|
|
|
1308
1465
|
const [tOn, setTOn] = React.useState(false)
|
|
1309
1466
|
const [tTimes, setTTimes] = React.useState({})
|
|
1310
1467
|
const [tFall, setTFall] = React.useState('22:30')
|
|
1311
|
-
const [tNote, setTNote] = React.useState(null)
|
|
1312
1468
|
const [tLast, setTLast] = React.useState(null)
|
|
1313
1469
|
const [planLive, setPlanLive] = React.useState(null)
|
|
1314
|
-
const [
|
|
1470
|
+
const [retentionDays, setRetentionDays] = React.useState(null)
|
|
1471
|
+
const [saved, setSaved] = React.useState(null)
|
|
1472
|
+
const savedRef = React.useRef(null)
|
|
1473
|
+
const [barNote, setBarNote] = React.useState('')
|
|
1474
|
+
const [retentionConfirm, setRetentionConfirm] = React.useState(false)
|
|
1475
|
+
const lastNote = useLastNote()
|
|
1315
1476
|
/** 站分组默认展开(含已勾选榜的站更该展开);只记「被收起」的,避免新站默认藏着 */
|
|
1316
1477
|
const [closedGroups, setClosedGroups] = React.useState({})
|
|
1317
1478
|
const load = React.useCallback(function () {
|
|
1318
1479
|
jget('/catalog').then(function (c) {
|
|
1319
1480
|
setCat(c)
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1481
|
+
const sv = settingsSavedFrom(c, ovRef.current)
|
|
1482
|
+
savedRef.current = sv
|
|
1483
|
+
setSaved(sv)
|
|
1484
|
+
setPicked(sv.captures.slice())
|
|
1485
|
+
setAutoEnrich(sv.autoEnrich)
|
|
1486
|
+
setQdEnrich(sv.qidianEnrich)
|
|
1323
1487
|
setQdCache(c.qidian || null)
|
|
1324
|
-
setIntervalMs(
|
|
1325
|
-
|
|
1488
|
+
setIntervalMs(sv.requestIntervalMs)
|
|
1489
|
+
setRetentionDays(sv.retentionDays)
|
|
1490
|
+
noteRequestInterval(sv.requestIntervalMs)
|
|
1326
1491
|
const t = c.timer || {}
|
|
1327
1492
|
setTOn(t.enabled === true)
|
|
1328
|
-
setTTimes(
|
|
1329
|
-
setTFall(
|
|
1493
|
+
setTTimes(Object.assign({}, sv.siteTimes))
|
|
1494
|
+
setTFall(sv.fallbackTime)
|
|
1330
1495
|
setTLast(t)
|
|
1331
1496
|
// ★ 组件被卸载过:草稿优先(不拿服务端值盖掉用户没保存的选择)
|
|
1332
1497
|
const d = DRAFTS.settings
|
|
1333
|
-
if (d
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1498
|
+
if (d) {
|
|
1499
|
+
const dd = settingsDraftFrom(d, sv)
|
|
1500
|
+
setPicked(dd.captures.slice())
|
|
1501
|
+
setAutoEnrich(dd.autoEnrich)
|
|
1502
|
+
setQdEnrich(dd.qidianEnrich)
|
|
1503
|
+
setIntervalMs(dd.requestIntervalMs)
|
|
1504
|
+
setTTimes(Object.assign({}, dd.siteTimes))
|
|
1505
|
+
setTFall(dd.fallbackTime)
|
|
1506
|
+
setRetentionDays(dd.retentionDays)
|
|
1507
|
+
setBarNote('已恢复未保存的改动(还没保存)')
|
|
1508
|
+
} else {
|
|
1509
|
+
setBarNote('')
|
|
1510
|
+
}
|
|
1511
|
+
}).catch(function (e) {
|
|
1512
|
+
toast('error', '设置加载失败:' + e)
|
|
1513
|
+
setBarNote('设置加载失败:' + e)
|
|
1514
|
+
})
|
|
1343
1515
|
}, [])
|
|
1344
1516
|
React.useEffect(function () { load() }, [load])
|
|
1517
|
+
/**
|
|
1518
|
+
* /overview 可能晚于 /catalog 到达(面板直接停在设置页时尤其常见):
|
|
1519
|
+
* 保留天数未知时先禁用 select、不参与 diff;值到达或变化后补进 saved,
|
|
1520
|
+
* 草稿里的保留天数若当时不脏,跟着同步,避免把「变长」误判成「删数据」。
|
|
1521
|
+
*/
|
|
1522
|
+
React.useEffect(function () {
|
|
1523
|
+
const rd = ov && ov.storage && (typeof ov.storage.retentionDays === 'number' || ov.storage.retentionDays === 'forever') ? ov.storage.retentionDays : null
|
|
1524
|
+
if (rd == null) return
|
|
1525
|
+
const sv = savedRef.current
|
|
1526
|
+
if (!sv) return
|
|
1527
|
+
const old = sv.retentionDays
|
|
1528
|
+
if (String(old) === String(rd)) return
|
|
1529
|
+
const next = Object.assign({}, sv, { retentionDays: rd })
|
|
1530
|
+
savedRef.current = next
|
|
1531
|
+
setSaved(next)
|
|
1532
|
+
setRetentionDays(function (cur) {
|
|
1533
|
+
if (cur == null || String(cur) === String(old)) return rd
|
|
1534
|
+
return cur
|
|
1535
|
+
})
|
|
1536
|
+
}, [ov])
|
|
1345
1537
|
// 只读的实时调度状态(3 分钟;有站到点待跑时 30 秒)——**不重载 /catalog**,免得冲掉草稿
|
|
1346
1538
|
React.useEffect(function () {
|
|
1347
1539
|
let alive = true
|
|
@@ -1359,23 +1551,34 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
|
|
|
1359
1551
|
tick()
|
|
1360
1552
|
return function () { alive = false; if (id) clearInterval(id) }
|
|
1361
1553
|
}, [])
|
|
1362
|
-
/**
|
|
1363
|
-
const
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1554
|
+
/** 统一草稿:设置项全部走这个对象;顺序固定,便于比较与持久化 */
|
|
1555
|
+
const draft = {
|
|
1556
|
+
captures: (picked || []).slice(),
|
|
1557
|
+
autoEnrich: !!autoEnrich,
|
|
1558
|
+
qidianEnrich: !!qdEnrich,
|
|
1559
|
+
requestIntervalMs: intervalMs,
|
|
1560
|
+
siteTimes: tTimes || {},
|
|
1561
|
+
fallbackTime: tFall || '',
|
|
1562
|
+
retentionDays: retentionDays,
|
|
1563
|
+
}
|
|
1564
|
+
const diff = saved ? settingsDiff(saved, draft) : []
|
|
1565
|
+
const dirty = diff.length > 0
|
|
1566
|
+
const draftKey = [
|
|
1567
|
+
draft.captures.slice().sort().join(','),
|
|
1568
|
+
draft.autoEnrich, draft.qidianEnrich, draft.requestIntervalMs,
|
|
1569
|
+
Object.keys(draft.siteTimes).sort().map(function (k) { return k + '=' + (draft.siteTimes[k] || '') }).join(','),
|
|
1570
|
+
draft.fallbackTime, draft.retentionDays,
|
|
1571
|
+
].join('|')
|
|
1572
|
+
/** 草稿写回组件外 + 登记脏状态(面板切页/收起前据此拦一下) */
|
|
1371
1573
|
React.useEffect(function () {
|
|
1372
|
-
if (!
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
DRAFTS.settings = { picked: (picked || []).slice(), autoEnrich: !!autoEnrich, qdEnrich: !!qdEnrich, times: tTimes || {}, fall: tFall || '', dirty: !!dirty }
|
|
1574
|
+
if (!saved) return
|
|
1575
|
+
if (!dirty) { DRAFTS.settings = null; dirtyGuard.set('settings', false); return }
|
|
1576
|
+
DRAFTS.settings = Object.assign({}, draft, { dirty: true })
|
|
1376
1577
|
dirtyGuard.set('settings', true)
|
|
1377
|
-
}, [
|
|
1378
|
-
|
|
1578
|
+
}, [draftKey, saved, dirty])
|
|
1579
|
+
/** 草稿一变就收起删除确认,避免确认的是旧值 */
|
|
1580
|
+
React.useEffect(function () { setRetentionConfirm(false) }, [draftKey])
|
|
1581
|
+
if (!cat || !picked) return h('div', { style: C.muted }, barNote || '加载中…')
|
|
1379
1582
|
const has = function (id) { return picked.indexOf(id) >= 0 }
|
|
1380
1583
|
const toggle = function (id, on) {
|
|
1381
1584
|
const next = picked.slice()
|
|
@@ -1383,13 +1586,12 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
|
|
|
1383
1586
|
if (on && at < 0) next.push(id)
|
|
1384
1587
|
if (!on && at >= 0) next.splice(at, 1)
|
|
1385
1588
|
setPicked(next)
|
|
1386
|
-
|
|
1387
|
-
setNote(null)
|
|
1589
|
+
setBarNote('')
|
|
1388
1590
|
}
|
|
1389
1591
|
const setAll = function (site, on) {
|
|
1390
1592
|
const ids = cat.boards.filter(function (b) { return b.site === site }).map(function (b) { return b.boardId })
|
|
1391
1593
|
setPicked(on ? picked.concat(ids.filter(function (i) { return picked.indexOf(i) < 0 })) : picked.filter(function (i) { return ids.indexOf(i) < 0 }))
|
|
1392
|
-
|
|
1594
|
+
setBarNote('')
|
|
1393
1595
|
}
|
|
1394
1596
|
/**
|
|
1395
1597
|
* ★ Spec S4「恢复默认」:只改**草稿**,并说清将新增/移除多少 —— 保存后才生效。
|
|
@@ -1399,31 +1601,107 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
|
|
|
1399
1601
|
const restoreDefaults = function () {
|
|
1400
1602
|
const def = cat && Array.isArray(cat.defaultCaptures) ? cat.defaultCaptures.slice() : null
|
|
1401
1603
|
if (!def || !def.length) {
|
|
1402
|
-
|
|
1604
|
+
setBarNote('这台宿主没有提供默认抓取集(catalog.defaultCaptures 缺失),只能手动勾选')
|
|
1605
|
+
toast('warn', '这台宿主没有提供默认抓取集,只能手动勾选')
|
|
1403
1606
|
return
|
|
1404
1607
|
}
|
|
1405
1608
|
const add = def.filter(function (id) { return picked.indexOf(id) < 0 })
|
|
1406
1609
|
const del = picked.filter(function (id) { return def.indexOf(id) < 0 })
|
|
1407
1610
|
setPicked(def)
|
|
1408
|
-
|
|
1409
|
-
setNote('已恢复默认抓取:将新增 ' + add.length + ' 个、移除 ' + del.length + ' 个(点「保存设置」才落盘)')
|
|
1611
|
+
setBarNote('已恢复默认抓取:将新增 ' + add.length + ' 个、移除 ' + del.length + ' 个(点「保存设置」才落盘)')
|
|
1410
1612
|
}
|
|
1411
1613
|
const toggleGroup = function (key) {
|
|
1412
1614
|
const nx = Object.assign({}, closedGroups)
|
|
1413
1615
|
nx[key] = !nx[key]
|
|
1414
1616
|
setClosedGroups(nx)
|
|
1415
1617
|
}
|
|
1416
|
-
|
|
1618
|
+
/** 动作后只刷新起点缓存计数;不重跑 load(否则会把未保存草稿写成「已恢复未保存的改动」) */
|
|
1619
|
+
const refreshQd = function () {
|
|
1620
|
+
return jget('/catalog').then(function (c) {
|
|
1621
|
+
setQdCache((c && c.qidian) || null)
|
|
1622
|
+
setCat(c)
|
|
1623
|
+
}).catch(function () {})
|
|
1624
|
+
}
|
|
1625
|
+
const retentionKnown = !!(saved && saved.retentionDays != null)
|
|
1626
|
+
const retentionLabel = retentionDays == null ? '读取中' : (retentionDays === 'forever' ? '永久' : retentionDays + ' 天')
|
|
1627
|
+
const retentionShortens = !!(diff.indexOf('保留天数') >= 0 && retentionShortensOf(saved, draft))
|
|
1628
|
+
/** 底栏保存:按变化分组顺序提交;成功的组并入 saved,失败的组留在草稿里继续算脏 */
|
|
1629
|
+
const doSave = function () {
|
|
1630
|
+
if (busy) return
|
|
1631
|
+
const d = draft
|
|
1632
|
+
const changes = diff.slice()
|
|
1633
|
+
const selChanged = changes.some(function (x) { return x === '抓取范围' || x === '自动补全' || x === '起点收藏补全' || x === '请求间隔' })
|
|
1634
|
+
const timerChanged = changes.some(function (x) { return x === '计划时刻' || x === '兜底时刻' })
|
|
1635
|
+
const retChanged = changes.indexOf('保留天数') >= 0
|
|
1636
|
+
const done = []
|
|
1637
|
+
const failed = []
|
|
1638
|
+
const notes = []
|
|
1639
|
+
let nextSaved = saved ? Object.assign({}, saved, { captures: (saved.captures || []).slice(), siteTimes: Object.assign({}, saved.siteTimes || {}) }) : null
|
|
1417
1640
|
setBusy(true)
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1641
|
+
setRetentionConfirm(false)
|
|
1642
|
+
const run = async function () {
|
|
1643
|
+
if (selChanged) {
|
|
1644
|
+
try {
|
|
1645
|
+
const r = await jpost('/select', { captures: d.captures, autoEnrich: d.autoEnrich, qidianEnrich: d.qidianEnrich, requestIntervalMs: d.requestIntervalMs })
|
|
1646
|
+
if (r && r.note) notes.push(r.note)
|
|
1647
|
+
nextSaved = Object.assign({}, nextSaved, { captures: d.captures.slice(), autoEnrich: d.autoEnrich, qidianEnrich: d.qidianEnrich, requestIntervalMs: d.requestIntervalMs })
|
|
1648
|
+
done.push('抓取/补全/间隔')
|
|
1649
|
+
} catch (e) { failed.push('抓取/补全/间隔:' + e) }
|
|
1650
|
+
}
|
|
1651
|
+
if (timerChanged) {
|
|
1652
|
+
try {
|
|
1653
|
+
const r = await jpost('/timer', { enabled: tOn, siteTimes: d.siteTimes, fallbackTime: d.fallbackTime })
|
|
1654
|
+
if (r && r.note) notes.push(r.note)
|
|
1655
|
+
nextSaved = Object.assign({}, nextSaved, { siteTimes: Object.assign({}, d.siteTimes), fallbackTime: d.fallbackTime })
|
|
1656
|
+
done.push('计划时刻')
|
|
1657
|
+
} catch (e) { failed.push('计划时刻:' + e) }
|
|
1658
|
+
}
|
|
1659
|
+
if (retChanged) {
|
|
1660
|
+
try {
|
|
1661
|
+
const r = await jpost('/retention', { days: d.retentionDays })
|
|
1662
|
+
if (r && r.note) notes.push(r.note)
|
|
1663
|
+
nextSaved = Object.assign({}, nextSaved, { retentionDays: d.retentionDays })
|
|
1664
|
+
done.push('保留天数')
|
|
1665
|
+
} catch (e) { failed.push('保留天数:' + e) }
|
|
1666
|
+
}
|
|
1667
|
+
}
|
|
1668
|
+
run().then(function () {
|
|
1669
|
+
setBusy(false)
|
|
1670
|
+
if (nextSaved) { savedRef.current = nextSaved; setSaved(nextSaved) }
|
|
1671
|
+
if (failed.length) {
|
|
1672
|
+
toast('error', (done.length ? '已保存:' + done.join('、') + ';失败:' : '保存失败:') + failed.join(';') + '(失败项仍在草稿里,可再试)')
|
|
1673
|
+
return
|
|
1674
|
+
}
|
|
1675
|
+
DRAFTS.settings = null
|
|
1676
|
+
dirtyGuard.set('settings', false)
|
|
1677
|
+
toast('success', notes.filter(Boolean).join(';') || ('已保存:' + (changes.length ? changes.join('、') : '设置')))
|
|
1423
1678
|
if (props.onSaved) props.onSaved()
|
|
1424
1679
|
try { window.dispatchEvent(new Event('rank-scan:saved')) } catch (e) {}
|
|
1425
|
-
|
|
1426
|
-
|
|
1680
|
+
}).catch(function (e) {
|
|
1681
|
+
setBusy(false)
|
|
1682
|
+
toast('error', '保存失败:' + e)
|
|
1683
|
+
})
|
|
1684
|
+
}
|
|
1685
|
+
/** 保存入口:保留天数变短时先在底栏出确认;确认后再真正提交 */
|
|
1686
|
+
const onSaveClick = function () {
|
|
1687
|
+
if (busy) return
|
|
1688
|
+
if (retentionShortens && !retentionConfirm) { setRetentionConfirm(true); return }
|
|
1689
|
+
doSave()
|
|
1690
|
+
}
|
|
1691
|
+
const discard = function () {
|
|
1692
|
+
const sv = savedRef.current
|
|
1693
|
+
if (!sv) return
|
|
1694
|
+
setPicked(sv.captures.slice())
|
|
1695
|
+
setAutoEnrich(sv.autoEnrich)
|
|
1696
|
+
setQdEnrich(sv.qidianEnrich)
|
|
1697
|
+
setIntervalMs(sv.requestIntervalMs)
|
|
1698
|
+
setTTimes(Object.assign({}, sv.siteTimes))
|
|
1699
|
+
setTFall(sv.fallbackTime)
|
|
1700
|
+
setRetentionDays(sv.retentionDays)
|
|
1701
|
+
DRAFTS.settings = null
|
|
1702
|
+
dirtyGuard.set('settings', false)
|
|
1703
|
+
setRetentionConfirm(false)
|
|
1704
|
+
setBarNote('已放弃改动')
|
|
1427
1705
|
}
|
|
1428
1706
|
const groups = []
|
|
1429
1707
|
const seenG = {}
|
|
@@ -1444,44 +1722,38 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
|
|
|
1444
1722
|
const toggleTimer = function (next) {
|
|
1445
1723
|
const prev = tOn
|
|
1446
1724
|
setTOn(next)
|
|
1447
|
-
setTNote(next ? '正在开启…' : '正在关闭…')
|
|
1448
1725
|
jpost('/timer', { enabled: next }).then(function (r) {
|
|
1449
|
-
|
|
1726
|
+
toast('success', (r && r.note ? r.note : '已' + (next ? '开启' : '关闭')) + '(立即生效)')
|
|
1450
1727
|
return jget('/catalog').then(function (c) { setTLast(c.timer || null) })
|
|
1451
1728
|
}).catch(function (e) {
|
|
1452
1729
|
setTOn(prev)
|
|
1453
|
-
|
|
1730
|
+
toast('error', '没能' + (next ? '开启' : '关闭') + ':' + e + '(已恢复原状态)')
|
|
1454
1731
|
})
|
|
1455
1732
|
}
|
|
1456
|
-
const savePlan = function () {
|
|
1457
|
-
setTNote('保存计划中…')
|
|
1458
|
-
jpost('/timer', { enabled: tOn, siteTimes: tTimes, fallbackTime: tFall }).then(function (r) {
|
|
1459
|
-
setTNote(r && r.note ? r.note : '计划已保存')
|
|
1460
|
-
return jget('/catalog').then(function (c) { setTLast(c.timer || null) })
|
|
1461
|
-
}).catch(function (e) { setTNote('保存失败:' + e) })
|
|
1462
|
-
}
|
|
1463
1733
|
/** 全站补全:按站把抓取集里的榜逐个补(逐本 1 请求 + 当前间隔,会很慢) */
|
|
1464
1734
|
const enrichSite = function (site) {
|
|
1465
1735
|
const ids = (cat.captures || []).filter(function (id) { return String(id).split('.')[0] === site })
|
|
1466
|
-
if (!ids.length) {
|
|
1736
|
+
if (!ids.length) { setBarNote('该站当前没有勾选任何榜'); toast('warn', '该站当前没有勾选任何榜'); return }
|
|
1467
1737
|
setBusy(true)
|
|
1468
1738
|
let done = 0
|
|
1469
1739
|
let filled = 0
|
|
1470
1740
|
let seq = Promise.resolve()
|
|
1471
1741
|
ids.forEach(function (id) {
|
|
1472
1742
|
seq = seq.then(function () {
|
|
1473
|
-
|
|
1743
|
+
setBarNote('补全 ' + siteNameOf(site) + ' ' + done + '/' + ids.length + ' 个榜…')
|
|
1474
1744
|
return jpost('/enrich?boardId=' + encodeURIComponent(id)).then(function (r) {
|
|
1475
1745
|
done += 1
|
|
1476
1746
|
filled += (r && r.filled) || 0
|
|
1477
1747
|
}).catch(function () { done += 1 })
|
|
1478
1748
|
})
|
|
1479
1749
|
})
|
|
1480
|
-
seq.then(function () {
|
|
1481
|
-
|
|
1750
|
+
seq.then(function () {
|
|
1751
|
+
setBarNote('')
|
|
1752
|
+
toast('success', siteNameOf(site) + ' 补全完成:' + ids.length + ' 个榜,共补 ' + filled + ' 条')
|
|
1753
|
+
})
|
|
1754
|
+
.catch(function (e) { setBarNote(''); toast('error', '补全失败:' + e) })
|
|
1482
1755
|
.then(function () { setBusy(false) })
|
|
1483
1756
|
}
|
|
1484
|
-
const retention = ov && ov.storage ? ov.storage.retentionDays : 180
|
|
1485
1757
|
const sv = (ov && ov.services) || {}
|
|
1486
1758
|
const diag = function () {
|
|
1487
1759
|
const lines = []
|
|
@@ -1492,6 +1764,7 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
|
|
|
1492
1764
|
lines.push('定时: enabled=' + tOn + ' 时刻=' + JSON.stringify(tTimes) + ' 兜底=' + tFall)
|
|
1493
1765
|
lines.push('抓取集: ' + picked.length + ' 个榜')
|
|
1494
1766
|
lines.push('上次扫描: ' + scanLabel(ov && ov.scan))
|
|
1767
|
+
lines.push('最近提示: ' + (lastNote || '—'))
|
|
1495
1768
|
return lines.join('\n')
|
|
1496
1769
|
}
|
|
1497
1770
|
/**
|
|
@@ -1505,13 +1778,16 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
|
|
|
1505
1778
|
background: T.surface,
|
|
1506
1779
|
backgroundImage: dirty ? 'linear-gradient(' + wash(T.warn, 16) + ',' + wash(T.warn, 16) + ')' : 'none',
|
|
1507
1780
|
boxShadow: T.shadowBar } },
|
|
1781
|
+
retentionConfirm ? h(Banner, { tone: 'warn', live: false },
|
|
1782
|
+
h('span', null, '将删除早于 ' + retentionLabel + '的数据日期目录,不可恢复'),
|
|
1783
|
+
h('button', { className: 'rs-btn is-danger', disabled: busy, onClick: doSave }, '确认保存'),
|
|
1784
|
+
h('button', { className: 'rs-btn', disabled: busy, onClick: function () { setRetentionConfirm(false) } }, '取消')) : null,
|
|
1508
1785
|
h('div', { style: C.row },
|
|
1509
|
-
h('button', { className: 'rs-btn is-primary', disabled: busy || !dirty, onClick:
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
dirty ? h('span', { style: { color: T.warn } }, '有未保存的改动') : null,
|
|
1786
|
+
h('button', { className: 'rs-btn is-primary', disabled: busy || !dirty, onClick: onSaveClick }, busy ? '保存中…' : '保存设置'),
|
|
1787
|
+
dirty ? h('button', { className: 'rs-btn', disabled: busy, onClick: discard }, '放弃改动') : null,
|
|
1788
|
+
h('span', { style: { color: dirty ? T.warn : T.muted } }, dirty ? '有 ' + diff.length + ' 处未保存:' + diff.join('、') : '已保存'),
|
|
1513
1789
|
h('button', { className: 'rs-btn', disabled: busy, onClick: restoreDefaults, title: '把勾选恢复成插件默认抓取集(只改草稿,保存后生效)' }, '恢复默认'),
|
|
1514
|
-
|
|
1790
|
+
barNote ? h('span', { style: C.muted }, String(barNote).slice(0, 120)) : null))
|
|
1515
1791
|
return h('div', null,
|
|
1516
1792
|
h(Section, { title: '抓取范围(' + picked.length + ' 个榜)', defaultOpen: true },
|
|
1517
1793
|
h('div', { style: C.muted }, '勾选 = 抓什么;改动进草稿,点下面的「保存设置」才落盘(下次扫描生效)。抓到的榜就会显示。'),
|
|
@@ -1544,7 +1820,8 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
|
|
|
1544
1820
|
h(Section, { title: '扫描计划', defaultOpen: false, summary: (tOn ? '已开启' : '已关闭') + ' · 兜底 ' + (tFall || '') + ' · ' + (tLast && tLast.wired ? '自动扫描已生效' : '自动扫描未生效') },
|
|
1545
1821
|
h('label', { style: C.row },
|
|
1546
1822
|
h('input', { type: 'checkbox', checked: tOn, onChange: function (e) { toggleTimer(e.target.checked) } }),
|
|
1547
|
-
h('span', null, tOn ? '
|
|
1823
|
+
h('span', null, tOn ? '已开启' : '已关闭'),
|
|
1824
|
+
h('span', { style: C.muted }, '立即生效'),
|
|
1548
1825
|
h('span', { style: C.muted }, '按站分时:每站放它自己的刷新点之后抓一次,一次只跑一个站')),
|
|
1549
1826
|
h('div', null, [['qidian', '起点'], ['sfacg', '菠萝包'], ['fanqie', '番茄'], ['ciweimao', '刺猬猫'], ['qidiantu', '起点图']].map(function (s) {
|
|
1550
1827
|
const key = s[0]
|
|
@@ -1569,40 +1846,38 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
|
|
|
1569
1846
|
h('span', { style: { width: '46px', flex: '0 0 auto' } }, '兜底'),
|
|
1570
1847
|
h('input', { type: 'time', style: { ...C.input, width: '92px' }, value: tFall, onChange: function (e) { setTFall(e.target.value) } }),
|
|
1571
1848
|
h('span', { style: C.muted }, '当天失败或内容待核对的站,到这个点再补一次(每站每天一次)')),
|
|
1572
|
-
timesDirty ? h('div', { style: C.row },
|
|
1573
|
-
h('button', { className: 'rs-btn', onClick: savePlan }, '保存计划'),
|
|
1574
|
-
h('span', { style: { color: T.warn } }, '时刻有改动,未保存')) : null,
|
|
1575
1849
|
h('div', { style: C.muted }, '状态更新于 ' + ((planLive && planLive.now) || '—') + (planLive && planLive.installedToday ? ' · 今天刚安装:安装当天不自动跑,明天起按上面的时刻执行' : '')),
|
|
1576
|
-
|
|
1577
|
-
h(Section, { title: '数据与性能', defaultOpen: false, summary: (ov && ov.storage ? '数据目录 ' + fmtBytes(ov.storage.totalBytes) + ' · 保留 ' +
|
|
1850
|
+
),
|
|
1851
|
+
h(Section, { title: '数据与性能', defaultOpen: false, summary: (ov && ov.storage ? '数据目录 ' + fmtBytes(ov.storage.totalBytes) + ' · 保留 ' + retentionLabel : '') },
|
|
1578
1852
|
h('div', { style: C.row },
|
|
1579
1853
|
h('span', { style: C.muted }, '保留'),
|
|
1580
1854
|
h('select', {
|
|
1581
1855
|
style: { ...C.input, width: 'auto', padding: '1px 4px' },
|
|
1582
|
-
value: String(
|
|
1583
|
-
|
|
1856
|
+
value: retentionKnown ? String(retentionDays) : '__loading',
|
|
1857
|
+
disabled: !retentionKnown || busy,
|
|
1858
|
+
title: retentionKnown ? '只影响数据日期目录(快照/报告);配置、书签、书页缓存永不删' : '正在读取数据目录的保留天数…',
|
|
1584
1859
|
onChange: function (e) {
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
.catch(function (e2) { setRetMsg('设置失败:' + e2) })
|
|
1860
|
+
setRetentionDays(e.target.value === 'forever' ? 'forever' : Number(e.target.value))
|
|
1861
|
+
setBarNote('')
|
|
1588
1862
|
},
|
|
1589
1863
|
},
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1864
|
+
retentionKnown
|
|
1865
|
+
? [30, 90, 180, 365].map(function (n) { return h('option', { key: n, value: String(n) }, n + ' 天') })
|
|
1866
|
+
.concat([h('option', { key: 'forever', value: 'forever' }, '永久保留')])
|
|
1867
|
+
: [h('option', { key: 'loading', value: '__loading' }, '读取中')])),
|
|
1593
1868
|
ov && ov.storage ? h('div', { style: C.muted },
|
|
1594
1869
|
'快照 ' + fmtBytes(ov.storage.snapshotBytes) + ' · state ' + fmtBytes(ov.storage.stateBytes) +
|
|
1595
1870
|
' · ' + ov.storage.dates + ' 天(' + dash(ov.storage.oldest) + ' 起)· 书签 ' + ov.storage.bookmarks + ' 条') : null,
|
|
1596
1871
|
h('label', { style: C.row },
|
|
1597
|
-
h('input', { type: 'checkbox', checked: autoEnrich, onChange: function (e) { setAutoEnrich(e.target.checked);
|
|
1872
|
+
h('input', { type: 'checkbox', checked: autoEnrich, onChange: function (e) { setAutoEnrich(e.target.checked); setBarNote('') } }),
|
|
1598
1873
|
h('span', null, '扫描后自动补全缺失字段'),
|
|
1599
1874
|
h('span', { style: C.muted }, '(榜页没有收藏/字数时要进书页取;补全在后台跑,抓榜先返回)')),
|
|
1600
1875
|
h('div', { style: { ...C.row, marginTop: '4px' } },
|
|
1601
1876
|
h('span', { style: C.muted }, '起点收藏补全'),
|
|
1602
|
-
h('input', { type: 'checkbox', checked: qdEnrich, onChange: function (e) { setQdEnrich(e.target.checked);
|
|
1877
|
+
h('input', { type: 'checkbox', checked: qdEnrich, onChange: function (e) { setQdEnrich(e.target.checked); setBarNote('') } }),
|
|
1603
1878
|
h('span', { style: C.muted }, qdEnrich ? '已开启' : '已关闭(默认关)'),
|
|
1604
|
-
h('button', { className: 'rs-btn', disabled: busy, onClick: function () { setBusy(true); jpost('/qidianEnrich').then(function (r) {
|
|
1605
|
-
h('button', { className: 'rs-btn', disabled: busy, onClick: function () { setBusy(true); jpost('/qidianCache', { clear: true }).then(function (r) {
|
|
1879
|
+
h('button', { className: 'rs-btn', disabled: busy, onClick: function () { setBusy(true); jpost('/qidianEnrich').then(function (r) { toast('success', (r && r.note) || '起点补全完成'); return refreshQd() }).catch(function (e) { toast('error', String(e)) }).then(function () { setBusy(false) }) } }, '补全起点收藏'),
|
|
1880
|
+
h('button', { className: 'rs-btn', disabled: busy, onClick: function () { setBusy(true); jpost('/qidianCache', { clear: true }).then(function (r) { toast('success', (r && r.note) || '缓存已清'); return refreshQd() }).catch(function (e) { toast('error', String(e)) }).then(function () { setBusy(false) }) } }, '清空书页缓存')),
|
|
1606
1881
|
h('div', { style: C.muted }, '起点书页缓存 ' + (qdCache && qdCache.cache ? qdCache.cache.books : 0) + ' 本 · 有效期 ' + ((qdCache && qdCache.ttlDays) || 7) + ' 天' +
|
|
1607
1882
|
(cat.bookCache ? ' · 通用书页缓存 ' + ((cat.bookCache.stat && cat.bookCache.stat.entries) || 0) + ' 本 · 有效期 ' + (cat.bookCache.ttlDays || 7) + ' 天' : '')),
|
|
1608
1883
|
h(Section, { title: '高级:请求间隔', defaultOpen: false, summary: '当前 ' + fmtIntervalText(intervalMs) },
|
|
@@ -1614,14 +1889,13 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
|
|
|
1614
1889
|
},
|
|
1615
1890
|
[200, 500, 1000, 2000, 5000].map(function (v) { return h('option', { key: v, value: String(v) }, v + ' ms' + (v === 1000 ? '(默认)' : '')) }),
|
|
1616
1891
|
h('option', { key: 0, value: '0' }, '不限速(仅本地测试)')),
|
|
1617
|
-
h('button', { className: 'rs-btn', disabled: busy, onClick: function () { setBusy(true); jpost('/select', { requestIntervalMs: intervalMs }).then(function () { setNote('请求间隔已改为 ' + (intervalMs === 0 ? '不限速' : intervalMs + 'ms')); return load() }).catch(function (e) { setNote(String(e)) }).then(function () { setBusy(false) }) } }, '应用'),
|
|
1618
1892
|
h('span', { style: C.muted }, '1s 是本项目自定的保守值(不是站点要求);调小更快,也更容易被站点注意到')))),
|
|
1619
1893
|
h(Section, { title: '关于与诊断', defaultOpen: false, summary: (sv.webServer ? '服务正常' : 'webServer 未注册') + ' · 自动扫描' + (sv.timerArmed ? '已生效' : '未生效') },
|
|
1620
|
-
h(VersionRow,
|
|
1894
|
+
h(VersionRow, null),
|
|
1621
1895
|
h('div', { style: C.muted }, '服务:webServer ' + (sv.webServer ? '✓' : '✗') + ' · timer ' + (sv.timerService ? '✓' : '✗') + ' · 定时任务' + (sv.timerArmed ? '已启用' : '未启用')),
|
|
1622
|
-
|
|
1896
|
+
lastNote ? h('div', { style: C.muted }, '最近提示:' + String(lastNote).slice(0, 160)) : null,
|
|
1623
1897
|
h('div', { style: C.row },
|
|
1624
|
-
h('button', { className: 'rs-btn', onClick: function () { try { navigator.clipboard.writeText(diag());
|
|
1898
|
+
h('button', { className: 'rs-btn', onClick: function () { try { navigator.clipboard.writeText(diag()); toast('success', '诊断信息已复制(不含凭证)') } catch (e) { toast('error', '复制失败:' + e) } } }, '复制诊断信息'))), saveBar)
|
|
1625
1899
|
}
|
|
1626
1900
|
/**
|
|
1627
1901
|
* ★ 版本区(2026-10-16):显示当前版本 + 「一键更新」。
|
|
@@ -1634,7 +1908,6 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
|
|
|
1634
1908
|
const [info, setInfo] = React.useState(null)
|
|
1635
1909
|
const [chk, setChk] = React.useState(null)
|
|
1636
1910
|
const [busy, setBusy] = React.useState('')
|
|
1637
|
-
const [note, setNote] = React.useState('')
|
|
1638
1911
|
/**
|
|
1639
1912
|
* ★ 2026-10-16 审计:一键更新的轮询链最多 30 次 × 2s(§runUpdate 的 poll)。
|
|
1640
1913
|
* 旧写法没有任何取消令牌 ⇒ 组件卸载(收起浮窗/切页签/热重载)后旧链还在 setTimeout 里
|
|
@@ -1644,7 +1917,7 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
|
|
|
1644
1917
|
function refresh(opId) {
|
|
1645
1918
|
return jget('/update-check' + (opId ? '?operationId=' + encodeURIComponent(opId) : ''))
|
|
1646
1919
|
.then(function (j) { if (aliveRef.current) setChk(j); return j })
|
|
1647
|
-
.catch(function (e) { if (aliveRef.current)
|
|
1920
|
+
.catch(function (e) { if (aliveRef.current) toast('error', '检查更新失败:' + String(e).slice(0, 80)); return null })
|
|
1648
1921
|
}
|
|
1649
1922
|
React.useEffect(function () {
|
|
1650
1923
|
aliveRef.current = true
|
|
@@ -1654,10 +1927,10 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
|
|
|
1654
1927
|
return function () { alive = false; aliveRef.current = false }
|
|
1655
1928
|
}, [])
|
|
1656
1929
|
function runUpdate() {
|
|
1657
|
-
setBusy('update');
|
|
1930
|
+
setBusy('update'); toast('info', '已请求更新…')
|
|
1658
1931
|
jpost('/update', {}).then(function (r) {
|
|
1659
1932
|
const id = r && r.operationId
|
|
1660
|
-
if (!id) {
|
|
1933
|
+
if (!id) { toast('error', (r && r.error) || '更新提供方没有返回 operationId'); return refresh() }
|
|
1661
1934
|
let n = 0
|
|
1662
1935
|
function poll() {
|
|
1663
1936
|
if (!aliveRef.current) return null
|
|
@@ -1668,16 +1941,16 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
|
|
|
1668
1941
|
if (n < 30 && (st === 'busy' || st === 'update-available')) {
|
|
1669
1942
|
return new Promise(function (res) { setTimeout(res, 2000) }).then(function () { return aliveRef.current ? poll() : j })
|
|
1670
1943
|
}
|
|
1671
|
-
if (st === 'failed')
|
|
1672
|
-
else if (j && j.action === 'refresh')
|
|
1673
|
-
else if (j && j.action === 'restart')
|
|
1674
|
-
else if (j && j.action === 'manual')
|
|
1675
|
-
else
|
|
1944
|
+
if (st === 'failed') toast('error', '更新未成功:' + ((j && j.reason) || '未知原因'))
|
|
1945
|
+
else if (j && j.action === 'refresh') toast('success', '更新完成,刷新页面即可生效')
|
|
1946
|
+
else if (j && j.action === 'restart') toast('success', '更新完成,按提示重启 DSH 生效')
|
|
1947
|
+
else if (j && j.action === 'manual') toast('success', '更新完成,但需要你自己重启 DSH 才能生效')
|
|
1948
|
+
else toast('success', '更新完成')
|
|
1676
1949
|
return j
|
|
1677
1950
|
})
|
|
1678
1951
|
}
|
|
1679
1952
|
return poll()
|
|
1680
|
-
}).catch(function (e) { if (aliveRef.current)
|
|
1953
|
+
}).catch(function (e) { if (aliveRef.current) toast('error', '更新请求失败:' + String(e).slice(0, 80)) })
|
|
1681
1954
|
.then(function () { if (aliveRef.current) setBusy('') })
|
|
1682
1955
|
}
|
|
1683
1956
|
const st = chk ? chk.state : null
|
|
@@ -1705,9 +1978,9 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
|
|
|
1705
1978
|
if (!chk) return
|
|
1706
1979
|
if (chk.action === 'refresh') { try { window.location.reload() } catch (e) {} return }
|
|
1707
1980
|
if (chk.action === 'restart') {
|
|
1708
|
-
setBusy('update');
|
|
1709
|
-
jpost('/update-restart', {}).then(function (r) {
|
|
1710
|
-
.catch(function (e) {
|
|
1981
|
+
setBusy('update'); toast('info', '已请求重启…')
|
|
1982
|
+
jpost('/update-restart', {}).then(function (r) { toast((r && r.ok) ? 'success' : 'error', (r && r.ok) ? '重启请求已发出' : ('重启失败:' + ((r && r.error) || '?'))) })
|
|
1983
|
+
.catch(function (e) { toast('error', '重启请求失败:' + String(e).slice(0, 80)) })
|
|
1711
1984
|
.then(function () { setBusy('') })
|
|
1712
1985
|
return
|
|
1713
1986
|
}
|
|
@@ -1715,8 +1988,7 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
|
|
|
1715
1988
|
else refresh()
|
|
1716
1989
|
},
|
|
1717
1990
|
}, busy !== '' ? '处理中…' : (!chk ? '检查中…' : chk.buttonLabel)),
|
|
1718
|
-
h('button', { className: 'rs-btn', disabled: busy !== '', onClick: function () {
|
|
1719
|
-
note ? h('div', { style: C.muted }, note) : null)
|
|
1991
|
+
h('button', { className: 'rs-btn', disabled: busy !== '', onClick: function () { refresh() } }, '重新检查')))
|
|
1720
1992
|
}
|
|
1721
1993
|
|
|
1722
1994
|
function cell(c, r) {
|
|
@@ -1831,7 +2103,6 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
|
|
|
1831
2103
|
const bk = props.bookKey
|
|
1832
2104
|
const [note, setNote] = React.useState('')
|
|
1833
2105
|
const [folders, setFolders] = React.useState('')
|
|
1834
|
-
const [msg, setMsg] = React.useState(null)
|
|
1835
2106
|
const [busy, setBusy] = React.useState(false)
|
|
1836
2107
|
const [loaded, setLoaded] = React.useState(false)
|
|
1837
2108
|
React.useEffect(function () {
|
|
@@ -1845,10 +2116,9 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
|
|
|
1845
2116
|
if (!bk || !store.has(bk)) return null
|
|
1846
2117
|
const save = function () {
|
|
1847
2118
|
setBusy(true)
|
|
1848
|
-
setMsg(null)
|
|
1849
2119
|
store.act({ action: 'update', bookKey: bk, note: note, folders: String(folders || '').split(/[\s,,]+/).filter(Boolean) })
|
|
1850
|
-
.then(function () { setBusy(false);
|
|
1851
|
-
.catch(function (e) { setBusy(false);
|
|
2120
|
+
.then(function () { setBusy(false); toast('success', '书签已保存'); return store.refreshList() })
|
|
2121
|
+
.catch(function (e) { setBusy(false); toast('error', '保存失败:' + e + '(草稿还在)') })
|
|
1852
2122
|
}
|
|
1853
2123
|
return h('div', { style: { ...C.detail, marginTop: '6px' } },
|
|
1854
2124
|
h('div', { style: C.row },
|
|
@@ -1857,8 +2127,7 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
|
|
|
1857
2127
|
h('div', { style: C.row },
|
|
1858
2128
|
h('span', { style: C.muted }, '书签夹'),
|
|
1859
2129
|
h('input', { style: { ...C.input, flex: 1, minWidth: '120px' }, value: folders, placeholder: '空格分隔,可属于多个夹', onChange: function (e) { setFolders(e.target.value) } }),
|
|
1860
|
-
h('button', { className: 'rs-btn is-primary', disabled: busy || !loaded, onClick: save }, busy ? '保存中…' : '保存'))
|
|
1861
|
-
msg ? h('div', { style: { ...C.muted, color: String(msg).indexOf('失败') >= 0 ? T.bad : null } }, msg) : null)
|
|
2130
|
+
h('button', { className: 'rs-btn is-primary', disabled: busy || !loaded, onClick: save }, busy ? '保存中…' : '保存')))
|
|
1862
2131
|
}
|
|
1863
2132
|
|
|
1864
2133
|
/**
|
|
@@ -1996,7 +2265,7 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
|
|
|
1996
2265
|
.catch(function (e) {
|
|
1997
2266
|
setEditBusy(false)
|
|
1998
2267
|
if (editKeyRef.current === b.bookKey) setEditErr('保存失败:' + e + ' (草稿还在,可再试一次)')
|
|
1999
|
-
else {
|
|
2268
|
+
else { toast('error', '「' + (b.label || b.bookKey) + '」保存失败:' + e); bump() }
|
|
2000
2269
|
})
|
|
2001
2270
|
}
|
|
2002
2271
|
const doRemove = function (b) {
|
|
@@ -2011,9 +2280,10 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
|
|
|
2011
2280
|
const doRefresh = function (keys) {
|
|
2012
2281
|
store.msg = '更新中(每本 1 请求,逐本 ' + fmtIntervalText() + ')…'; bump()
|
|
2013
2282
|
jpost('/bookmark/refresh', { bookKeys: keys }).then(function (r) {
|
|
2014
|
-
store.msg =
|
|
2283
|
+
store.msg = null
|
|
2284
|
+
toast('success', (r && r.note) || '已更新')
|
|
2015
2285
|
return store.refreshList()
|
|
2016
|
-
}).then(function () { bump() }).catch(function (e) { store.msg = '更新失败:' + e; bump() })
|
|
2286
|
+
}).then(function () { bump() }).catch(function (e) { store.msg = null; toast('error', '更新失败:' + e); bump() })
|
|
2017
2287
|
}
|
|
2018
2288
|
const scopeCount = function () {
|
|
2019
2289
|
if (scope === 'selected') return sel.length
|
|
@@ -2040,10 +2310,11 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
|
|
|
2040
2310
|
}
|
|
2041
2311
|
const addManual = function () {
|
|
2042
2312
|
jpost('/bookmark/add-manual', { input: String(manual || '').trim(), site: manualSite || undefined }).then(function (r) {
|
|
2043
|
-
store.msg =
|
|
2313
|
+
store.msg = null
|
|
2314
|
+
toast('success', (r && r.note) || '已添加')
|
|
2044
2315
|
setManual('')
|
|
2045
2316
|
return store.refreshList()
|
|
2046
|
-
}).then(function () { bump() }).catch(function (e) { store.msg = '添加失败:' + e; bump() })
|
|
2317
|
+
}).then(function () { bump() }).catch(function (e) { store.msg = null; toast('error', '添加失败:' + e); bump() })
|
|
2047
2318
|
}
|
|
2048
2319
|
const collectTitle = function (b, lab) {
|
|
2049
2320
|
const src = b.collectFrom === 'qidian-book-cache' ? '来自起点书页缓存(扫描后补全回填)'
|
|
@@ -2778,7 +3049,8 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
|
|
|
2778
3049
|
*/
|
|
2779
3050
|
const [scanActBusy, setScanActBusy] = React.useState(false)
|
|
2780
3051
|
const postInFlightRef = React.useRef(0)
|
|
2781
|
-
|
|
3052
|
+
/** 概览轮询失败会每 20s 来一次:同一条错误 60s 内只弹一次,别把 Toast 刷屏 */
|
|
3053
|
+
const errToastRef = React.useRef({ msg: '', at: 0 })
|
|
2782
3054
|
const [rect, setRect] = useRect()
|
|
2783
3055
|
|
|
2784
3056
|
/** 有未保存草稿时切页/收起先问一句(草稿留在 DRAFTS,回来还在) */
|
|
@@ -2796,8 +3068,15 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
|
|
|
2796
3068
|
if (reloadBusyRef.current) return Promise.resolve()
|
|
2797
3069
|
reloadBusyRef.current = true
|
|
2798
3070
|
return readOverview()
|
|
2799
|
-
.then(setOv)
|
|
2800
|
-
.catch(function (e) {
|
|
3071
|
+
.then(function (data) { setOv(data); errToastRef.current = { msg: '', at: 0 } })
|
|
3072
|
+
.catch(function (e) {
|
|
3073
|
+
const s = String(e)
|
|
3074
|
+
const now = Date.now()
|
|
3075
|
+
if (errToastRef.current.msg !== s || now - errToastRef.current.at > 60000) {
|
|
3076
|
+
errToastRef.current = { msg: s, at: now }
|
|
3077
|
+
toast('error', '读取概览失败:' + s)
|
|
3078
|
+
}
|
|
3079
|
+
})
|
|
2801
3080
|
.then(function () { reloadBusyRef.current = false })
|
|
2802
3081
|
}, [])
|
|
2803
3082
|
React.useEffect(function () { reload() }, [reload])
|
|
@@ -2853,8 +3132,11 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
|
|
|
2853
3132
|
if (scanAct) setScanActBusy(true)
|
|
2854
3133
|
else setBusy(true)
|
|
2855
3134
|
postInFlightRef.current += 1
|
|
2856
|
-
jpost(path, body).then(function (r) {
|
|
2857
|
-
|
|
3135
|
+
jpost(path, body).then(function (r) {
|
|
3136
|
+
toast('success', r && r.note ? r.note : '完成:' + (r.outcome || 'ok'))
|
|
3137
|
+
return reload()
|
|
3138
|
+
})
|
|
3139
|
+
.catch(function (e) { toast('error', String(e)) })
|
|
2858
3140
|
.then(function () {
|
|
2859
3141
|
postInFlightRef.current -= 1
|
|
2860
3142
|
if (!scanAct) return setBusy(false)
|
|
@@ -2891,7 +3173,6 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
|
|
|
2891
3173
|
h('button', { style: C.tab(tab === 'board'), onClick: function () { switchTab('board') } }, '榜单'),
|
|
2892
3174
|
h('button', { style: C.tab(tab === 'bm'), onClick: function () { switchTab('bm') } }, '书签'),
|
|
2893
3175
|
h('button', { style: C.tab(tab === 'pick'), onClick: function () { switchTab('pick') } }, '设置')),
|
|
2894
|
-
msg ? h('div', { style: C.muted }, msg) : null,
|
|
2895
3176
|
leaveAsk ? h(Banner, { tone: 'warn' },
|
|
2896
3177
|
h('span', null, '有未保存的改动(' + (leaveAsk.keys || []).map(function (k) { return LEAVE_LABEL[k] || k }).join('、') + ')'),
|
|
2897
3178
|
h('span', { style: C.muted }, '草稿会保留,下次进来还在'),
|
|
@@ -2908,6 +3189,7 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
|
|
|
2908
3189
|
: tab === 'board' ? h(BoardTab, { ov: ov, openLink: props.openLink, narrow: narrow, width: rect.w, rev: rev })
|
|
2909
3190
|
: tab === 'bm' ? h(BookmarksTab, { openLink: props.openLink })
|
|
2910
3191
|
: h(SettingsTab, { ov: ov, onSaved: reload }))),
|
|
3192
|
+
h(ToastHost, null),
|
|
2911
3193
|
h(ResizeHandle, { rect: rect, setRect: setRect }))
|
|
2912
3194
|
}
|
|
2913
3195
|
|
|
@@ -3027,7 +3309,8 @@ const LS_OPEN = 'rank-scan-panel:open:v1'
|
|
|
3027
3309
|
return { name: 'dsh-rank-scan', inject: inject, apply: apply, __test: {
|
|
3028
3310
|
metricChipText: metricChipText,
|
|
3029
3311
|
helpers: { revOf: revOf, statusText: statusText, scanLabel: scanLabel, pollDelay: pollDelay, canDayQuery: canDayQuery, fitColumns: fitColumns, colPrio: colPrio, mdOf: mdOf, boardLabel: boardLabel, rememberBoardNames: rememberBoardNames },
|
|
3030
|
-
components: { Overview: Overview, BoardTab: BoardTab, BookmarksTab: BookmarksTab, SettingsTab: SettingsTab, PopMenu: PopMenu, Panel: Panel },
|
|
3312
|
+
components: { Overview: Overview, BoardTab: BoardTab, BookmarksTab: BookmarksTab, SettingsTab: SettingsTab, PopMenu: PopMenu, Panel: Panel, ToastHost: ToastHost },
|
|
3313
|
+
toast: toast, toastStore: toastStore, lastNote: lastNote, settingsDiff: settingsDiff,
|
|
3031
3314
|
} }
|
|
3032
3315
|
},
|
|
3033
3316
|
})
|