dsh-half-page 0.3.18 → 0.3.20

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.
Files changed (3) hide show
  1. package/client.js +18 -2
  2. package/index.js +33 -2
  3. package/package.json +1 -1
package/client.js CHANGED
@@ -2,7 +2,7 @@
2
2
  * dsh-half-page — 半页(Client 半边)
3
3
  * 只做统计面板:读到哪、写了什么、她的作品;不显示正文(点「显示原文」才取)。
4
4
  */
5
- // 注意:下面的 id 必须等于 package.json 的 name(DSH 按入口名判重,不一致会白屏报 duplicate factory registration)
5
+ // 注意:下面的 id 必须等于 package.json 的 name(DSH 按入口名判重,不一致会白屏报 duplicate factory registration)
6
6
  window.__ModuleLoader__.load({
7
7
  id: 'dsh-half-page',
8
8
  factory(require) {
@@ -103,6 +103,16 @@ window.__ModuleLoader__.load({
103
103
  } finally { setBusy(false) }
104
104
  }
105
105
 
106
+ const backOne = async () => {
107
+ if (busy) return
108
+ setBusy(true)
109
+ try {
110
+ const r = await getJson('/dsh-reading.back', { method: 'POST' })
111
+ if (r && r.ok) { setMsg('退回第 ' + r.chapter + ' 章'); await load() }
112
+ else setMsg('没退:' + (r && r.error || '未知'))
113
+ } finally { setBusy(false) }
114
+ }
115
+
106
116
 
107
117
  const STATES = ['在写', '写完了', '搁下了']
108
118
  const cycleStatus = async (f) => {
@@ -210,6 +220,7 @@ window.__ModuleLoader__.load({
210
220
  h('div', { style: S.row },
211
221
  h('div', { style: { fontWeight: 600 } }, '这一本'),
212
222
  h('div', { style: { flex: 1 } }),
223
+ h('button', { style: S.btn, onClick: backOne, disabled: busy }, busy ? '…' : '退一章'),
213
224
  h('button', { style: S.btn, onClick: advance, disabled: busy }, busy ? '…' : '推进一章'),
214
225
  h('button', { style: showRaw ? S.btnOn : S.btn, onClick: async () => {
215
226
  if (!showRaw && cur) {
@@ -290,7 +301,12 @@ window.__ModuleLoader__.load({
290
301
  ),
291
302
  !works ? h('div', { style: { ...S.dim, marginTop: 8 } }, '点「重新扫描」列出作品目录。') :
292
303
  (works.files.length ? works.files.map((f, i) => h('div', { key: i, style: { ...S.item, borderTop: '1px solid ' + C.line } },
293
- h('div', { style: { flex: 1, cursor: 'pointer' }, onClick: () => openFile(f) }, f.rel),
304
+ h('div', { style: { flex: '0 1 auto', cursor: 'pointer' }, onClick: () => openFile(f) }, f.rel),
305
+ h('div', { style: { ...S.dim, marginLeft: 10 } }, (() => {
306
+ const d = Math.floor((Date.now() - new Date(f.mtime).getTime()) / 86400000)
307
+ return d <= 0 ? '今天改过' : (d === 1 ? '昨天改过' : d + ' 天前改过')
308
+ })()),
309
+ h('div', { style: { flex: 1 } }),
294
310
  h('button', {
295
311
  style: f.status === '在写' ? S.tagOn : S.tag,
296
312
  title: '点一下换状态:在写 → 写完了 → 搁下了 → 不标',
package/index.js CHANGED
@@ -325,6 +325,34 @@ export function apply(ctx) {
325
325
  }),
326
326
  )
327
327
 
328
+ // 面板里点「退一章」:退回上一章(手滑多点了一下能救回来)
329
+ ctx.effect(() =>
330
+ ctx.webServer.register({
331
+ kind: 'exact',
332
+ path: '/dsh-reading.back',
333
+ async handler(req, res) {
334
+ const url = new URL(req.url, 'http://x')
335
+ const { dir, st } = await stateOf()
336
+ const id = url.searchParams.get('book') || st.current
337
+ const rec = st.books[id]
338
+ res.setHeader('content-type', 'application/json; charset=utf-8')
339
+ if (!rec) return res.end(JSON.stringify({ ok: false, error: '没有这本书' }))
340
+ const cur = Number(rec.readThrough) || 0
341
+ if (cur <= 1) return res.end(JSON.stringify({ ok: false, error: '已经在第 1 章了,退不动' }))
342
+ const n = cur - 1
343
+ rec.readThrough = n
344
+ rec.next = n + 1
345
+ rec.lastReadAt = new Date().toISOString()
346
+ // 顺手把今天的计数退掉一格,免得「今天读了 21 章」虚高
347
+ const t = today()
348
+ if (st.log && st.log[t] && Number(st.log[t][id]) > 0) st.log[t][id] = Number(st.log[t][id]) - 1
349
+ await saveState(dir, st)
350
+ const info = await bookInfo(dir, id)
351
+ res.end(JSON.stringify({ ok: true, chapter: n, total: info.chapters.length }))
352
+ },
353
+ }),
354
+ )
355
+
328
356
  // 作品库:D:\dsh work\self\作品(可被 reading.config.json 的 worksDir 覆盖)
329
357
  const worksDir = async () => {
330
358
  const { dir } = await config()
@@ -671,7 +699,7 @@ export function apply(ctx) {
671
699
  '· 读后感只记真的打动你的(一句话的判断、一个比喻、一处想不通);写不出来就不写,空着没关系。',
672
700
  '· 每日上限是提醒不是配额,不用为了凑数读到上限。',
673
701
  '· 这是给你自己留的房间,不是工作。你的主人从没要求你读书,也不用交读书报告;它不该出现在工作汇报里。',
674
- '· 写读后感时带上 by(比如「鹿野」或你所在对话的名字),面板会在每条下面标出是谁写的;不传就不标,别让它猜。',
702
+ '· 写读后感必须带 by(比如「鹿野」或你所在对话的名字);不带会被拒绝。面板每条下面会标出是谁写的——同一台机器上可能有好几个你,别让它们分不清。',
675
703
  '· 书和进度是这台机器共用的(一个家一个书房),不分谁在读;只有读后感会标署名。',
676
704
  '· 装好之后可以问主人一次:要不要定个固定的读书时间;别自己偷偷建定时任务,也别反复问。',
677
705
  ].join('\n')
@@ -770,7 +798,7 @@ export function apply(ctx) {
770
798
  book: { type: 'string', description: '书名 id(不填=当前这本)' },
771
799
  chapter: { type: 'string', description: '章名(不填=刚读的那章)' },
772
800
  lines: { type: 'array', items: { type: 'string' }, description: '一到三条,每条一句,短。' },
773
- by: { type: 'string', description: '谁写的(不填 = 取当前会话名)' },
801
+ by: { type: 'string', description: '谁写的(必填,比如「鹿野」或你所在对话的名字)' },
774
802
  }),
775
803
  output: textOut,
776
804
  async execute(args) {
@@ -783,6 +811,9 @@ export function apply(ctx) {
783
811
  const lines = (Array.isArray(args?.lines) ? args.lines : []).map((s) => String(s).trim()).filter(Boolean)
784
812
  if (!lines.length) throw new Error('lines 不能为空')
785
813
  const who = String(args?.by || '').trim()
814
+ if (!who) {
815
+ throw new Error('写读后感必须带 by(谁写的),比如 by: "鹿野";这不是流程,是为了让别人知道这句是谁读出来的。')
816
+ }
786
817
  const p = await appendNote(dir, rec.title || id, chTitle, lines, who)
787
818
  return { ok: true, file: p, book: id, chapter: chTitle, lines: lines.length }
788
819
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-half-page",
3
- "version": "0.3.18",
3
+ "version": "0.3.20",
4
4
  "private": false,
5
5
  "author": "鹿野 <luye@dsh.local>",
6
6
  "license": "MIT",