Changeset e27b8db in Klonkt for src/routes/guardian.js
- Timestamp:
- 07/29/2026 10:04:36 AM (6 weeks ago)
- Branches:
- main
- Children:
- 329873e
- Parents:
- 88d7c8f
- File:
-
- 1 edited
-
src/routes/guardian.js (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/routes/guardian.js
r88d7c8f re27b8db 54 54 'away_title', 'away_sub', 'away_week', 'away_month', 'away_done', 55 55 // A gated-setting proposal from a fellow guardian (5.6). 56 'gated_title', 'gated_line_on', 'gated_line_off', 'gated_agree', 'gated_disagree']; 56 'gated_title', 'gated_line_on', 'gated_line_off', 'gated_agree', 'gated_disagree', 57 'play_propose', 'play_on', 'play_off']; 57 58 const s = Object.fromEntries(keys.map((k) => [k, i18nT(L, `guardian.${k}`)])); 58 59 s.wave = i18nT(L, 'guardian.wave'); … … 90 91 ...w, 91 92 embeds: wardEmbedSetting(w.other_uri), 93 playback: wardPlaybackSetting(w.other_uri), 92 94 guardians: wardGuardianStatuses(w.other_uri), 93 95 })), … … 466 468 * the ward lives elsewhere and the setting is not ours to show. 467 469 */ 468 function wardEmbedSetting(uri) { 470 function wardEmbedSetting(uri) { return wardGateSetting(uri, 'external_embeds'); } 471 /** The playback gate of a ward we host (5.6): the heavier sibling. */ 472 function wardPlaybackSetting(uri) { return wardGateSetting(uri, 'external_playback'); } 473 function wardGateSetting(uri, column) { 469 474 const base = (process.env.PUBLIC_BASE_URL || '').replace(/\/+$/, ''); 470 475 if (!base || !String(uri || '').startsWith(`${base}/`)) return null; 471 476 const slug = String(uri).trim().replace(/\/+$/, '').split('/').pop(); 472 const row = slug ? db.prepare( 'SELECT external_embeds FROM sites WHERE slug = ?').get(slug) : null;477 const row = slug ? db.prepare(`SELECT ${column === 'external_playback' ? 'external_playback' : 'external_embeds'} AS v FROM sites WHERE slug = ?`).get(slug) : null; 473 478 if (!row) return null; 474 return row. external_embeds === null || row.external_embeds === undefined ? false : row.external_embeds=== 1;479 return row.v === null || row.v === undefined ? false : row.v === 1; 475 480 } 476 481 … … 480 485 // can move, and only a committed guardian of THAT ward may move it. 481 486 router.post('/wards/embeds', requireAuth, express.json({ limit: '4kb' }), (req, res) => { 487 req.body = { ...req.body, feature: req.body?.feature === 'shaer:externalPlayback' ? 'shaer:externalPlayback' : 'shaer:externalEmbeds' }; 488 return proposeGated(req, res); 489 }); 490 function proposeGated(req, res) { 482 491 const site = siteForUser(req); 483 492 if (!site) return res.status(404).json({ error: 'no_site' }); … … 496 505 const base = (process.env.PUBLIC_BASE_URL || '').replace(/\/+$/, ''); 497 506 const me = AP.actorId(base, site.slug); 498 const feature = 'shaer:externalEmbeds';507 const feature = req.body.feature; // normalised by the route above 499 508 const offerId = `${me}/gated/${Date.now().toString(36)}${Math.floor(Math.random() * 1e4).toString(36)}`; 500 509 const offer = Guardianship.gated.buildGatedOffer(offerId, me, uri, feature, allow); … … 504 513 Guardianship.gated.rememberGatedOffer(offerId, localWard.slug, feature, allow); 505 514 const r = Guardianship.gated.recordGatedVote(localWard.slug, feature, me, allow); 515 // Same forward as the S2S path: without it the other guardians never learn 516 // the proposal exists and a threshold of two can never be met. 517 if (r.state === 'open') { 518 for (const g of Guardianship.listGuardians(localWard.slug).map((x) => x.other_uri)) { 519 if (g === me) continue; 520 AP.deliverToActor(site, g, { ...offer, to: [g] }).catch(() => { /* queued */ }); 521 } 522 } 506 523 return res.json({ ok: true, allow, state: r.state, need: r.need, of: r.of }); 507 524 }
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)