Changeset 183875b in Klonkt for src/routes/admin-audio.js
- Timestamp:
- 06/20/2026 05:23:08 AM (3 months ago)
- Branches:
- main
- Children:
- d727e92
- Parents:
- 459acd9
- File:
-
- 1 edited
-
src/routes/admin-audio.js (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/routes/admin-audio.js
r459acd9 r183875b 72 72 73 73 const router = express.Router(); 74 75 // "Open in"-platformlinks per track: alleen https + de juiste host accepteren 76 // (href komt ongeescaped in de view → scheme/host-guard tegen misbruik). 77 const LINK_DOMAINS = { 78 spotify: ['spotify.com'], 79 youtube: ['youtube.com', 'youtu.be', 'music.youtube.com'], 80 soundcloud: ['soundcloud.com'], 81 }; 82 function platformLink(url, domains) { 83 const u = String(url || '').trim(); 84 if (!u || !/^https:\/\//i.test(u)) return null; 85 try { 86 const h = new URL(u).hostname.toLowerCase(); 87 if (domains.some((d) => h === d || h.endsWith('.' + d))) return u; 88 } catch (e) { /* ongeldige URL */ } 89 return null; 90 } 74 91 75 92 router.get('/', requireGod, (req, res) => { … … 172 189 const finalCredit = (req.body.credit || '').trim() || finalArtist || null; 173 190 const finalLicense = (req.body.license || '').trim() || null; 191 const finalLinkSpotify = platformLink(req.body.link_spotify, LINK_DOMAINS.spotify); 192 const finalLinkYoutube = platformLink(req.body.link_youtube, LINK_DOMAINS.youtube); 193 const finalLinkSoundcloud = platformLink(req.body.link_soundcloud, LINK_DOMAINS.soundcloud); 174 194 175 195 console.log('[admin-audio] upload received:', { … … 222 242 console.log('[admin-audio] inserting audio_tracks row (duration=' + finalDuration + ')'); 223 243 db.prepare(` 224 INSERT INTO audio_tracks (id, site_id, title, artist, album, duration, cover_url, credit, license, media_id, position)225 VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, COALESCE(244 INSERT INTO audio_tracks (id, site_id, title, artist, album, duration, cover_url, credit, license, link_spotify, link_youtube, link_soundcloud, media_id, position) 245 VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, COALESCE( 226 246 (SELECT MAX(position) + 1 FROM audio_tracks WHERE site_id = ?), 227 247 0 … … 233 253 coverUrl, 234 254 finalCredit, finalLicense, 255 finalLinkSpotify, finalLinkYoutube, finalLinkSoundcloud, 235 256 mediaId, site.id 236 257 ); … … 378 399 const t = db.prepare(` 379 400 SELECT t.id, t.title, t.artist, t.album, t.duration, t.cover_url, 380 t.credit, t.license, t.position, t.created_at, m.filename 401 t.credit, t.license, t.link_spotify, t.link_youtube, t.link_soundcloud, 402 t.position, t.created_at, m.filename 381 403 FROM audio_tracks t LEFT JOIN media m ON m.id = t.media_id 382 404 WHERE t.id = ? AND t.site_id = ? … … 445 467 if (Object.prototype.hasOwnProperty.call(body, 'license')) { 446 468 fields.push('license = ?'); values.push(String(body.license || '').trim() || null); 469 } 470 if (Object.prototype.hasOwnProperty.call(body, 'link_spotify')) { 471 fields.push('link_spotify = ?'); values.push(platformLink(body.link_spotify, LINK_DOMAINS.spotify)); 472 } 473 if (Object.prototype.hasOwnProperty.call(body, 'link_youtube')) { 474 fields.push('link_youtube = ?'); values.push(platformLink(body.link_youtube, LINK_DOMAINS.youtube)); 475 } 476 if (Object.prototype.hasOwnProperty.call(body, 'link_soundcloud')) { 477 fields.push('link_soundcloud = ?'); values.push(platformLink(body.link_soundcloud, LINK_DOMAINS.soundcloud)); 447 478 } 448 479
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)