Changeset 8ef8c3e in Klonkt


Ignore:
Timestamp:
06/26/2026 09:20:12 AM (2 months ago)
Author:
Robin Genis <roboburr@…>
Branches:
main
Children:
429d3b0
Parents:
46f3dd6
Message:

feat(cirkel): remove the old Cirkels pull-protocol; Cirkels is now AP-only

Phase 4 of the Cirkels-on-AP rework. Removes the legacy custom-Ed25519 pull
protocol and everything around it: /.klonkt/* (federation.js), CircleService +
CircleFederation, the 15-min sync loop, the /admin/circle UI, the remote_posts
union in /cirkel and the /cirkel/:id local-reading page. Tenancy is retired
(getTenancy always 'solo'); the Solo|Circle mode picker is gone. /cirkel is now
purely the auto-boosted (featured) feed. The circle_links/remote_* tables are
kept as dead data. A scripts/migrate-circles.mjs converts existing circle_links
to AP follows with auto-boost (run per instance).

Co-Authored-By: Claude <noreply@…>

Files:
1 added
6 deleted
8 edited

Legend:

Unmodified
Added
Removed
  • src/middleware/render.js

    r46f3dd6 r8ef8c3e  
    125125    // Cirkel = the artists you feature (auto-boost). Shown when AP is on and you
    126126    // auto-boost ≥1 account, or (legacy) on a circle-tenancy site.
    127     hasCirkel: !!(_site && ((apEnabled() && ActivityPubService.autoBoostCount(_site.slug) > 0) || (res.locals.tenancy || 'solo') === 'circle')),
     127    hasCirkel: !!(_site && apEnabled() && ActivityPubService.autoBoostCount(_site.slug) > 0),
    128128    isViewer: _isViewer,
    129129    canMutate: !_isViewer,
  • src/routes/changelog.js

    r46f3dd6 r8ef8c3e  
    33 *
    44 * GET /changelog  -> renders CHANGELOG.md (the source of truth for releases).
    5  *
    6  * The app version (footer, package.json) is intentionally decoupled from the
    7  * circle federation proto (KLONKT_PROTO): a version bump is cosmetic and does not
    8  * affect federation. We show the proto here explicitly so that each release
    9  * makes visible which federation version this instance speaks (circles = lockstep per proto).
    105 */
    116
     
    1611import { renderPage } from '../middleware/render.js';
    1712import { MarkdownService } from '../services/MarkdownService.js';
    18 import { KLONKT_PROTO } from '../services/CircleFederation.js';
    1913
    2014const router = express.Router();
     
    3327    bodyClass: 'on-changelog',
    3428    changelogHtml: html,
    35     proto: KLONKT_PROTO,
    3629  });
    3730});
  • src/routes/circle.js

    r46f3dd6 r8ef8c3e  
    11/**
    2  * Circle feed + local reading page.
    3  *   GET /cirkel        -> overview (same timeline/grid view as the home)
    4  *   GET /cirkel/:id    -> individual remote post in own chrome (stay on your site)
    5  * Only active when tenancy === 'circle' (otherwise next() -> postsRoutes/404).
    6  * See docs/cirkels-v1-spec.md §5c.
     2 * Circle feed — the artists this site features (auto-boosts), sourced from
     3 * ActivityPub. Cards link to the source post. Available whenever the site
     4 * auto-boosts at least one account; otherwise next() -> postsRoutes.
     5 *   GET /cirkel
    76 */
    87
    98import express from 'express';
    109import { renderPage } from '../middleware/render.js';
    11 import db from '../config/database.js';
    12 import { getTenancy, apEnabled } from '../services/SettingsService.js';
     10import { apEnabled } from '../services/SettingsService.js';
    1311import ActivityPubService from '../services/ActivityPubService.js';
    1412
    1513const router = express.Router();
    16 
    17 function htmlToText(html) {
    18   return String(html || '').replace(/<[^>]+>/g, ' ').replace(/&[a-z#0-9]+;/gi, ' ').replace(/\s+/g, ' ').trim();
    19 }
    2014
    2115function safeUrl(u) {
     
    2721function mediaImage(media_json) {
    2822  const media = safeJson(media_json).map((m) => ({ ...m, url: safeUrl(m.url) })).filter((m) => m.url);
    29   return media.find((m) => m.type === 'image') || null;
     23  return media.find((m) => /image/i.test(m.type || '')) || media[0] || null;
     24}
     25function htmlToText(html) {
     26  return String(html || '').replace(/<[^>]+>/g, ' ').replace(/&[a-z#0-9]+;/gi, ' ').replace(/\s+/g, ' ').trim();
    3027}
    3128
    32 // ── Overview ─────────────────────────────────────────────────
    33 // New model: the Cirkel = posts from the accounts this site auto-boosts
    34 // ("feature an artist"), sourced from ActivityPub. Cards link to the source
    35 // post (external_url). Legacy circle-tenancy remote_posts are merged in until
    36 // the old pull-protocol is removed (Phase 4).
    3729router.get('/cirkel', (req, res, next) => {
    3830  const site = res.locals.site;
    39   if (!site) return next();
    40   const slug = site.slug;
    41   const isCircle = getTenancy() === 'circle';
    42   const abCount = apEnabled() ? ActivityPubService.autoBoostCount(slug) : 0;
    43   if (!abCount && !isCircle) return next(); // no cirkel on this site
     31  if (!site || !apEnabled() || ActivityPubService.autoBoostCount(site.slug) === 0) return next();
    4432
    45   let posts = [];
     33  const posts = ActivityPubService.getCirkelPosts(site.slug, 80).map((r) => {
     34    const text = htmlToText(r.content);
     35    const image = mediaImage(r.media_json);
     36    const name = r.author_name || r.author_handle || 'Onbekend';
     37    return {
     38      id: 'ap-' + r.id,
     39      slug: '',
     40      title: text ? (text.length > 90 ? text.slice(0, 90) + '…' : text) : name,
     41      excerpt: '',
     42      cover_image_url: image ? image.url : null,
     43      published_at: r.published,
     44      created_at: r.published,
     45      type: 'post',
     46      tags: '',
     47      pinned: 0,
     48      status: 'published',
     49      source_name: name,
     50      external_url: safeUrl(r.url),
     51    };
     52  });
    4653
    47   // Featured (auto-boosted) fediverse posts → link to the original.
    48   if (abCount) {
    49     posts = ActivityPubService.getCirkelPosts(slug, 80).map((r) => {
    50       const text = htmlToText(r.content);
    51       const image = mediaImage(r.media_json);
    52       const name = r.author_name || r.author_handle || 'Onbekend';
    53       return {
    54         id: 'ap-' + r.id,
    55         slug: '',
    56         title: text ? (text.length > 90 ? text.slice(0, 90) + '…' : text) : name,
    57         excerpt: '',
    58         cover_image_url: image ? image.url : null,
    59         published_at: r.published,
    60         created_at: r.published,
    61         type: 'post',
    62         tags: '',
    63         pinned: 0,
    64         status: 'published',
    65         source_name: name,
    66         external_url: safeUrl(r.url),
    67       };
    68     });
    69   }
    70 
    71   // Legacy circle-tenancy remote_posts (local reading page, no external_url).
    72   if (isCircle) {
    73     const rows = db.prepare(`
    74       SELECT p.id, p.published, p.title, p.summary, p.media_json, p.tags, a.name AS actor_name
    75       FROM remote_posts p JOIN remote_actors a ON a.id = p.actor_id
    76       ORDER BY COALESCE(p.published, p.fetched_at) DESC LIMIT 100
    77     `).all().map((r) => {
    78       const image = mediaImage(r.media_json);
    79       return {
    80         id: r.id, slug: 'cirkel/' + encodeURIComponent(r.id),
    81         title: r.title || '(zonder titel)', excerpt: r.summary || '',
    82         cover_image_url: image ? image.url : null, published_at: r.published, created_at: r.published,
    83         type: 'post', tags: r.tags || '', pinned: 0, status: 'published', source_name: r.actor_name || 'Onbekend',
    84       };
    85     });
    86     posts = posts.concat(rows);
    87   }
    88 
    89   posts.sort((a, b) => String(b.published_at || '').localeCompare(String(a.published_at || '')));
    90 
    91   // Members header (avatars): featured artists + legacy circle links.
    92   let sites = abCount
    93     ? ActivityPubService.getCirkelMembers(slug).map((s) => ({ name: s.name || 'Onbekend', url: safeUrl(s.url), avatar: safeUrl(s.icon) }))
    94     : [];
    95   if (isCircle) {
    96     const old = db.prepare(`
    97       SELECT a.name, a.url, a.avatar FROM remote_actors a
    98       JOIN circle_links l ON l.remote_actor_id = a.id WHERE l.status = 'active' ORDER BY a.name
    99     `).all().map((s) => ({ name: s.name || 'Onbekend', url: safeUrl(s.url), avatar: safeUrl(s.avatar) }));
    100     sites = sites.concat(old);
    101   }
     54  const sites = ActivityPubService.getCirkelMembers(site.slug)
     55    .map((s) => ({ name: s.name || 'Onbekend', url: safeUrl(s.url), avatar: safeUrl(s.icon) }));
    10256
    10357  renderPage(req, res, 'pages/circle-feed', { pageTitle: 'Cirkel', bodyClass: 'on-cirkel', posts, sites });
    10458});
    10559
    106 // ── Individual remote post (local reading) ────────────────────
    107 router.get('/cirkel/:id', (req, res, next) => {
    108   if (getTenancy() !== 'circle') return next();
    109 
    110   const row = db.prepare(`
    111     SELECT p.id, p.published, p.title, p.summary, p.url, p.media_json, p.tags,
    112            a.name AS actor_name, a.url AS actor_url, a.avatar AS actor_avatar
    113     FROM remote_posts p
    114     JOIN remote_actors a ON a.id = p.actor_id
    115     WHERE p.id = ?
    116   `).get(req.params.id);
    117 
    118   if (!row) return next();
    119 
    120   const image = mediaImage(row.media_json);
    121   const post = {
    122     title: row.title || '(zonder titel)',
    123     body: row.summary || '',          // platte tekst (gesanitized bij ingest)
    124     published: row.published,
    125     image: image ? image.url : null,
    126     sourceName: row.actor_name || 'Onbekend',
    127     sourceUrl: safeUrl(row.actor_url),
    128     sourceAvatar: safeUrl(row.actor_avatar),
    129     originalUrl: safeUrl(row.url),
    130     tags: (row.tags || '').split(',').map((t) => t.trim()).filter(Boolean),
    131     sourceTagBase: safeUrl(row.actor_url) ? safeUrl(row.actor_url).replace(/\/+$/, '') : null,
    132   };
    133 
    134   renderPage(req, res, 'pages/circle-post', {
    135     pageTitle: post.title,
    136     bodyClass: 'on-cirkel-post',
    137     post,
    138   });
    139 });
    140 
    14160export default router;
  • src/server.js

    r46f3dd6 r8ef8c3e  
    4242import postsRoutes from './routes/posts.js';
    4343import langRoutes from './routes/lang.js';
    44 import federationRoutes from './routes/federation.js';
    45 import { startCircleSyncLoop } from './services/CircleService.js';
    46 import adminCircleRoutes from './routes/admin-circle.js';
    4744import adminUpdatesRoutes from './routes/admin-updates.js';
    4845import adminPatreonRoutes from './routes/admin-patreon.js';
     
    198195// Klonkt is PWA-only; assetlinks.json is no longer served.
    199196
    200 // Circles: periodic background sync of remote instances (no-op unless tenancy='circle').
    201 startCircleSyncLoop();
    202 
    203197// Bundle HTMX: copy from node_modules into our own assets dir so we can serve
    204198// it locally (no third-party CDN). Idempotent — only copies if size differs.
     
    217211  }
    218212})();
    219 
    220 // Circle federation: public, site-agnostic endpoints (/.klonkt/*).
    221 // Before resolveSite/theme — they don't need a site context.
    222 app.use(federationRoutes);
    223213
    224214// ActivityPub: WebFinger + /ap/* (site-agnostic, resolves the site by slug).
     
    304294app.use('/admin/settings', adminSettingsRoutes);
    305295app.use('/admin/seo', adminSeoRoutes);
    306 app.use('/admin/circle', adminCircleRoutes);
    307296app.use('/admin/updates', adminUpdatesRoutes);
    308297app.use('/admin/patreon', adminPatreonRoutes);
  • src/services/SettingsService.js

    r46f3dd6 r8ef8c3e  
    4040
    4141export function getTenancy() {
    42   const v = getSetting('tenancy', 'solo');
    43   // 'hub' is removed → coerce legacy values to 'solo'.
    44   return v === 'circle' ? 'circle' : 'solo';
     42  // Tenancy is retired: 'hub' and 'circle' were both removed. Every site is
     43  // 'solo'. Cirkels are now an ActivityPub feature (auto-boost), not a mode.
     44  return 'solo';
    4545}
    4646
    47 export function setTenancy(mode) {
    48   const m = mode === 'circle' ? 'circle' : 'solo';
    49   setSetting('tenancy', m);
     47export function setTenancy() {
     48  setSetting('tenancy', 'solo');
    5049}
    5150
  • src/views/pages/admin-settings.ejs

    r46f3dd6 r8ef8c3e  
    55  <% if (success) { %><div class="alert alert-success"><%= success %></div><% } %>
    66  <% if (typeof error !== 'undefined' && error) { %><div class="alert alert-error"><%= error %></div><% } %>
    7 
    8   <section class="set-card">
    9     <h2><%= t('aset.mode') %></h2>
    10     <p class="set-help">
    11       <%= t('aset.mode_help') %>
    12     </p>
    13 
    14     <form method="post" action="/admin/settings" class="set-form">
    15       <label class="set-opt">
    16         <input type="radio" name="tenancy" value="solo" <%= tenancy === 'solo' ? 'checked' : '' %>>
    17         <span>
    18           <strong><%= t('aset.solo') %></strong> — <%= t('aset.solo_title') %>
    19           <small><%= t('aset.solo_desc') %></small>
    20         </span>
    21       </label>
    22       <label class="set-opt">
    23         <input type="radio" name="tenancy" value="circle" <%= tenancy === 'circle' ? 'checked' : '' %>>
    24         <span>
    25           <strong><%= t('aset.circle') %></strong> &mdash; <%= t('aset.circle_title') %>
    26           <small><%= t('aset.circle_desc') %></small>
    27         </span>
    28       </label>
    29       <button type="submit" class="btn btn-primary"><%= t('aset.save') %></button>
    30     </form>
    31   </section>
    327
    338  <%# ── Default language for visitors ── %>
     
    7045
    7146  <%# Mode-specific config — Circle settings below the mode card. (Hub removed.) %>
    72   <% if (tenancy === 'circle') { %>
    73   <section class="set-card set-card--mode" style="margin-top:1rem">
    74     <h2>🔗 <%= t('aset.your_circle') %></h2>
    75     <p class="set-help">
    76       <%= t('aset.your_circle_help') %>
    77     </p>
    78     <div class="set-actions">
    79       <a href="/admin/circle" class="btn btn-primary"><%= t('aset.manage_circle') %> &rarr;</a>
    80     </div>
    81   </section>
    82   <% } %>
    8347
    8448  <%# Premium (Patreon) — only visible when the self-hoster enables the premium layer
  • src/views/pages/admin.ejs

    r46f3dd6 r8ef8c3e  
    4343        <a href="/admin/sites/new" class="btn"><%= t('admin.b_makesite') %></a>
    4444      <% } %>
    45       <% if (tenancy === 'circle') { %>
    46         <a href="/admin/circle" class="btn"><%= t('admin.b_circle') %></a>
    47       <% } %>
    4845      <% if (primarySite) { %><a href="/admin/seo" class="btn"><%= t('admin.b_seo') %></a><% } %>
    4946      <a href="/admin/settings" class="btn"><%= t('admin.b_settings') %></a>
  • src/views/pages/changelog.ejs

    r46f3dd6 r8ef8c3e  
    44  <p class="cl-meta">
    55    <%= t('chlog.app_version') %> <strong>v<%= appVersion %></strong>
    6     <span class="cl-sep">·</span>
    7     <%= t('chlog.fed_proto') %> <strong><%= proto %></strong>
    86    <% if (typeof user !== 'undefined' && user && user.role === 'god') { %>
    97      <span class="cl-sep">·</span> <a href="/admin/updates"><%= t('chlog.manage_updates') %></a>
Note: See TracChangeset for help on using the changeset viewer.