source: Klonkt/src/routes/shows.js@ 294207e

main
Last change on this file since 294207e was 834bcc3, checked in by Robin Genis <roboburr@…>, 3 months ago

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@…>

  • Property mode set to 100644
File size: 3.4 KB
RevLine 
[8d32dcf]1/**
[834bcc3]2 * Show agenda + notify-me (premium feature #8) — public side.
[8d32dcf]3 *
[834bcc3]4 * GET /shows -> upcoming gigs + "keep me posted" form
5 * POST /shows/notify -> subscribe to show announcements (subscribers, source
6 * 'notify'; double opt-in if SMTP configured)
[8d32dcf]7 *
[834bcc3]8 * The notify confirm/unsubscribe reuses the generic subscriber links
[8d32dcf]9 * (/nieuwsbrief/bevestigen|uitschrijven/:token). Hub: /user/:slug/shows.
10 */
11
12import express from 'express';
13import db from '../config/database.js';
14import { renderPage } from '../middleware/render.js';
15import { premiumUnlocked } from '../services/PatreonService.js';
16import { mailerConfigured, sendMail } from '../config/mailer.js';
17import { addSubscriber } from '../services/SubscriberService.js';
[68b27a4]18import { getSetting } from '../services/SettingsService.js';
[8d32dcf]19
20const router = express.Router();
21
[834bcc3]22// Agenda is opt-in: only accessible once the admin has enabled it.
[68b27a4]23function agendaOn() { return getSetting('agenda_enabled') === '1'; }
24
[8d32dcf]25function esc(s) { return String(s || '').replace(/[&<>"]/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;' }[c])); }
26function fullUrl(req, p) {
27 const base = (process.env.PUBLIC_BASE_URL || ('https://' + (req.get('host') || ''))).replace(/\/$/, '');
28 return base + (req.res.locals.siteUrlBase || '') + p;
29}
30function upcoming(siteId) {
31 const today = new Date().toISOString().slice(0, 10);
32 return db.prepare('SELECT * FROM shows WHERE site_id = ? AND date >= ? ORDER BY date ASC, time ASC').all(siteId, today);
33}
34
35router.get('/shows', (req, res, next) => {
[68b27a4]36 if (!premiumUnlocked() || !agendaOn()) return next();
[8d32dcf]37 const site = res.locals.site;
38 if (!site) return next();
39 renderPage(req, res, 'pages/shows', {
40 pageTitle: 'Agenda — ' + (site.title || ''),
41 bodyClass: 'on-shows',
42 shows: upcoming(site.id),
43 notifyState: req.query.ok ? 'done' : (req.query.check ? 'check' : null),
44 });
45});
46
47router.post('/shows/notify', async (req, res, next) => {
[68b27a4]48 if (!premiumUnlocked() || !agendaOn()) return next();
[8d32dcf]49 const site = res.locals.site;
50 if (!site) return next();
51 const email = (req.body.email || '').trim();
52 const doubleOptin = mailerConfigured();
53 const r = addSubscriber(site.id, email, 'notify', { doubleOptin });
54 if (!r.ok) {
55 return renderPage(req, res, 'pages/shows', {
56 pageTitle: 'Agenda', bodyClass: 'on-shows', shows: upcoming(site.id),
57 notifyState: 'error', notifyMsg: r.error === 'invalid_email' ? 'Controleer je e-mailadres.' : 'Er ging iets mis.',
58 });
59 }
60 if (r.status === 'pending') {
61 const link = fullUrl(req, '/nieuwsbrief/bevestigen/' + r.token);
62 const unsub = fullUrl(req, '/nieuwsbrief/uitschrijven/' + r.token);
63 try {
64 await sendMail({
65 to: email,
66 subject: 'Bevestig — show-updates van ' + (site.title || ''),
67 text: 'Bevestig dat je show-aankondigingen wilt ontvangen: ' + link + '\n\nUitschrijven: ' + unsub,
68 html: '<p>Bevestig dat je show-aankondigingen van <strong>' + esc(site.title) + '</strong> wilt ontvangen:</p>' +
69 '<p><a href="' + link + '">Bevestigen</a></p><p style="color:#888;font-size:12px"><a href="' + unsub + '">Uitschrijven</a></p>',
70 });
71 } catch { return res.redirect((res.locals.siteUrlBase || '') + '/shows'); }
72 return res.redirect((res.locals.siteUrlBase || '') + '/shows?check=1');
73 }
74 res.redirect((res.locals.siteUrlBase || '') + '/shows?ok=1');
75});
76
77export default router;
Note: See TracBrowser for help on using the repository browser.