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
This commit is contained in:
parent
176c2b1574
commit
050e31288a
@ -4,100 +4,7 @@ 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) => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user