tickets
All repositories: gitoria
2.0 KB
// Thin token-only wrappers; cookies, project keys and ident access keys do not own subscriptions.import { Response } from 'hl:http1'import { userOfBearer } from './users.hl'import { jsonErrorAt } from './jsoncheck.hl'import { hdr, fail, unauthorizedFor, wantsMarkdown } from './api-helpers.hl'import { subscriptionsFor, createSubscription, removeSubscription, subscriptionDelta } from './subscriptions.hl'static answer = (status, data, markdown) => {return new Response(markdown ? data : JSON.stringify(data), { status = status headers = hdr({ 'Content-Type' = markdown ? 'text/markdown; charset=utf-8' : 'application/json; charset=utf-8' 'Cache-Control' = 'no-store' 'Vary' = 'Accept' }) })}static result = (r, status) => { return answer(r.error != null ? (r.forbidden == true ? 403 : (r.status != null ? r.status : 400)) : status, r, false) }static subscriptionsApi = (route, req) => {if (req.method != 'GET' && req.method != 'POST') { return fail(405, 'GET or POST') }u = userOfBearer(req.headers['authorization'])if (u == null) { return unauthorizedFor('subscriptions') }if (req.method == 'GET') { return result(subscriptionsFor(u), 200) }if (req.body == null || req.body == '' || req.body.length > 32768 || jsonErrorAt(req.body) >= 0) { return fail(400, 'invalid JSON body (maximum 32768 characters)') }return result(createSubscription(u, JSON.parse(req.body)), 201)}static deltaApi = (route, req) => {if (req.method != 'GET') { return fail(405, 'GET only') }u = userOfBearer(req.headers['authorization'])if (u == null) { return unauthorizedFor('subscriptions') }md = wantsMarkdown(req)q = req.query != null ? req.query : {}r = subscriptionDelta(route.params.id, u, q.peek == '1', md)if (r.error != null) { return result(r, 200) }return answer(200, md ? r.text : r.data, md)}static removeSubscriptionApi = (route, req) => {if (req.method != 'POST') { return fail(405, 'POST only') }u = userOfBearer(req.headers['authorization'])if (u == null) { return unauthorizedFor('subscriptions') }return result(removeSubscription(route.params.id, u), 200)}
Branches
Latest commits
- 59c02e4dMerge e30: preserve edited state note labels in Markdownmre
- 30970796Log E30 deploy GOmre
- 7c8e6d83Limit edited state note fix to Markdown renderingmre
- 910536d0Log E30 reviewmre
- 36984386Preserve state transitions when their notes are editedmre
- d75cb946Log E30 startmre
- 0bf3fefaMission 030: edited state note labelmre
- 691565c6Log neutral-ticket rule checkmre
- bc3bdecerecords: day38b live, #94 purgedmre
- f6c5aa0dMerge main (records)mre
- e23d42acconnect gate: wait for hydration before clicking Disconnectmre
- a5d45d00records: D38 cause, GOmre
- 19eeb938records: D38 gates, two day38b failuresmre
- f8e42a85Re-vendor tickets to Hybriel set day38b (1e554d7)mre
- 51645016Merge purge-94 (#94, identity rule)mre
- 94d6ca2arecords: D38 startedmre
- 9df09aacmission 029: day38b re-vendor + deploymre
- d2834f65records: #94 backup planmre
- 4467d8cbrecords: #94 purge readymre
- aa2d124eREADME: the #94 purge gatemre