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) {
|
if (targetArtist) {
|
||||||
const albums = await all(`
|
const albums = await all(`
|
||||||
SELECT DISTINCT album, album_artist, year,
|
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,
|
(SELECT artwork_path FROM tracks t2 WHERE t2.album = tracks.album AND t2.artist = ? LIMIT 1) as artwork_path
|
||||||
COUNT(*) as track_count
|
|
||||||
FROM tracks
|
FROM tracks
|
||||||
WHERE artist = ?
|
WHERE artist = ?
|
||||||
GROUP BY album, album_artist
|
GROUP BY album, album_artist
|
||||||
ORDER BY year DESC, album
|
ORDER BY year DESC, album
|
||||||
`, [targetArtist, targetArtist]);
|
`, [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 => {
|
albums.forEach(album => {
|
||||||
const albumId = crypto.createHash('md5').update(`album-${album.album}-${album.album_artist}`).digest('hex');
|
const albumId = crypto.createHash('md5').update(`album-${album.album}-${album.album_artist}`).digest('hex');
|
||||||
const coverArt = album.artwork_path ? albumId : '';
|
const coverArt = album.artwork_path ? albumId : '';
|
||||||
dirXml += ` <child id="${albumId}" parent="${id}" title="${escapeXml(album.album)}" `;
|
dirXml += ` <child id="${albumId}" parent="${artistIdForParent}" `;
|
||||||
dirXml += `album="${escapeXml(album.album)}" artist="${escapeXml(targetArtist)}" `;
|
dirXml += `title="${escapeXml(album.album)}" `;
|
||||||
dirXml += `coverArt="${coverArt}" isDir="true"/>\n`;
|
dirXml += `album="${escapeXml(album.album)}" `;
|
||||||
|
dirXml += `artist="${escapeXml(targetArtist)}" `;
|
||||||
|
dirXml += `isDir="true" `;
|
||||||
|
dirXml += `coverArt="${coverArt}"/>\n`;
|
||||||
});
|
});
|
||||||
|
|
||||||
dirXml += '</directory>';
|
dirXml += '</directory>';
|
||||||
@@ -184,11 +187,16 @@ router.get('/getMusicDirectory.view', authenticateSubsonic, async (req, res) =>
|
|||||||
return sendSubsonicError(res, 70, 'Album not found');
|
return sendSubsonicError(res, 70, 'Album not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Find the parent artist ID
|
||||||
const firstTrack = tracks[0];
|
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 => {
|
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>';
|
dirXml += '</directory>';
|
||||||
|
|||||||
Reference in New Issue
Block a user