jukebox
All repositories: gitoria
1.5 KB
// lib/api-helpers.hl — the plumbing of the function routes (lib/api.hl): JSON answers, query numbers.import { Response } from 'hl:http1'import { coverFile, thumbFile } from './covers.hl'import { leadingInt } from './util.hl'static jsonHeaders = { 'Content-Type' = 'application/json; charset=utf-8' 'X-Content-Type-Options' = 'nosniff' 'Cache-Control' = 'no-store' }static reply = (status, value) => {return new Response(JSON.stringify(value), { status = status headers = jsonHeaders })}static fail = (status, message) => { return reply(status, { error = message }) }// a query value as a non-negative whole Number, or null (missing or not a number)static queryNumber = (req, name) => {v = req.query == null ? null : req.query[name]if (v == null || hlTypeName(v) != 'String') { return null }return leadingInt(v)}static queryText = (req, name) => {v = req.query == null ? null : req.query[name]return v == null || hlTypeName(v) != 'String' || v == '' ? null : v}// Covers and thumbnails share validation, headers and the missing-cover response.static pictureReply = (Hybrid route, Hybrid req, Boolean thumbnail) => {if (req.method != 'GET') { return fail(405, 'GET only') }id = route.params.idif (id == null || id.length > 64) { return fail(404, 'no such cover') }c = thumbnail ? thumbFile(id) : coverFile(id)if (c == null) { return fail(404, 'no such cover') }return new Response(c.bytes, { status = 200 headers = { 'Content-Type' = c.mime 'Cache-Control' = 'public, max-age=31536000, immutable' 'X-Content-Type-Options' = 'nosniff' } })}
Branches
Latest commits
- d7b5e780|||PR Records 2026-11-24 (2): live day72, PR #19 merge, #10 newsmre
- 43b564dbMerge branch 'records-1124b' into mainJukebox
- 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