source: Klonkt/src/routes/push.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: 2.7 KB
Line 
1/**
2 * Web Push (docs/webpush-design.md) slice 2: enable/disable + test.
3 * The public VAPID key is public by design (it only identifies this server to
4 * the browser's push service); everything that touches a subscription is a
5 * logged-in action. Web Push delivery itself is cookie-less.
6 */
7import express from 'express';
8import db from '../config/database.js';
9import { requireAuth } from '../middleware/auth.js';
10import Push from '../services/PushService.js';
11import { t as i18nT, resolveLang } from '../services/i18n.js';
12
13const router = express.Router();
14
15// A subscription row is personal: only its creator may touch it.
16function ownRow(endpoint, userId) {
17 if (!endpoint) return null;
18 const row = db.prepare('SELECT endpoint, user_id FROM push_subscriptions WHERE endpoint = ?').get(String(endpoint));
19 return row && row.user_id === userId ? row : null;
20}
21
22router.get('/vapid', async (req, res) => {
23 const key = await Push.publicKey();
24 if (!key) return res.status(503).json({ error: 'push_unavailable' });
25 res.json({ publicKey: key });
26});
27
28router.post('/subscribe', requireAuth, express.json({ limit: '16kb' }), async (req, res) => {
29 if (!(await Push.pushReady())) return res.status(503).json({ error: 'push_unavailable' });
30 const s = req.body && req.body.subscription;
31 const keys = s && s.keys;
32 const ok = Push.saveSubscription({
33 endpoint: s && s.endpoint, userId: req.session.user.id,
34 p256dh: keys && keys.p256dh, auth: keys && keys.auth,
35 alertTypes: req.body.alerts || null,
36 uaLabel: String(req.body.uaLabel || '').slice(0, 120) || null,
37 });
38 if (!ok) return res.status(400).json({ error: 'bad_subscription' });
39 res.json({ ok: true });
40});
41
42router.post('/unsubscribe', requireAuth, express.json({ limit: '4kb' }), (req, res) => {
43 const row = ownRow(req.body && req.body.endpoint, req.session.user.id);
44 if (!row) return res.status(404).json({ error: 'not_found' });
45 Push.deleteSubscription(row.endpoint);
46 res.json({ ok: true });
47});
48
49router.post('/alerts', requireAuth, express.json({ limit: '4kb' }), (req, res) => {
50 const row = ownRow(req.body && req.body.endpoint, req.session.user.id);
51 if (!row) return res.status(404).json({ error: 'not_found' });
52 Push.updateAlerts(row.endpoint, req.session.user.id, req.body.alerts || {});
53 res.json({ ok: true });
54});
55
56// A test ping to all of the caller's own devices (bypasses alert prefs).
57router.post('/test', requireAuth, async (req, res) => {
58 const L = resolveLang(req);
59 const sent = await Push.notifyUser(req.session.user.id, {
60 type: 'test', title: i18nT(L, 'push.n_test_t'),
61 body: i18nT(L, 'push.n_test_b'), url: '/admin/push',
62 });
63 res.json({ ok: true, sent });
64});
65
66export default router;
Note: See TracBrowser for help on using the repository browser.