feat: Add debug endpoint for playlist troubleshooting
- Add /api/songs/debug/playlist/:name endpoint - Debug endpoint shows playlist structure and track data - Lists all available playlists when target not found - Shows track IDs and whether songs exist for those IDs - Helps diagnose playlist loading issues - Useful for troubleshooting missing songs in playlists This will help identify why songs are not showing in playlists like 'Disco'.
This commit is contained in:
parent
ba78aabd53
commit
176c2b1574
@ -4,6 +4,101 @@ import { Playlist } from '../models/Playlist.js';
|
|||||||
|
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
|
|
||||||
|
// Debug endpoint to check playlist data
|
||||||
|
router.get('/debug/playlist/:name', async (req: Request, res: Response) => {
|
||||||
|
try {
|
||||||
|
const playlistName = req.params.name;
|
||||||
|
console.log(`Debug: Checking playlist "${playlistName}"`);
|
||||||
|
|
||||||
|
// Get all playlists
|
||||||
|
const allPlaylists = await Playlist.find({});
|
||||||
|
console.log(`Debug: Found ${allPlaylists.length} playlist documents`);
|
||||||
|
|
||||||
|
// Find the specific playlist
|
||||||
|
const findPlaylistRecursively = (nodes: any[], targetName: string): any => {
|
||||||
|
for (const node of nodes) {
|
||||||
|
if (node.name === targetName) {
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
if (node.children && node.children.length > 0) {
|
||||||
|
const found = findPlaylistRecursively(node.children, targetName);
|
||||||
|
if (found) return found;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
|
let playlist = null;
|
||||||
|
for (const playlistDoc of allPlaylists) {
|
||||||
|
playlist = findPlaylistRecursively([playlistDoc], playlistName);
|
||||||
|
if (playlist) break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!playlist) {
|
||||||
|
// List all available playlists
|
||||||
|
const getAllPlaylistNames = (nodes: any[]): string[] => {
|
||||||
|
const names: string[] = [];
|
||||||
|
for (const node of nodes) {
|
||||||
|
names.push(node.name);
|
||||||
|
if (node.children && node.children.length > 0) {
|
||||||
|
names.push(...getAllPlaylistNames(node.children));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return names;
|
||||||
|
};
|
||||||
|
|
||||||
|
const allNames: string[] = [];
|
||||||
|
for (const playlistDoc of allPlaylists) {
|
||||||
|
allNames.push(...getAllPlaylistNames([playlistDoc]));
|
||||||
|
}
|
||||||
|
|
||||||
|
return res.json({
|
||||||
|
error: `Playlist "${playlistName}" not found`,
|
||||||
|
availablePlaylists: allNames,
|
||||||
|
playlistDocuments: allPlaylists.map(p => ({ name: p.name, type: p.type }))
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get track IDs from playlist
|
||||||
|
const getAllTrackIds = (node: any): string[] => {
|
||||||
|
if (node.type === 'playlist' && node.tracks) {
|
||||||
|
return node.tracks;
|
||||||
|
}
|
||||||
|
if (node.type === 'folder' && node.children) {
|
||||||
|
return node.children.flatMap((child: any) => getAllTrackIds(child));
|
||||||
|
}
|
||||||
|
return [];
|
||||||
|
};
|
||||||
|
|
||||||
|
const trackIds = getAllTrackIds(playlist);
|
||||||
|
|
||||||
|
// Check if songs exist for these track IDs
|
||||||
|
const songs = await Song.find({ id: { $in: trackIds } }).lean();
|
||||||
|
const songIds = songs.map(s => s.id);
|
||||||
|
|
||||||
|
res.json({
|
||||||
|
playlist: {
|
||||||
|
name: playlist.name,
|
||||||
|
type: playlist.type,
|
||||||
|
trackIds: trackIds,
|
||||||
|
trackCount: trackIds.length
|
||||||
|
},
|
||||||
|
songs: {
|
||||||
|
found: songIds,
|
||||||
|
foundCount: songs.length,
|
||||||
|
missing: trackIds.filter(id => !songIds.includes(id))
|
||||||
|
},
|
||||||
|
debug: {
|
||||||
|
playlistStructure: playlist,
|
||||||
|
allPlaylistDocuments: allPlaylists.length
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Debug error:', error);
|
||||||
|
res.status(500).json({ error: 'Debug endpoint error', details: error });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Get songs with pagination and search
|
// Get songs with pagination and search
|
||||||
router.get('/', async (req: Request, res: Response) => {
|
router.get('/', async (req: Request, res: Response) => {
|
||||||
try {
|
try {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user