Fix a gap under Friends listening, and lyrics failing while LRCLIB's exact lookup is overloaded
The feed's itemLayoutAnimation left the cards behind when the header above them shrank (your own card's lyrics loading). LRCLIB rate-limits /api/get on its own; fall back to search. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011Y2iUsKEWDuRGjK5FPmcUP
This commit is contained in:
@@ -65,10 +65,8 @@ async function lookup(track: { title: string; artist: string; album: string | nu
|
||||
if (track.durationMs) {
|
||||
const params = new URLSearchParams({ track_name: track.title, artist_name: artist, duration: String(Math.round(track.durationMs / 1000)) });
|
||||
if (track.album) params.set('album_name', track.album);
|
||||
const exact = await fetchJson<LrclibRecord>(`${env.LRCLIB_URL}/api/get?${params}`, { headers }).catch((e: unknown) => {
|
||||
if (e instanceof HttpError && e.status === 404) return null;
|
||||
throw e;
|
||||
});
|
||||
// Not found, or LRCLIB's exact lookup is overloaded (it rate-limits /api/get separately): try the search.
|
||||
const exact = await fetchJson<LrclibRecord>(`${env.LRCLIB_URL}/api/get?${params}`, { headers }).catch(() => null);
|
||||
if (exact) return exact;
|
||||
}
|
||||
const params = new URLSearchParams({ track_name: track.title, artist_name: artist });
|
||||
|
||||
@@ -55,6 +55,20 @@ describe('lyrics', () => {
|
||||
expect(body.plain).toBe('the one');
|
||||
});
|
||||
|
||||
it("uses the search when LRCLIB's exact lookup is rate-limited", async () => {
|
||||
const { id } = await upsertTrack({ title: 'Midnight City', artist: 'M83', durationMs: 241_000 });
|
||||
vi.stubGlobal(
|
||||
'fetch',
|
||||
routeFetch([
|
||||
[/\/api\/get\?/, () => json({ message: 'slow down' }, 429)],
|
||||
[/\/api\/search\?/, () => json([record()])],
|
||||
]),
|
||||
);
|
||||
const res = await lyrics(id);
|
||||
expect(res.statusCode).toBe(200);
|
||||
expect(res.json().synced).toHaveLength(2);
|
||||
});
|
||||
|
||||
it('returns null when nothing matches, and 503 when LRCLIB is down', async () => {
|
||||
const { id } = await upsertTrack({ title: 'Unknown', artist: 'Nobody', durationMs: 100_000 });
|
||||
vi.stubGlobal('fetch', routeFetch([[/lrclib/, () => json({ message: 'down' }, 500)]]));
|
||||
|
||||
Reference in New Issue
Block a user