fix: handle iTunes rate-limit empty responses, reduce Spotify artwork concurrency
- itunesSearch: use r.text() + JSON.parse so empty body (rate-limit) returns [] instead of throwing - reduce Spotify artwork batch size 8→4 to avoid hammering iTunes and affecting global search Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
a61436669e
commit
2b6870583b
2 files changed
+7
-4
No files matched your search
+6
-3
@@ -43,9 +43,12 @@ export async function ndAuth() {
|
|||||||
const ITUNES = 'https://itunes.apple.com';
|
const ITUNES = 'https://itunes.apple.com';
|
||||||
|
|
||||||
export async function itunesSearch(query, entity='musicTrack', limit=25) {
|
export async function itunesSearch(query, entity='musicTrack', limit=25) {
|
||||||
const r = await fetch(`${ITUNES}/search?term=${encodeURIComponent(query)}&media=music&entity=${entity}&limit=${limit}&country=us&explicit=Yes`);
|
try {
|
||||||
const d = await r.json();
|
const r = await fetch(`${ITUNES}/search?term=${encodeURIComponent(query)}&media=music&entity=${entity}&limit=${limit}&country=us&explicit=Yes`);
|
||||||
return d.results || [];
|
const text = await r.text();
|
||||||
|
if (!text) return [];
|
||||||
|
return JSON.parse(text).results || [];
|
||||||
|
} catch { return []; }
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function itunesLookupAlbum(collectionId) {
|
export async function itunesLookupAlbum(collectionId) {
|
||||||
|
|||||||
+1
-1
@@ -172,7 +172,7 @@ async function _loadSpotifyTrackArtwork(tracks, listEl) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Enrich each track with iTunes data — same call as global search
|
// Enrich each track with iTunes data — same call as global search
|
||||||
const CONC = 8;
|
const CONC = 4;
|
||||||
for (let i = 0; i < tracks.length; i += CONC) {
|
for (let i = 0; i < tracks.length; i += CONC) {
|
||||||
const batch = tracks.slice(i, i + CONC);
|
const batch = tracks.slice(i, i + CONC);
|
||||||
await Promise.all(batch.map(async (t, bi) => {
|
await Promise.all(batch.map(async (t, bi) => {
|
||||||
|
|||||||
Reference in new issue
Block a user