fix(playlist-order): honor custom order in playlist songs endpoint by slicing trackIds and mapping results
This commit is contained in:
parent
8136bbb959
commit
484d191201
@ -172,13 +172,17 @@ router.get('/playlist/*', async (req: Request, res: Response) => {
|
||||
return total + seconds;
|
||||
}, 0);
|
||||
|
||||
// Get songs with pagination
|
||||
const songs = await Song.find(query)
|
||||
.sort({ title: 1 })
|
||||
.skip(skip)
|
||||
.limit(limit)
|
||||
// Get songs for this page in the exact playlist order
|
||||
const pageStart = (page - 1) * limit;
|
||||
const pageEnd = Math.min(pageStart + limit, trackIds.length);
|
||||
const pageTrackIds = trackIds.slice(pageStart, pageEnd);
|
||||
|
||||
const pageSongs = await Song.find({ id: { $in: pageTrackIds } })
|
||||
.populate('s3File.musicFileId')
|
||||
.lean();
|
||||
const idToSong: Record<string, any> = {};
|
||||
for (const s of pageSongs) idToSong[s.id] = s;
|
||||
const songs = pageTrackIds.map(id => idToSong[id]).filter(Boolean);
|
||||
|
||||
console.log(`Found ${songs.length} songs for playlist "${playlistName}" (${totalSongs} total), ${songs.filter((s: any) => s.s3File?.hasS3File).length} with S3 files`);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user