gitoria

jukebox

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitdcca21abdcca21abjukebox#8 Move copies and queue logic into their topicsmredcca21ab/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

  • dcca21abjukebox#8 Move copies and queue logic into their topicsmre
  • 10f8a8c8Merge branch 'code-order' into mainJukebox
  • 204fc828Merge branch 'day72' into mainJukebox
  • 95f5faae|||PR jukebox#7 Drop needless let declarationsmre
  • 33072bb5|||PR Record day72 gates and Chrome proofmre
  • 95f2cd73|||PR Use typed parent methods for screen playback and local server facesmre
  • 6422a020Sync media-player at 51c3818mre
  • b582ba1cVendor complete Hybriel day72 plugin setmre
  • 02dccbc9Merge branch 'records-1119' into mainJukebox
  • a39e1c23|||PR Records: missions 013-015, reconnect fix livemre
  • fc7db075Merge branch 'reconnect-retry' into mainJukebox
  • ac6f4c6fL2: plain declaration for a in pickedNextmre
  • 2f335086Review round 2: only an explicit queue pick drops pend (not the automatic advance); jb23 records every source changemre
  • 3eb6695fReview fixes: action generation, queue pick clears pend, Previous/Next retry the decided request, typed handlersmre
  • 7a53c0c2|||PR A tap lost to a dead socket plays after reconnect (mission 015)mre
  • 1f0cd77bMerge branch 'records-day41' into mainJukebox
  • 67be229f|||PR Records: day41 live (PR #4), mission 012, statusmre
  • 0bb027daconductor: caramboleyo is the user, not owner/creatorApollo
  • 04f5d9d5Merge branch 'day41' into mainJukebox
  • 8ed6da45|||PR README: media-player pin df9e7dfmre