list-chapters.js 794 B

123456789101112131415161718192021
  1. /**
  2. * list-chapters --章定位=<推进|过渡|日常> [--卷=N] → JSON 数组(章号、标题)
  3. * 契约:纯返回 {ok, output?, error?}(见 design §6.2)。
  4. */
  5. export async function run(args, options, ctx) {
  6. const position = options['章定位']
  7. if (!position) {
  8. return { ok: false, error: '请用 --章定位=<推进|过渡|日常> 指定筛选' }
  9. }
  10. let sql = 'SELECT chapter_num, title, volume_num FROM chapters WHERE chapter_position = ?'
  11. const params = [position]
  12. if (options['卷'] !== undefined && options['卷'] !== true) {
  13. sql += ' AND volume_num = ?'
  14. params.push(parseInt(options['卷'], 10))
  15. }
  16. sql += ' ORDER BY chapter_num'
  17. const rows = await ctx.cache.query(sql, params)
  18. return { ok: true, output: JSON.stringify(rows, null, 2) }
  19. }