gitoria

tickets

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Branchl33-thinecd7e226|||PR Consolidate login and move handler logic into topic libraries (partial)mrel33-thin/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

  • ecd7e226|||PR Consolidate login and move handler logic into topic libraries (partial)mre
  • 6dea1c60Merge branch 'r35-day72' into mainTickets
  • 7bcfdc22|||PR drop worker edits to conductor recordsmre
  • 2617b6ee|||PR dialogs: host flag cleared on close, dialog gate (tickets#40)mre
  • 6e701371|||PR record partial day72 dialog validationmre
  • b9fb9a91|||PR bind ticket dialog visibility to member flagsmre
  • 0788e65f|||PR re-vendor Hybriel day72mre
  • e2a6bdcfMerge branch 'records-t35' into mainTickets
  • d8d54df1|||PR records: R35 day72 + #40mre
  • 8a7f475aMerge branch 'records-t33' into mainTickets
  • e685d0c2|||PR records: PROCEDURES merge callmre
  • b42aff2b|||PR records: GO 2026-11-23, workers L33 O34, PROCEDURES.mdmre
  • ed091d44Merge branch 'records' into mainTickets
  • 180c0cdb|||PR records: ticket move live (M32), hybriel#439mre
  • 497cae7bMerge branch 'm32-move' into mainTickets
  • 772e0696|||PR Allow project admins to move tickets between their projectsmre
  • be92a560Merge branch 'records' into mainTickets
  • 0daf2ea8|||PR records: PR-only workflow, #50 donemre
  • 0185d0b6Log PR 1 deploymre
  • f5bf16e2Mission 031: deploy PR 1mre