source: Klonkt/src/routes/admin-epk.js@ 834bcc3

main
Last change on this file since 834bcc3 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: 2.4 KB
Line 
1/**
2 * Admin: Edit press kit (EPK) — per-site bio + press contact.
3 *
4 * GET /admin/epk -> form with current bio + contact
5 * POST /admin/epk -> save (app_settings: epk_bio_<siteId> / epk_contact_<siteId>)
6 *
7 * The press kit page itself (/pers) reads these values; tracks + recent posts come
8 * automatically. Press kit is premium + solo (see routes/epk.js).
9 */
10
11import express from 'express';
12import db from '../config/database.js';
13import { renderPage } from '../middleware/render.js';
14import { requireGod } from '../middleware/auth.js';
15import { getSetting, setSetting } from '../services/SettingsService.js';
16import { premiumUnlocked } from '../services/PatreonService.js';
17
18const router = express.Router();
19
20const MAX_EPK_TRACKS = 5;
21
22router.get('/', requireGod, (req, res) => {
23 const site = res.locals.site;
24 if (!site) return res.status(404).send('Geen site');
25 if (!premiumUnlocked()) {
26 return res.status(403).send('Perskit is een premium-functie.');
27 }
28 const allTracks = db.prepare(
29 `SELECT id, title, artist FROM audio_tracks WHERE site_id = ? ORDER BY position ASC, created_at ASC`
30 ).all(site.id);
31 let chosen = [];
32 try { const r = JSON.parse(getSetting('epk_tracks_' + site.id, '') || '[]'); if (Array.isArray(r)) chosen = r; } catch (e) {}
33 renderPage(req, res, 'pages/admin-epk', {
34 pageTitle: 'Perskit bewerken',
35 bodyClass: 'on-admin',
36 site,
37 epkBio: getSetting('epk_bio_' + site.id, '') || '',
38 epkContact: getSetting('epk_contact_' + site.id, '') || '',
39 allTracks,
40 chosenTracks: chosen,
41 maxEpkTracks: MAX_EPK_TRACKS,
42 success: req.query.success || null,
43 });
44});
45
46router.post('/', requireGod, (req, res) => {
47 const site = res.locals.site;
48 if (!site) return res.status(404).send('Geen site');
49 setSetting('epk_bio_' + site.id, (req.body.epk_bio || '').toString().slice(0, 1000).trim());
50 setSetting('epk_contact_' + site.id, (req.body.epk_contact || '').toString().slice(0, 300).trim());
51 // Chosen tracks: only ids belonging to THIS site, max 5, in the supplied order.
52 let ids = req.body.epk_tracks;
53 if (!Array.isArray(ids)) ids = ids ? [ids] : [];
54 const valid = new Set(db.prepare('SELECT id FROM audio_tracks WHERE site_id = ?').all(site.id).map((r) => r.id));
55 ids = ids.map(String).filter((id) => valid.has(id)).slice(0, MAX_EPK_TRACKS);
56 setSetting('epk_tracks_' + site.id, JSON.stringify(ids));
57 res.redirect('/admin/epk?success=' + encodeURIComponent('Perskit opgeslagen'));
58});
59
60export default router;
Note: See TracBrowser for help on using the repository browser.