gitoria

jukebox

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitfa86b08cfa86b08c|||PR Records 2026-11-24: LOG, STATUS, missions 020-023mrefa86b08c/lib/api-helpers.hl

1.5 KB

  1. // lib/api-helpers.hl — the plumbing of the function routes (lib/api.hl): JSON answers, query numbers.
  2. import { Response } from 'hl:http1'
  3. import { coverFile, thumbFile } from './covers.hl'
  4. import { leadingInt } from './util.hl'
  5. static jsonHeaders = { 'Content-Type' = 'application/json; charset=utf-8' 'X-Content-Type-Options' = 'nosniff' 'Cache-Control' = 'no-store' }
  6. static reply = (status, value) => {
  7. return new Response(JSON.stringify(value), { status = status headers = jsonHeaders })
  8. }
  9. static fail = (status, message) => { return reply(status, { error = message }) }
  10. // a query value as a non-negative whole Number, or null (missing or not a number)
  11. static queryNumber = (req, name) => {
  12. v = req.query == null ? null : req.query[name]
  13. if (v == null || hlTypeName(v) != 'String') { return null }
  14. return leadingInt(v)
  15. }
  16. static queryText = (req, name) => {
  17. v = req.query == null ? null : req.query[name]
  18. return v == null || hlTypeName(v) != 'String' || v == '' ? null : v
  19. }
  20. // Covers and thumbnails share validation, headers and the missing-cover response.
  21. static pictureReply = (Hybrid route, Hybrid req, Boolean thumbnail) => {
  22. if (req.method != 'GET') { return fail(405, 'GET only') }
  23. id = route.params.id
  24. if (id == null || id.length > 64) { return fail(404, 'no such cover') }
  25. c = thumbnail ? thumbFile(id) : coverFile(id)
  26. if (c == null) { return fail(404, 'no such cover') }
  27. return new Response(c.bytes, { status = 200 headers = { 'Content-Type' = c.mime 'Cache-Control' = 'public, max-age=31536000, immutable' 'X-Content-Type-Options' = 'nosniff' } })
  28. }

Branches

Latest commits

  • fa86b08c|||PR Records 2026-11-24: LOG, STATUS, missions 020-023mre
  • 0a2ae3daMerge remote-tracking branch 'origin/records-1123' into records-1124mre
  • 9a48cfcaMerge branch 'vendor-theme' into mainJukebox
  • 170d3735Merge branch 'code-order-2' into mainJukebox
  • 3f1918a7|||PR Re-sync layouts theme 4099e64 with Segoe UI firstmre
  • 2e7f6a43Vendor virtual-list 489afcf from components.hybrielmre
  • 0ba85799Merge branch 'reset-classes' into mainJukebox
  • 502eeed5jukebox#20: vendor virtual-list initial resetKey baseline fixmre
  • 6d5ce287|||PR jukebox#9 Centralize songs table reads and writes in db.hlmre
  • dcca21abjukebox#8 Move copies and queue logic into their topicsmre
  • 3b76651cjukebox#20: update virtual-list README pin and resetKey optionsmre
  • bc09e1e8|||PR jukebox#20: reset virtual lists through resetKey (partial validation)mre
  • a3796dc5Records: live step waits for idlemre
  • 3b158e16Records: merges of #9 and #11mre
  • 27204167Merge main into records-1123mre
  • 10f8a8c8Merge branch 'code-order' into mainJukebox
  • 204fc828Merge branch 'day72' into mainJukebox
  • 8e8d0e2b|||PR Records: PROCEDURES.md, missions 016-019, GO 2026-11-23mre
  • 95f5faae|||PR jukebox#7 Drop needless let declarationsmre
  • 33072bb5|||PR Record day72 gates and Chrome proofmre