feat: add album routes, playlist detail, liked tracks, fix search/artist routing
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import mongoose from 'mongoose';
|
||||
import Track from '../models/Track.js';
|
||||
|
||||
export const searchController = {
|
||||
@@ -26,11 +27,42 @@ export const searchController = {
|
||||
.limit(50)
|
||||
.lean();
|
||||
|
||||
const artistNames = [...new Set(tracks.map(t => t.artist))];
|
||||
const artists = artistNames.map(name => ({ name }));
|
||||
const artistMap = new Map();
|
||||
tracks.forEach(t => {
|
||||
if (!artistMap.has(t.artist)) {
|
||||
artistMap.set(t.artist, {
|
||||
_id: new mongoose.Types.ObjectId(),
|
||||
name: t.artist,
|
||||
imageUrl: t.coverUrl || '',
|
||||
trackCount: 0,
|
||||
});
|
||||
}
|
||||
const entry = artistMap.get(t.artist);
|
||||
entry.trackCount++;
|
||||
if (t.coverUrl && !entry.imageUrl) {
|
||||
entry.imageUrl = t.coverUrl;
|
||||
}
|
||||
});
|
||||
const artists = [...artistMap.values()];
|
||||
|
||||
const albumNames = [...new Set(tracks.map(t => t.album))];
|
||||
const albums = albumNames.map(name => ({ name }));
|
||||
const albumMap = new Map();
|
||||
tracks.forEach(t => {
|
||||
if (!albumMap.has(t.album)) {
|
||||
albumMap.set(t.album, {
|
||||
_id: new mongoose.Types.ObjectId(),
|
||||
title: t.album,
|
||||
artist: t.artist,
|
||||
coverUrl: t.coverUrl || '',
|
||||
trackCount: 0,
|
||||
});
|
||||
}
|
||||
const entry = albumMap.get(t.album);
|
||||
entry.trackCount++;
|
||||
if (t.coverUrl && !entry.coverUrl) {
|
||||
entry.coverUrl = t.coverUrl;
|
||||
}
|
||||
});
|
||||
const albums = [...albumMap.values()];
|
||||
|
||||
const data = { tracks, artists, albums };
|
||||
|
||||
|
||||
Reference in New Issue
Block a user