report-secret-accumulation.js 790 B

1234567891011121314151617
  1. /**
  2. * report-secret-accumulation → 未揭晓信息差 + 蓄积章数(按蓄积降序)
  3. * 蓄积章数 = 当前最大章号 − 登记章(派生值不物化,查询时算)。
  4. * 契约:纯返回 {ok, output?, error?}(见 design §6.2)。
  5. */
  6. export async function run(args, options, ctx) {
  7. const rows = await ctx.cache.query(
  8. 'SELECT id, short_title, registered_chapter FROM secrets WHERE reader_knows = 0'
  9. )
  10. const maxRows = await ctx.cache.query('SELECT MAX(chapter_num) AS m FROM chapters')
  11. const max = maxRows[0]?.m || 0
  12. const out = rows
  13. .map((s) => ({ id: s.id, short_title: s.short_title, 蓄积章数: max - s.registered_chapter }))
  14. .sort((a, b) => b.蓄积章数 - a.蓄积章数)
  15. return { ok: true, output: JSON.stringify(out, null, 2) }
  16. }