fix: iTunes route order (lookup before proxy); stable cover art URLs for browser caching
This commit is contained in:
1 parent
09cec18b33
commit
21159ad2c5
3 files changed
+45
-24
No files matched your search
+24
-22
@@ -160,8 +160,32 @@ app.post('/api/spotify/track-artwork', async (req, res) => {
|
||||
res.json({ results });
|
||||
});
|
||||
|
||||
// ─── ITUNES METADATA LOOKUP (must be before the proxy route) ─────────────────
|
||||
app.get('/api/itunes/lookup', async (req, res) => {
|
||||
const { artist, title } = req.query;
|
||||
if (!artist || !title) return res.status(400).json({ error: 'artist and title required' });
|
||||
try {
|
||||
const meta = await lookupItunesTrackMeta(artist, title);
|
||||
if (!meta.album && !meta.genre && !meta.year) return res.json({ found: false });
|
||||
res.json({
|
||||
found: true,
|
||||
album: meta.album || undefined,
|
||||
year: meta.year || undefined,
|
||||
trackNum: meta.trackNum || undefined,
|
||||
totalTracks: meta.totalTracks || undefined,
|
||||
genre: meta.genre || undefined,
|
||||
coverUrl: meta.artworkUrl || undefined,
|
||||
artist: meta.itunesArtistName || undefined,
|
||||
});
|
||||
} catch (e) {
|
||||
console.error('[itunes/lookup]', e.message);
|
||||
res.status(500).json({ error: e.message });
|
||||
}
|
||||
});
|
||||
|
||||
// ─── ITUNES PROXY ─────────────────────────────────────────────────────────────
|
||||
// Browsers can't call itunes.apple.com directly (no CORS headers). Proxy it here.
|
||||
// Note: /api/itunes/lookup is handled above — proxy only covers /search and id-based /lookup.
|
||||
app.get('/api/itunes/:endpoint', (req, res) => {
|
||||
const allowed = new Set(['search', 'lookup']);
|
||||
if (!allowed.has(req.params.endpoint)) return res.status(404).json({ error: 'not found' });
|
||||
@@ -570,28 +594,6 @@ app.post('/api/soundcloud/resolve', async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
// ─── ITUNES LOOKUP ───────────────────────────────────────────────────────────
|
||||
app.get('/api/itunes/lookup', async (req, res) => {
|
||||
const { artist, title } = req.query;
|
||||
if (!artist || !title) return res.status(400).json({ error: 'artist and title required' });
|
||||
try {
|
||||
const meta = await lookupItunesTrackMeta(artist, title);
|
||||
if (!meta.album && !meta.genre && !meta.year) return res.json({ found: false });
|
||||
res.json({
|
||||
found: true,
|
||||
album: meta.album || undefined,
|
||||
year: meta.year || undefined,
|
||||
trackNum: meta.trackNum || undefined,
|
||||
totalTracks: meta.totalTracks || undefined,
|
||||
genre: meta.genre || undefined,
|
||||
coverUrl: meta.artworkUrl || undefined,
|
||||
artist: meta.itunesArtistName || undefined,
|
||||
});
|
||||
} catch (e) {
|
||||
console.error('[itunes/lookup]', e.message);
|
||||
res.status(500).json({ error: e.message });
|
||||
}
|
||||
});
|
||||
|
||||
// ─── MUSICBRAINZ LOOKUP ──────────────────────────────────────────────────────
|
||||
app.get('/api/musicbrainz/lookup', async (req, res) => {
|
||||
|
||||
Reference in new issue
Block a user