Changeset e6ad948 in Klonkt for src/routes/admin-epk.js


Ignore:
Timestamp:
06/20/2026 06:47:41 AM (3 months ago)
Author:
roboburr <roboburr@…>
Branches:
main
Children:
08cfdaa
Parents:
57b1843
Message:

feat(epk): choose up to 5 tracks for the press kit (instead of auto top-5)

Press kit editor now has a track picker (checkboxes, max 5). /pers shows the
chosen tracks in that order; no selection → automatically the top 5 most
played. Stored as epk_tracks_<siteId> (validated on site + max 5).

Co-Authored-By: Claude <noreply@…>

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/routes/admin-epk.js

    r57b1843 re6ad948  
    1010
    1111import express from 'express';
     12import db from '../config/database.js';
    1213import { renderPage } from '../middleware/render.js';
    1314import { requireGod } from '../middleware/auth.js';
     
    1718const router = express.Router();
    1819
     20const MAX_EPK_TRACKS = 5;
     21
    1922router.get('/', requireGod, (req, res) => {
    2023  const site = res.locals.site;
     
    2326    return res.status(403).send('Perskit is een premium-functie.');
    2427  }
     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) {}
    2533  renderPage(req, res, 'pages/admin-epk', {
    2634    pageTitle: 'Perskit bewerken',
     
    2937    epkBio: getSetting('epk_bio_' + site.id, '') || '',
    3038    epkContact: getSetting('epk_contact_' + site.id, '') || '',
     39    allTracks,
     40    chosenTracks: chosen,
     41    maxEpkTracks: MAX_EPK_TRACKS,
    3142    success: req.query.success || null,
    3243  });
     
    3849  setSetting('epk_bio_' + site.id, (req.body.epk_bio || '').toString().slice(0, 1000).trim());
    3950  setSetting('epk_contact_' + site.id, (req.body.epk_contact || '').toString().slice(0, 300).trim());
     51  // Gekozen nummers: alleen ids van DEZE site, max 5, in de aangeleverde volgorde.
     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));
    4057  res.redirect('/admin/epk?success=' + encodeURIComponent('Perskit opgeslagen'));
    4158});
Note: See TracChangeset for help on using the changeset viewer.