gitoria

tickets

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit7c8e6d837c8e6d83Limit edited state note fix to Markdown renderingmre7c8e6d83/lib/subscriptions-api.hl

2.0 KB

  1. // Thin token-only wrappers; cookies, project keys and ident access keys do not own subscriptions.
  2. import { Response } from 'hl:http1'
  3. import { userOfBearer } from './users.hl'
  4. import { jsonErrorAt } from './jsoncheck.hl'
  5. import { hdr, fail, unauthorizedFor, wantsMarkdown } from './api-helpers.hl'
  6. import { subscriptionsFor, createSubscription, removeSubscription, subscriptionDelta } from './subscriptions.hl'
  7. static answer = (status, data, markdown) => {
  8. 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' }) })
  9. }
  10. static result = (r, status) => { return answer(r.error != null ? (r.forbidden == true ? 403 : (r.status != null ? r.status : 400)) : status, r, false) }
  11. static subscriptionsApi = (route, req) => {
  12. if (req.method != 'GET' && req.method != 'POST') { return fail(405, 'GET or POST') }
  13. u = userOfBearer(req.headers['authorization'])
  14. if (u == null) { return unauthorizedFor('subscriptions') }
  15. if (req.method == 'GET') { return result(subscriptionsFor(u), 200) }
  16. if (req.body == null || req.body == '' || req.body.length > 32768 || jsonErrorAt(req.body) >= 0) { return fail(400, 'invalid JSON body (maximum 32768 characters)') }
  17. return result(createSubscription(u, JSON.parse(req.body)), 201)
  18. }
  19. static deltaApi = (route, req) => {
  20. if (req.method != 'GET') { return fail(405, 'GET only') }
  21. u = userOfBearer(req.headers['authorization'])
  22. if (u == null) { return unauthorizedFor('subscriptions') }
  23. md = wantsMarkdown(req)
  24. q = req.query != null ? req.query : {}
  25. r = subscriptionDelta(route.params.id, u, q.peek == '1', md)
  26. if (r.error != null) { return result(r, 200) }
  27. return answer(200, md ? r.text : r.data, md)
  28. }
  29. static removeSubscriptionApi = (route, req) => {
  30. if (req.method != 'POST') { return fail(405, 'POST only') }
  31. u = userOfBearer(req.headers['authorization'])
  32. if (u == null) { return unauthorizedFor('subscriptions') }
  33. return result(removeSubscription(route.params.id, u), 200)
  34. }

Branches

Latest commits

  • 7c8e6d83Limit edited state note fix to Markdown renderingmre
  • 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
  • e843ff7cOne-time purge of miserit-anthar#94 (#94, identity rule): idempotent step in lib/migrate.hl, fixture gate tests/purge94.mjsmre
  • 506a4efdmission 028: #94, identity rulemre
  • 78c7f48eRefine mpackdb holdmre