Changeset 91094a4 in Klonkt for src/routes/admin-audio.js


Ignore:
Timestamp:
06/19/2026 01:09:15 AM (3 months ago)
Author:
roboburr <roboburr@…>
Branches:
main
Children:
37edecd
Parents:
2e247e4
Message:

Download-for-email (premium feature #2)

Fan leaves their email -> receives the file; address is added to the mailing list
(source 'download', single opt-in so the download is not behind a confirm barrier).
Reuses SubscriberService (#1).

  • DB: audio_tracks.downloadable (default 0).
  • admin-audio: per-track no-JS toggle (POST /admin/audio/:id/downloadable) + ⬇ button in the admin list (premium-gated); downloadable also in the /api/:id whitelist.
  • routes/download.js (premium-gated): GET /downloads (list), GET /download/:id (capture page), POST /download/:id (save email + session grant), GET /download/:id/bestand (serves attachment from storage/audio, 15-min session window, path-traversal guards).
  • views: pages/downloads.ejs + pages/download.ejs (form/ready, auto-start download).
  • admin dashboard: ⬇ Downloads link (premium, non-hub).

node --check passed. Nothing else reuses this; #8 notify reuses subscribers.

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

File:
1 edited

Legend:

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

    r2e247e4 r91094a4  
    7878  const rows = db.prepare(`
    7979    SELECT t.id, t.title, t.artist, t.album, t.duration, t.cover_url,
    80            t.position, t.created_at, m.filename, m.size, m.mime_type
     80           t.position, t.created_at, t.downloadable, m.filename, m.size, m.mime_type
    8181    FROM audio_tracks t
    8282    LEFT JOIN media m ON m.id = t.media_id
     
    241241    });
    242242  });
     243});
     244
     245// Download-voor-email per track aan/uit (premium #2). Zonder-JS toggle vanaf de
     246// audio-beheerlijst → flip + terug.
     247router.post('/:id/downloadable', requireGod, (req, res) => {
     248  const site = res.locals.site;
     249  if (!site) return res.status(404).send('Site required');
     250  const row = db.prepare('SELECT downloadable FROM audio_tracks WHERE id = ? AND site_id = ?').get(req.params.id, site.id);
     251  if (row) {
     252    db.prepare('UPDATE audio_tracks SET downloadable = ? WHERE id = ? AND site_id = ?')
     253      .run(row.downloadable ? 0 : 1, req.params.id, site.id);
     254  }
     255  res.redirect('/admin/audio');
    243256});
    244257
     
    413426  }
    414427
     428  if (Object.prototype.hasOwnProperty.call(body, 'downloadable')) {
     429    fields.push('downloadable = ?'); values.push(body.downloadable ? 1 : 0);
     430  }
     431
    415432  if (fields.length === 0) {
    416433    return res.status(400).json({ error: 'Niks om te updaten' });
Note: See TracChangeset for help on using the changeset viewer.