source: Klonkt/src/routes/circle.js@ 6e9a95b

main
Last change on this file since 6e9a95b was 0091cb7, checked in by roboburr <roboburr@…>, 3 months ago

Circles v1 — steps 4+5: Admin UI + /cirkel feed

  • Mode 'Circles' in Admin > Settings (radio + section).
  • Admin > Circle (admin-circle): add sources/list/status, per source Refresh (syncOne) + Delete (cleans up orphaned cache), and a visibility toggle (sites.allow_circle, opt-out for surfacing).
  • /cirkel feed: cached remote_posts as static cards (source/avatar, title, summary, cover, link to source). Only when tenancy=circle.
  • allow_circle column (ensureColumn) + CircleFederation respects it.
  • Output escaped everywhere + URL-scheme guards (http/https) against XSS import.

v1 functionally complete (publish + pull + UI + feed). Remaining: hardening/review.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@…>

  • Property mode set to 100644
File size: 1.7 KB
Line 
1/**
2 * Publieke Cirkel-feed: /cirkel
3 * Toont de gecachte publieke posts uit je cirkel als statische kaarten.
4 * Alleen actief als tenancy === 'circle' (anders next() -> postsRoutes/404).
5 * Zie docs/cirkels-v1-spec.md §5c.
6 */
7
8import express from 'express';
9import { renderPage } from '../middleware/render.js';
10import db from '../config/database.js';
11import { getTenancy } from '../services/SettingsService.js';
12
13const router = express.Router();
14
15function safeUrl(u) {
16 return typeof u === 'string' && /^https?:\/\//i.test(u) ? u : null;
17}
18function safeJson(s) {
19 try { return s ? JSON.parse(s) : []; } catch { return []; }
20}
21
22router.get('/cirkel', (req, res, next) => {
23 if (getTenancy() !== 'circle') return next();
24
25 const rows = db.prepare(`
26 SELECT p.id, p.published, p.title, p.summary, p.url, p.media_json,
27 a.name AS actor_name, a.url AS actor_url, a.avatar AS actor_avatar
28 FROM remote_posts p
29 JOIN remote_actors a ON a.id = p.actor_id
30 ORDER BY COALESCE(p.published, p.fetched_at) DESC
31 LIMIT 100
32 `).all();
33
34 const posts = rows.map((r) => {
35 const media = safeJson(r.media_json)
36 .map((m) => ({ ...m, url: safeUrl(m.url) }))
37 .filter((m) => m.url);
38 const image = media.find((m) => m.type === 'image') || null;
39 return {
40 id: r.id,
41 title: r.title || '(zonder titel)',
42 summary: r.summary || '',
43 url: safeUrl(r.url),
44 published: r.published,
45 actorName: r.actor_name || 'Onbekend',
46 actorUrl: safeUrl(r.actor_url),
47 actorAvatar: safeUrl(r.actor_avatar),
48 image: image ? image.url : null,
49 };
50 });
51
52 renderPage(req, res, 'pages/circle-feed', { pageTitle: 'Cirkel', posts });
53});
54
55export default router;
Note: See TracBrowser for help on using the repository browser.