Fix directory structure and add isDir flags for proper Amperfy navigation
This commit is contained in:
@@ -137,22 +137,25 @@ router.get('/getMusicDirectory.view', authenticateSubsonic, async (req, res) =>
|
||||
if (targetArtist) {
|
||||
const albums = await all(`
|
||||
SELECT DISTINCT album, album_artist, year,
|
||||
(SELECT artwork_path FROM tracks t2 WHERE t2.album = tracks.album AND t2.artist = ? LIMIT 1) as artwork_path,
|
||||
COUNT(*) as track_count
|
||||
(SELECT artwork_path FROM tracks t2 WHERE t2.album = tracks.album AND t2.artist = ? LIMIT 1) as artwork_path
|
||||
FROM tracks
|
||||
WHERE artist = ?
|
||||
GROUP BY album, album_artist
|
||||
ORDER BY year DESC, album
|
||||
`, [targetArtist, targetArtist]);
|
||||
|
||||
let dirXml = `<directory id="${id}" parent="1" name="${escapeXml(targetArtist)}">\n`;
|
||||
const artistIdForParent = crypto.createHash('md5').update(`artist-${targetArtist}`).digest('hex');
|
||||
let dirXml = `<directory id="${artistIdForParent}" parent="1" name="${escapeXml(targetArtist)}">\n`;
|
||||
|
||||
albums.forEach(album => {
|
||||
const albumId = crypto.createHash('md5').update(`album-${album.album}-${album.album_artist}`).digest('hex');
|
||||
const coverArt = album.artwork_path ? albumId : '';
|
||||
dirXml += ` <child id="${albumId}" parent="${id}" title="${escapeXml(album.album)}" `;
|
||||
dirXml += `album="${escapeXml(album.album)}" artist="${escapeXml(targetArtist)}" `;
|
||||
dirXml += `coverArt="${coverArt}" isDir="true"/>\n`;
|
||||
dirXml += ` <child id="${albumId}" parent="${artistIdForParent}" `;
|
||||
dirXml += `title="${escapeXml(album.album)}" `;
|
||||
dirXml += `album="${escapeXml(album.album)}" `;
|
||||
dirXml += `artist="${escapeXml(targetArtist)}" `;
|
||||
dirXml += `isDir="true" `;
|
||||
dirXml += `coverArt="${coverArt}"/>\n`;
|
||||
});
|
||||
|
||||
dirXml += '</directory>';
|
||||
@@ -184,11 +187,16 @@ router.get('/getMusicDirectory.view', authenticateSubsonic, async (req, res) =>
|
||||
return sendSubsonicError(res, 70, 'Album not found');
|
||||
}
|
||||
|
||||
// Find the parent artist ID
|
||||
const firstTrack = tracks[0];
|
||||
let dirXml = `<directory id="${id}" name="${escapeXml(targetAlbum)}">\n`;
|
||||
const parentArtistId = crypto.createHash('md5').update(`artist-${firstTrack.artist}`).digest('hex');
|
||||
|
||||
let dirXml = `<directory id="${id}" parent="${parentArtistId}" name="${escapeXml(targetAlbum)}">\n`;
|
||||
|
||||
tracks.forEach(track => {
|
||||
dirXml += buildSongXml(track, req);
|
||||
const songXml = buildSongXml(track, req);
|
||||
// Replace the closing /> with isDir="false" />
|
||||
dirXml += songXml.replace('type="music"/>', 'type="music" isDir="false"/>');
|
||||
});
|
||||
|
||||
dirXml += '</directory>';
|
||||
|
||||
Reference in New Issue
Block a user