Changeset 65abc85 in Klonkt for src/routes/guardian.js
- Timestamp:
- 07/28/2026 10:40:50 AM (6 weeks ago)
- Branches:
- main
- Children:
- 2708282
- Parents:
- 2a76184
- File:
-
- 1 edited
-
src/routes/guardian.js (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/routes/guardian.js
r2a76184 r65abc85 39 39 const keys = ['sent', 'sent_retry', 'sending', 'not_found', 'failed', 'network', 40 40 'pending', 'active', 'retract', 'release', 'release_confirm', 'open', 'push_unavailable', 41 'embeds_on', 'embeds_off', 41 'embeds_on', 'embeds_off', 'embeds_propose', 'embeds_waiting', 42 42 'accept', 'reject', 'complete', 'awaiting_others', 'coguard']; 43 43 const s = Object.fromEntries(keys.map((k) => [k, i18nT(L, `guardian.${k}`)])); … … 300 300 const isMyWard = Guardianship.listWards(site.slug).some((w) => w.other_uri === uri); 301 301 if (!isMyWard) return res.status(403).json({ error: 'not_your_ward' }); 302 const base = (process.env.PUBLIC_BASE_URL || '').replace(/\/+$/, ''); 303 const slug = (base && uri.startsWith(`${base}/`)) ? uri.trim().replace(/\/+$/, '').split('/').pop() : null; 304 const ward = slug ? db.prepare('SELECT id, slug FROM sites WHERE slug = ?').get(slug) : null; 305 if (!ward) return res.status(400).json({ error: 'remote_ward_not_supported' }); 306 db.prepare('UPDATE sites SET external_embeds = ? WHERE id = ?').run(allow ? 1 : 0, ward.id); 307 res.json({ ok: true, allow }); 302 // §5.6: propose it to the WARD'S server, wherever that is. The ward's server 303 // tallies (a majority of its guardians, §3.5) and enforces. Co-location is 304 // just the case where that server happens to be this one, so it takes the 305 // same road: propose, then let the tally decide. Anything else would make a 306 // guardian on the ward's own instance more powerful than one elsewhere. 307 const base = (process.env.PUBLIC_BASE_URL || '').replace(/\/+$/, ''); 308 const me = AP.actorId(base, site.slug); 309 const feature = 'shaer:externalEmbeds'; 310 const offerId = `${me}/gated/${Date.now().toString(36)}${Math.floor(Math.random() * 1e4).toString(36)}`; 311 const offer = Guardianship.gated.buildGatedOffer(offerId, me, uri, feature, allow); 312 const localSlug = (base && uri.startsWith(`${base}/`)) ? uri.replace(/\/+$/, '').split('/').pop() : null; 313 const localWard = localSlug ? db.prepare('SELECT slug FROM sites WHERE slug = ?').get(localSlug) : null; 314 if (localWard) { 315 Guardianship.gated.rememberGatedOffer(offerId, localWard.slug, feature, allow); 316 const r = Guardianship.gated.recordGatedVote(localWard.slug, feature, me, allow); 317 return res.json({ ok: true, allow, state: r.state, need: r.need, of: r.of }); 318 } 319 AP.deliverTo(site, uri, offer).catch(() => { /* queued, best-effort */ }); 320 res.json({ ok: true, allow, state: 'open', federated: true }); 308 321 }); 309 322
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)