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
- cd3641a1|||PR records: day72 deploy live, tickets closedmre
- 7d44d852Merge branch 'records-t37' into mainTickets
- 926f7061|||PR records: merges, D36 deploymre
- bf58534eMerge branch 'l33-final' into mainTickets
- 759a9ac3|||PR thin login (tickets#46, #45): merge main, route entry cleanupmre
- 239436d8Merge remote-tracking branch 'origin/main' into l33-finalmre
- 5822cb3aMerge branch 'o34-clean' into mainTickets
- 0870653c|||PR offline note from __hlOnline, no polling (tickets#41)mre
- 14cf96b4Merge branch 'records-t36' into mainTickets
- 07749fa1|||PR records: day72 + #40 mergedmre
- 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