From 050e31288ab91df4d4f19f5143c146643e0eef9d Mon Sep 17 00:00:00 2001 From: Geert Rademakes Date: Thu, 7 Aug 2025 08:57:10 +0200 Subject: [PATCH] chore: Remove debug endpoint after playlist issue resolution - Remove /api/songs/debug/playlist/:name endpoint - Debug endpoint was temporary and no longer needed - Playlist loading issue resolved by database reload - Clean up code after successful troubleshooting --- packages/backend/src/routes/songs.ts | 93 ---------------------------- 1 file changed, 93 deletions(-) diff --git a/packages/backend/src/routes/songs.ts b/packages/backend/src/routes/songs.ts index 562d4ce..c0b1a4f 100644 --- a/packages/backend/src/routes/songs.ts +++ b/packages/backend/src/routes/songs.ts @@ -4,100 +4,7 @@ import { Playlist } from '../models/Playlist.js'; 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 router.get('/', async (req: Request, res: Response) => {