Changeset 4c9c60b in Klonkt for src/routes/embed.js
- Timestamp:
- 06/25/2026 05:27:29 AM (3 months ago)
- Branches:
- main
- Children:
- ca25f360
- Parents:
- e951b7c
- File:
-
- 1 edited
-
src/routes/embed.js (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/routes/embed.js
re951b7c r4c9c60b 12 12 13 13 import express from 'express'; 14 import db from '../config/database.js'; 14 15 import { premiumUnlocked } from '../services/PatreonService.js'; 15 16 … … 28 29 ); 29 30 30 const tracks = (res.locals.audioTracks || []).map((t) => ({31 let tracks = (res.locals.audioTracks || []).map((t) => ({ 31 32 id: t.id, title: t.title, artist: t.artist, duration: t.duration, url: t.media_url, 32 33 })).filter((t) => t.url); 34 35 // ?post=<slug> → scope the player to that post's tracks (for the fediverse 36 // player card). Resolve [[track]]/[[album]]/[[playlist]] shortcodes → track ids. 37 const postSlug = (req.query.post || '').toString(); 38 if (postSlug) { 39 try { 40 const post = db.prepare("SELECT content FROM posts WHERE site_id = ? AND slug = ? AND status = 'published'").get(site.id, postSlug); 41 if (post && post.content) { 42 const ids = []; const seen = new Set(); 43 const add = (id) => { if (id && !seen.has(id)) { seen.add(id); ids.push(id); } }; 44 for (const m of post.content.matchAll(/\[\[track:([A-Za-z0-9_-]+)\]\]/g)) add(m[1]); 45 for (const m of post.content.matchAll(/\[\[album:([^\]]+)\]\]/g)) for (const r of db.prepare('SELECT id FROM audio_tracks WHERE site_id = ? AND album = ? ORDER BY position').all(site.id, m[1].trim())) add(r.id); 46 for (const m of post.content.matchAll(/\[\[playlist:([A-Za-z0-9_-]+)\]\]/g)) for (const r of db.prepare('SELECT track_id FROM playlist_tracks WHERE playlist_id = ? ORDER BY position').all(m[1])) add(r.track_id); 47 if (ids.length) { 48 const byId = new Map(tracks.map((t) => [t.id, t])); 49 const scoped = ids.map((id) => byId.get(id)).filter(Boolean); 50 if (scoped.length) tracks = scoped; 51 } 52 } 53 } catch { /* fall back to the full site player */ } 54 } 33 55 34 56 res.render('pages/embed-player', {
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)