Changeset 834bcc3 in Klonkt for src/services/CircleService.js


Ignore:
Timestamp:
06/23/2026 06:14:27 PM (3 months ago)
Author:
Robin Genis <roboburr@…>
Branches:
main
Children:
d774679
Parents:
bb42dfb
Message:

i18n: translate Dutch code comments to English across src/

Comments in routes/services/views/config/middleware/assets translated to
English for the public repo. A few dev-facing throw/console message strings
were Englished too. No user-facing UI strings or i18n dictionary values changed
(src/services/i18n.js untouched). Logic unchanged.

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/services/CircleService.js

    rbb42dfb r834bcc3  
    1 // CircleService.js — pull-kant van Cirkels (v1).
     1// CircleService.js — pull side of Circles (v1).
    22//
    3 // Haalt per circle_link de remote actor + outbox op, verifieert de Ed25519-
    4 // handtekening, sanitiseert en cachet publieke posts in remote_actors/remote_posts.
    5 // Alleen LEZEN van remote; nooit schrijven. Zie docs/cirkels-v1-spec.md §5b.
     3// Per circle_link: fetches the remote actor + outbox, verifies the Ed25519
     4// signature, sanitizes, and caches public posts in remote_actors/remote_posts.
     5// READ ONLY from remote; never write. See docs/cirkels-v1-spec.md §5b.
    66
    77import db from '../config/database.js';
     
    1616  return String(s || '')
    1717    .replace(/<[^>]+>/g, ' ')
    18     .replace(/\[\[[^\]]*\]\]/g, ' ')   // [[playlist:..]]/[[track:..]]/[[album:..]]-shortcodes weg
     18    .replace(/\[\[[^\]]*\]\]/g, ' ')   // strip [[playlist:..]] / [[track:..]] / [[album:..]] shortcodes
    1919    .replace(/\s+/g, ' ')
    2020    .trim();
     
    3131}
    3232
    33 // AS Hashtag-array -> comma-separated tagnamen (zonder #), gesanitized.
     33// AS Hashtag array -> comma-separated tag names (without #), sanitized.
    3434function extractTags(tag) {
    3535  if (!Array.isArray(tag)) return null;
     
    4141}
    4242
    43 // Bron buiten de cirkel zetten met een leesbare reden (geen stille mislukking).
    44 // Aparte status 'outdated' zodat de Beheer-UI er een nette "update vereist"-
    45 // melding van kan maken i.p.v. een generieke fout.
     43// Mark a source as outside the circle with a readable reason (no silent failure).
     44// Separate 'outdated' status so the admin UI can show a clean "update required"
     45// notice instead of a generic error.
    4646function markOutdated(link, msg) {
    47   // Gecachte posts van deze bron weghalen: we kunnen ze niet meer verifiëren of
    48   // verversen (proto-mismatch), dus ze horen niet meer in de cirkel-feed.
     47  // Remove cached posts from this source: we can no longer verify or refresh
     48  // them (proto mismatch), so they no longer belong in the circle feed.
    4949  if (link.remote_actor_id) {
    5050    try { db.prepare('DELETE FROM remote_posts WHERE actor_id = ?').run(link.remote_actor_id); } catch {}
     
    5555}
    5656
    57 // Robuuste, defensieve fetch: alleen https, timeout, body-cap, redirect-follow.
     57// Robust, defensive fetch: https only, timeout, body cap, redirect follow.
    5858async function fetchText(url) {
    5959  if (!/^https:\/\//i.test(url)) throw new Error('alleen https toegestaan');
     
    6666      headers: {
    6767        Accept: 'application/activity+json, application/json',
    68         // Vertel de publisher onze proto → die kan ons met 426 weren als we te oud zijn.
     68        // Tell the publisher our proto → they can reject us with 426 if we are too old.
    6969        'Klonkt-Proto': String(KLONKT_PROTO),
    7070      },
     
    7272    if (!res.ok) throw new Error(`HTTP ${res.status}`);
    7373    const buf = Buffer.from(await res.arrayBuffer());
    74     if (buf.length > MAX_BODY_BYTES) throw new Error('body te groot');
     74    if (buf.length > MAX_BODY_BYTES) throw new Error('body too large');
    7575    return { text: buf.toString('utf8'), headers: res.headers, finalUrl: res.url };
    7676  } finally {
     
    7979}
    8080
    81 // Lazy prepares — de tabellen bestaan pas ná initializeDatabase(); dit module
    82 // wordt geïmporteerd vóór die call, dus niet op module-niveau prepare'n.
     81// Lazy prepares — tables only exist after initializeDatabase(); this module is
     82// imported before that call, so do not prepare at module level.
    8383let _stmts = null;
    8484function stmts() {
     
    107107  const base = baseOf(link.remote_url);
    108108
    109   // 1. Actor ophalen + valideren
     109  // 1. Fetch + validate actor
    110110  const actorUrl = `${base}/.klonkt/actor.json`;
    111111  const a = await fetchText(actorUrl);
     
    117117  if (originOf(actorId) !== originOf(actorUrl)) throw new Error('actor.id heeft andere origin dan de actor-URL');
    118118
    119   // Protocol-versie-gate. De proto zit óók in de outbox-handtekening-grondslag,
    120   // dus liegen in de (ongetekende) actor helpt niet: bij een echte mismatch faalt
    121   // de verificatie verderop alsnog. Hier vooral voor een DUIDELIJKE melding +
    122   // buitensluiten zonder stille mislukking.
     119  // Protocol version gate. The proto is also embedded in the outbox signing
     120  // input, so lying in the (unsigned) actor does not help: a real mismatch
     121  // will still fail verification later. This check is mainly for a CLEAR
     122  // message + exclusion without silent failure.
    123123  const remoteProto = Number(actor.klonkt && actor.klonkt.proto) || 1;
    124124  if (remoteProto > KLONKT_PROTO) {
     
    131131  }
    132132
    133   // TOFU: een sleutelwissel vereist expliciete herbevestiging (anti-hijack)
     133  // TOFU: a key change requires explicit re-confirmation (anti-hijack)
    134134  const existing = db.prepare('SELECT public_key FROM remote_actors WHERE id = ?').get(actorId);
    135135  if (existing && existing.public_key !== pubKey) {
     
    146146  });
    147147
    148   // 2. Outbox ophalen + handtekening verifiëren
     148  // 2. Fetch outbox + verify signature
    149149  const outboxUrl = actor.outbox || `${base}/.klonkt/outbox.json`;
    150150  const o = await fetchText(outboxUrl);
     
    158158  const items = Array.isArray(outbox.orderedItems) ? outbox.orderedItems.slice(0, MAX_ITEMS) : [];
    159159
    160   // 3. Objecten sanitizen + cachen (same-origin als de actor = anti-impersonatie)
     160  // 3. Sanitize + cache objects (same origin as actor = anti-impersonation)
    161161  const actorOrigin = originOf(actorId);
    162162  const seen = new Set();
     
    186186  }
    187187
    188   // 4. Pruning: posts die niet meer in de outbox staan opruimen
     188  // 4. Pruning: remove posts that are no longer in the outbox
    189189  const known = db.prepare('SELECT id FROM remote_posts WHERE actor_id = ?').all(actorId).map((r) => r.id);
    190190  const stale = known.filter((id) => !seen.has(id));
     
    194194  }
    195195
    196   // Naam automatisch overnemen van de remote actor (geen handmatige invoer nodig).
    197   // COALESCE: heeft de actor geen naam, dan blijft een evt. bestaand label staan.
     196  // Automatically adopt the name from the remote actor (no manual entry needed).
     197  // COALESCE: if the actor has no name, any existing label is preserved.
    198198  db.prepare(
    199199    "UPDATE circle_links SET remote_actor_id=?, label=COALESCE(?, label), last_synced=CURRENT_TIMESTAMP, status='active', last_error=NULL WHERE id=?"
     
    221221
    222222let _timer = null;
    223 /** Periodieke achtergrond-sync (gated op tenancy='circle' binnen sync()). */
     223/** Periodic background sync (gated on tenancy='circle' inside sync()). */
    224224export function startCircleSyncLoop(intervalMs = 15 * 60 * 1000) {
    225225  if (_timer) return;
    226226  const run = () => { sync().catch((e) => console.error('[cirkels] sync-fout:', e.message)); };
    227   setTimeout(run, 30 * 1000); // korte delay na boot
     227  setTimeout(run, 30 * 1000); // short delay after boot
    228228  _timer = setInterval(run, intervalMs);
    229229  if (_timer.unref) _timer.unref();
Note: See TracChangeset for help on using the changeset viewer.