Fix directory structure and add isDir flags for proper Amperfy navigation

This commit is contained in:
2025-12-07 23:17:27 +00:00
parent 12a8faea53
commit 6d06f7621c

View File

@@ -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>';