Fix getCoverArt to properly lookup artwork by album ID
This commit is contained in:
@@ -554,8 +554,26 @@ router.get('/getCoverArt.view', authenticateSubsonic, async (req, res) => {
|
||||
try {
|
||||
const { id } = req.query;
|
||||
|
||||
// Try to find artwork by album ID or track ID
|
||||
const track = await get('SELECT artwork_path FROM tracks WHERE id = ? OR id IN (SELECT id FROM tracks LIMIT 1)', [id]);
|
||||
// First try to find by track 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) {
|
||||
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}`;
|
||||
res.sendFile(artworkPath);
|
||||
} catch (error) {
|
||||
console.error('Error in getCoverArt:', error);
|
||||
res.status(404).send('Cover art not found');
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user