Changeset 0d7acdf in Klonkt for src/routes/admin-audio.js
- Timestamp:
- 06/20/2026 05:04:13 AM (3 months ago)
- Branches:
- main
- Children:
- 3ec691c
- Parents:
- fef781e
- File:
-
- 1 edited
-
src/routes/admin-audio.js (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/routes/admin-audio.js
rfef781e r0d7acdf 20 20 import { toWebp } from '../services/ImageWebpService.js'; 21 21 import { requireGod } from '../middleware/auth.js'; 22 import { transcodeToMp3 } from '../services/AudioTranscoder.js';22 import { transcodeToMp3, retagMp3 } from '../services/AudioTranscoder.js'; 23 23 import { audioUrl } from '../services/AudioStreamService.js'; 24 24 … … 168 168 const finalArtist = artist?.trim() || null; 169 169 const finalAlbum = album?.trim() || null; 170 // Eigenaarschap/licentie. credit valt terug op de artiest; deze gaan zowel de 171 // DB in als de ID3-tags van de mp3 (copyright + comment). 172 const finalCredit = (req.body.credit || '').trim() || finalArtist || null; 173 const finalLicense = (req.body.license || '').trim() || null; 170 174 171 175 console.log('[admin-audio] upload received:', { … … 186 190 artist: finalArtist || undefined, 187 191 album: finalAlbum || undefined, 192 copyright: finalCredit || undefined, 193 comment: finalLicense || undefined, 188 194 }, 189 195 }); … … 216 222 console.log('[admin-audio] inserting audio_tracks row (duration=' + finalDuration + ')'); 217 223 db.prepare(` 218 INSERT INTO audio_tracks (id, site_id, title, artist, album, duration, cover_url, media_id, position)219 VALUES (?, ?, ?, ?, ?, ?, ?, ?, COALESCE(224 INSERT INTO audio_tracks (id, site_id, title, artist, album, duration, cover_url, credit, license, media_id, position) 225 VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, COALESCE( 220 226 (SELECT MAX(position) + 1 FROM audio_tracks WHERE site_id = ?), 221 227 0 … … 226 232 finalDuration, 227 233 coverUrl, 234 finalCredit, finalLicense, 228 235 mediaId, site.id 229 236 ); … … 371 378 const t = db.prepare(` 372 379 SELECT t.id, t.title, t.artist, t.album, t.duration, t.cover_url, 373 t. position, t.created_at, m.filename380 t.credit, t.license, t.position, t.created_at, m.filename 374 381 FROM audio_tracks t LEFT JOIN media m ON m.id = t.media_id 375 382 WHERE t.id = ? AND t.site_id = ? … … 388 395 * fallback keeps working. 389 396 */ 390 router.post('/api/:id', requireGod, express.json(), (req, res) => {397 router.post('/api/:id', requireGod, express.json(), async (req, res) => { 391 398 const site = res.locals.site; 392 399 if (!site) return res.status(404).json({ error: 'Site required' }); … … 433 440 fields.push('downloadable = ?'); values.push(body.downloadable ? 1 : 0); 434 441 } 442 if (Object.prototype.hasOwnProperty.call(body, 'credit')) { 443 fields.push('credit = ?'); values.push(String(body.credit || '').trim() || null); 444 } 445 if (Object.prototype.hasOwnProperty.call(body, 'license')) { 446 fields.push('license = ?'); values.push(String(body.license || '').trim() || null); 447 } 435 448 436 449 if (fields.length === 0) { … … 445 458 } 446 459 447 // Return fresh row so the caller can update its UI without reloading 460 // Verse rij + (als tag-velden wijzigden) de mp3 her-taggen, zodat de eigenaar/ 461 // licentie ook IN het bestand staat (ID3) en meereist bij een download. 448 462 const fresh = db.prepare(` 449 SELECT id, title, artist, album, duration, cover_url 450 FROM audio_tracks WHERE id = ? AND site_id = ? 463 SELECT t.id, t.title, t.artist, t.album, t.duration, t.cover_url, t.credit, t.license, m.storage_path 464 FROM audio_tracks t LEFT JOIN media m ON m.id = t.media_id 465 WHERE t.id = ? AND t.site_id = ? 451 466 `).get(req.params.id, site.id); 452 res.json({ ok: true, track: fresh }); 467 468 const tagsChanged = ['title', 'artist', 'album', 'credit', 'license'] 469 .some((f) => Object.prototype.hasOwnProperty.call(body, f)); 470 if (fresh && fresh.storage_path && tagsChanged) { 471 try { 472 await retagMp3({ filePath: fresh.storage_path, tags: { 473 title: fresh.title || undefined, 474 artist: fresh.artist || undefined, 475 album: fresh.album || undefined, 476 copyright: fresh.credit || undefined, 477 comment: fresh.license || undefined, 478 } }); 479 } catch (e) { 480 console.warn('[admin-audio] ID3 her-taggen mislukt (DB is wel bijgewerkt):', e.message); 481 } 482 } 483 const { storage_path, ...trackOut } = fresh || {}; 484 res.json({ ok: true, track: trackOut }); 453 485 }); 454 486
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)