Fix getCoverArt to properly lookup artwork by album ID

This commit is contained in:
2025-12-07 23:27:19 +00:00
parent e0ca158bbb
commit 48bfa048a0

View File

@@ -554,8 +554,26 @@ router.get('/getCoverArt.view', authenticateSubsonic, async (req, res) => {
try { try {
const { id } = req.query; const { id } = req.query;
// Try to find artwork by album ID or track ID // First try to find by track ID
const track = await get('SELECT artwork_path FROM tracks WHERE id = ? OR id IN (SELECT id FROM tracks LIMIT 1)', [id]); let track = await get('SELECT artwork_path FROM tracks WHERE id = ?', [id]);
// If not found, the ID might be an album ID - decode it and find a track from that album
if (!track) {
// Try to find which album this ID represents
const allAlbums = await all(`SELECT DISTINCT album, album_artist FROM tracks`);
for (const album of allAlbums) {
const albumId = crypto.createHash('md5').update(`album-${album.album}-${album.album_artist}`).digest('hex');
if (albumId === id) {
// Found the album, get artwork from any track in this album
track = await get(
'SELECT artwork_path FROM tracks WHERE album = ? AND album_artist = ? AND artwork_path IS NOT NULL LIMIT 1',
[album.album, album.album_artist]
);
break;
}
}
}
if (!track || !track.artwork_path) { if (!track || !track.artwork_path) {
return res.status(404).send('Cover art not found'); return res.status(404).send('Cover art not found');
@@ -564,6 +582,7 @@ router.get('/getCoverArt.view', authenticateSubsonic, async (req, res) => {
const artworkPath = `${process.cwd()}/artwork/${track.artwork_path}`; const artworkPath = `${process.cwd()}/artwork/${track.artwork_path}`;
res.sendFile(artworkPath); res.sendFile(artworkPath);
} catch (error) { } catch (error) {
console.error('Error in getCoverArt:', error);
res.status(404).send('Cover art not found'); res.status(404).send('Cover art not found');
} }
}); });