From daac41b15479852493758943e19ab886a0d3229e Mon Sep 17 00:00:00 2001 From: Ncbudd <209378361+ncbudd@users.noreply.github.com> Date: Tue, 24 Nov 2026 12:22:14 -0500 Subject: [PATCH] [SeerrNG #724] fix(lumen): fetch the poster for a recent title saved without one --- lumen/src/recentMedia.ts | 13 ++++++----- lumen/tests/recentMedia.test.mjs | 38 +++++++++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 6 deletions(-) diff --git a/lumen/src/recentMedia.ts b/lumen/src/recentMedia.ts index a43ac63..ee59140 100644 --- a/lumen/src/recentMedia.ts +++ b/lumen/src/recentMedia.ts @@ -35,8 +35,9 @@ export function recentMediaTitles(rows: MediaRow[]): RecentMediaTitle[] { })); } // Some recent-view-only accounts receive a deliberately limited /media projection -// without catalog titles. Reuse the existing authorized detail endpoint only -// for those rows; a failed lookup must never erase the entire recent card. +// without catalog titles, and a title saved before TMDB had a poster keeps no +// poster in the list. Reuse the existing authorized detail endpoint only for +// those rows; a failed lookup must never erase the entire recent card. export async function enrichRecentMediaTitles( cards: RecentMediaTitle[], lookup: (card: RecentMediaTitle) => Promise @@ -47,7 +48,7 @@ export async function enrichRecentMediaTitles( card.mediaType === 'movie' ? card.title === 'Untitled movie' : card.name === 'Untitled series'; - if (!missingName) return card; + if (!missingName && card.posterPath) return card; try { const detail = await lookup(card); const resolvedTitle = detail.title || detail.name; @@ -55,10 +56,12 @@ export async function enrichRecentMediaTitles( ...card, title: card.mediaType === 'movie' - ? resolvedTitle || card.title + ? (missingName && resolvedTitle) || card.title : undefined, name: - card.mediaType === 'tv' ? resolvedTitle || card.name : undefined, + card.mediaType === 'tv' + ? (missingName && resolvedTitle) || card.name + : undefined, posterPath: card.posterPath || detail.posterPath, releaseDate: card.releaseDate || detail.releaseDate, firstAirDate: card.firstAirDate || detail.firstAirDate, diff --git a/lumen/tests/recentMedia.test.mjs b/lumen/tests/recentMedia.test.mjs index 8b4e753..b98a357 100644 --- a/lumen/tests/recentMedia.test.mjs +++ b/lumen/tests/recentMedia.test.mjs @@ -69,6 +69,7 @@ test('complete catalog rows need no extra detail requests', async () => { mediaType: i % 2 ? 'tv' : 'movie', status: 5, title: `Title ${i}`, + posterPath: `/poster/${i}.jpg`, })); let lookups = 0; const titles = await enrichRecentMediaTitles( @@ -86,7 +87,13 @@ test('missing restricted-view titles are enriched where permitted, not discarded const cards = recentMediaTitles([ { tmdbId: 51, mediaType: 'movie', status: 5 }, { tmdbId: 52, mediaType: 'tv', status: 5 }, - { tmdbId: 53, mediaType: 'movie', status: 5, title: 'Already provided' }, + { + tmdbId: 53, + mediaType: 'movie', + status: 5, + title: 'Already provided', + posterPath: '/b.jpg', + }, ]); const calls = []; const result = await enrichRecentMediaTitles(cards, async (item) => { @@ -107,3 +114,32 @@ test('missing restricted-view titles are enriched where permitted, not discarded assert.equal(result[2].title, 'Already provided'); assert.equal(result.length, 3); }); + +test('a titled card without a poster takes the poster from the title, and keeps its own title', async () => { + const cards = recentMediaTitles([ + { tmdbId: 61, mediaType: 'movie', status: 5, title: 'Fjord' }, + { tmdbId: 62, mediaType: 'tv', status: 5, title: 'Show' }, + { tmdbId: 63, mediaType: 'movie', status: 5, title: 'Lookup fails' }, + ]); + const calls = []; + const result = await enrichRecentMediaTitles(cards, async (item) => { + calls.push(item.id); + if (item.id === 63) throw Error('Detail endpoint unavailable'); + return { + id: item.id, + mediaType: item.mediaType, + title: 'Other title', + name: 'Other name', + posterPath: `/${item.id}.jpg`, + }; + }); + assert.deepEqual(calls, [61, 62, 63]); + assert.deepEqual( + result.map((r) => [r.title ?? r.name, r.posterPath]), + [ + ['Fjord', '/61.jpg'], + ['Show', '/62.jpg'], + ['Lookup fails', undefined], + ] + ); +});