app: announcements, devotionals and events' backend (APP-1.0-PLAN §5-§7)
Announcements: public or members-only, pinned, a campus, a publish time and an end, an optional button, markdown text; Content admins write them; the heartbeat counts the last 30 days; "also send it" flags kept for §8. Devotionals: Cross Code's from the Hub each night and on Sync now (the next 2 weeks from today in the church's timezone, with the licence; exactly those days replaced, the rest kept, a Hub outage changes nothing), or the church's own by its Devotional writers, by hand or the same CSV import as the Hub's (preview, then replace or skip days already filled). Only KJV and BSB; the passage with its copyright line and Read in YouVersion; today's or the most recent; the archive by month; members-only ones; the acknowledgements. Events: simple events in the church's timezone, and the feed both ways as the Website's (publish its own as crosscode.event/1 with removals; read-only copies of Cross Events' and the Website's, Register on the Events site, canonical to the origin). Jobs event-feed (15 min) and crosscode-devotionals (01:15). Migration 20261204000000_content (checked on PostgreSQL 18: applies, no diff). 93 backend tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -5,15 +5,19 @@
|
||||
* POST /links/v1/connect, /disconnect a sibling connects or disconnects
|
||||
* POST /church/v1/changed Accounts: the church profile changed (signed)
|
||||
*
|
||||
* To come with their modules: the event feed (`/feed/v1/events`, `/feed/v1/changed`, §7) and
|
||||
* Accounts' "the messaging settings changed" (§8).
|
||||
* GET /feed/v1/events?updatedSince= the App's events (crosscode.event-feed/1), public
|
||||
* POST /feed/v1/changed a sibling's events changed: fetch them now (signed)
|
||||
*
|
||||
* To come: Accounts' "the messaging settings changed" (§8).
|
||||
*/
|
||||
import express from 'express';
|
||||
import { CHURCH_PATHS, churchChangedSchema, LINK_PATHS } from '@crosscode/contracts';
|
||||
import { CHURCH_PATHS, churchChangedSchema, eventChangedSchema, FEED_PATHS, LINK_PATHS } from '@crosscode/contracts';
|
||||
import { LINK_HEADERS, verify } from '@crosscode/contracts/signing';
|
||||
import type { Ctx } from '../context.js';
|
||||
import { churchChanged } from '../church/profile.js';
|
||||
import { acceptConnect, acceptDisconnect, LinkError } from './connect.js';
|
||||
import { buildFeed, publishOn, syncLink } from '../events/feed.js';
|
||||
import { enabledModules } from '../modules.js';
|
||||
|
||||
export function linksRouter(ctx: Ctx) {
|
||||
const r = express.Router();
|
||||
@@ -66,6 +70,33 @@ export function linksRouter(ctx: Ctx) {
|
||||
|
||||
const raw = express.raw({ type: () => true, limit: '16kb' });
|
||||
|
||||
r.get(FEED_PATHS.events.replace(/^\/api/, ''), async (req, res) => {
|
||||
try {
|
||||
if (!(await enabledModules(ctx)).includes('events') || !(await publishOn(ctx))) return say(res, 404, 'FEED_OFF', 'The App doesn\'t publish its events.');
|
||||
if (!(await ctx.settings.get('hub_install_id'))) return say(res, 503, 'FEED_UNAVAILABLE', 'The App isn\'t connected to the Hub yet, so it has no feed.');
|
||||
const rawSince = typeof req.query.updatedSince === 'string' ? req.query.updatedSince : null;
|
||||
const since = rawSince ? new Date(rawSince) : null;
|
||||
if (rawSince && (!since || !Number.isFinite(since.getTime()))) return say(res, 400, 'INVALID_REQUEST', 'updatedSince must be an ISO 8601 date and time.');
|
||||
res.set('Cache-Control', 'no-store');
|
||||
return res.json(await buildFeed(ctx, since));
|
||||
} catch (e) {
|
||||
return fail(res, e);
|
||||
}
|
||||
});
|
||||
|
||||
r.post(FEED_PATHS.changed.replace(/^\/api/, ''), raw, async (req, res) => {
|
||||
try {
|
||||
const got = await signedBy(req, res);
|
||||
if (!got) return undefined;
|
||||
if (!eventChangedSchema.safeParse(got.body).success) return say(res, 400, 'INVALID_REQUEST', 'That isn\'t an event.changed message.');
|
||||
// Fetched after answering: the sibling doesn't wait for it.
|
||||
if (got.link.showEvents) setImmediate(() => { syncLink(ctx, got.link).catch(() => {}); });
|
||||
return res.status(202).json({ accepted: true, fetching: got.link.showEvents });
|
||||
} catch (e) {
|
||||
return fail(res, e);
|
||||
}
|
||||
});
|
||||
|
||||
r.post(CHURCH_PATHS.changed.replace(/^\/api/, ''), raw, async (req, res) => {
|
||||
try {
|
||||
const got = await signedBy(req, res, true);
|
||||
|
||||
Reference in New Issue
Block a user