source: Klonkt/src/routes/admin-paid.js@ 9a00f28

main
Last change on this file since 9a00f28 was 9a00f28, checked in by Robin <roboburr@…>, 7 weeks ago

Fix: test feedback round, cirkels tagline + report details + full i18n

Three findings from Bart's test pass, tied together by the new i18n keys:

  1. The admin tagline said "Solo mode" even with Cirkels (federation) on. Solo-tenancy now distinguishes: apEnabled -> "Cirkels-modus: jouw site, verbonden met de fediverse", else the solo line. New key in nl/en/de.
  1. Reports only showed who reported; now they show the reason and WHICH post. getNotifications resolves the stored objects URIs of a report: our own /ap/notes/<id> become "Over de post: <title>" links under the description; an empty reason renders "Geen reden opgegeven". Other URIs (the actor itself) are skipped, the row already names the account.
  1. Notificaties and Betaalde posts were hardcoded Dutch on an English-configured Klonkt. Everything now goes through t(): the two admin pages (including their client-side status strings, passed via the JSON data block), the admin menu buttons, and the visitor-facing paid pages (gate, passkey, result). Server-side push payloads translate too, using the SITE's content language (fallback KLONKT_DEFAULT_LANG), and the test ping uses the request language. Full nl/en/de dictionaries.

Changed files:
src/services/i18n.js

  • admin.tagline_cirkels, admin.b_paid/b_push/back, notif.report_about/ report_noreason, and the push.*, apaid.*, pgate.*, ppk.*, pres.* blocks in nl/en/de

src/routes/admin.js, src/views/pages/admin.ejs

  • circlesOn (apEnabled) -> cirkels tagline; menu buttons via t()

src/services/ActivityPubService.js

  • report objects resolved to post links; push payloads via i18nT with pushLang(slug) (site language)

src/views/pages/fedi-notifications.ejs

  • report reason fallback + "Over de post" links (+ styles)

src/routes/admin-push.js, src/views/pages/admin-push.ejs

  • pageTitleKey push.t; all copy + JS status strings via t()

src/routes/admin-paid.js, src/views/pages/admin-paid.ejs

  • pageTitleKey apaid.t; all copy via t(), copy-button label via data-attr

src/routes/paid.js

  • pageTitleKey pres.t / ppk.t

src/views/pages/paid-gate.ejs, paid-passkey.ejs, paid-result.ejs

  • visitor copy + JS strings via t()

src/routes/push.js

  • test notification via resolveLang(req)

-robo
Co-Authored-By: Claude Opus 4.8 <noreply@…>

  • Property mode set to 100644
File size: 3.3 KB
Line 
1/**
2 * Admin: Paid posts (premium module, god-only). Slice 1 of klonkt-demo-aki.
3 *
4 * GET /admin/paid -> the owner's Patreon config form + status
5 * POST /admin/paid -> save config (secret/token stored encrypted)
6 * POST /admin/paid/disconnect -> forget the config
7 *
8 * Premium-gated via premiumUnlocked(), like stats/downloads. This is the site
9 * owner's OWN Patreon campaign, separate from Klonkt Premium's license flow.
10 */
11import express from 'express';
12import { renderPage } from '../middleware/render.js';
13import { requireGod } from '../middleware/auth.js';
14import { premiumUnlocked } from '../services/PatreonService.js';
15import { cryptoBoxReady } from '../services/CryptoBox.js';
16import PaidPatreon from '../services/PaidPatreonService.js';
17
18const router = express.Router();
19
20// The redirect URI the owner MUST whitelist in their Patreon client. Must match
21// exactly what paid.js sends, or Patreon shows its own error page (which we
22// cannot skin) instead of returning the visitor to us.
23const redirectUri = (req) =>
24 (process.env.PUBLIC_BASE_URL || `${req.protocol}://${req.get('host')}`).replace(/\/+$/, '') + '/paid/callback';
25
26function gate(req, res) {
27 if (!premiumUnlocked()) {
28 res.status(403).send('Betaalde posts is een premium-functie: koppel Patreon in Beheer, Instellingen.');
29 return false;
30 }
31 if (!res.locals.site) { res.status(400).send('Geen site.'); return false; }
32 return true;
33}
34
35router.get('/', requireGod, (req, res) => {
36 if (!gate(req, res)) return;
37 renderPage(req, res, 'pages/admin-paid', {
38 pageTitleKey: 'apaid.t',
39 bodyClass: 'on-admin',
40 status: PaidPatreon.ownerStatus(res.locals.site.id),
41 secretReady: cryptoBoxReady(),
42 redirectUri: redirectUri(req),
43 saved: req.query.saved === '1',
44 error: req.query.error || null,
45 });
46});
47
48router.post('/', requireGod, (req, res) => {
49 if (!gate(req, res)) return;
50 if (!cryptoBoxReady()) return res.redirect('/admin/paid?error=' + encodeURIComponent('De encryptiesleutel kon niet worden aangemaakt of gelezen (schrijfrechten op de opslagmap?); secrets kunnen niet veilig worden opgeslagen.'));
51 const b = req.body || {};
52 const eur = String(b.default_min_eur || '').replace(',', '.').trim();
53 const cents = eur ? Math.round(parseFloat(eur) * 100) : undefined;
54 try {
55 PaidPatreon.saveOwnerConfig(res.locals.site.id, {
56 clientId: (b.client_id || '').trim() || undefined,
57 // Empty secret/token fields keep the stored value (no re-paste needed).
58 clientSecret: (b.client_secret || '').trim() || undefined,
59 campaignId: (b.campaign_id || '').trim() || undefined,
60 accessToken: (b.access_token || '').trim() || undefined,
61 refreshToken: (b.refresh_token || '').trim() || undefined,
62 // Empty clears it (null), a value sets it. Unlike secrets, this is not
63 // sensitive and there's a clear "remove the link" intent.
64 patreonUrl: (b.patreon_url || '').trim() || null,
65 defaultMinCents: Number.isFinite(cents) ? cents : undefined,
66 });
67 return res.redirect('/admin/paid?saved=1');
68 } catch (e) {
69 return res.redirect('/admin/paid?error=' + encodeURIComponent(e.message || 'Opslaan mislukt'));
70 }
71});
72
73router.post('/disconnect', requireGod, (req, res) => {
74 if (!gate(req, res)) return;
75 PaidPatreon.disconnect(res.locals.site.id);
76 res.redirect('/admin/paid?saved=1');
77});
78
79export default router;
Note: See TracBrowser for help on using the repository browser.