From f9f6de41007c040b00a47af0ab09c2c6eda208f5 Mon Sep 17 00:00:00 2001 From: Violet Caulfield <42452695+anultravioletaurora@users.noreply.github.com> Date: Fri, 20 Feb 2026 09:56:52 -0600 Subject: [PATCH] fix lots of images not showing up --- jest/functional/getItemImageUrl.test.ts | 41 +++++++++++++++++++++++++ src/api/queries/image/utils/index.ts | 7 ++++- 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/jest/functional/getItemImageUrl.test.ts b/jest/functional/getItemImageUrl.test.ts index 7d55a17b..64fdab64 100644 --- a/jest/functional/getItemImageUrl.test.ts +++ b/jest/functional/getItemImageUrl.test.ts @@ -426,4 +426,45 @@ describe('getItemImageUrl', () => { }) }) }) + + describe('fallback - item own ID', () => { + it('should use item ID as last resort when no image tags, album, or artists exist', () => { + const mockItem: BaseItemDto = { + Id: 'item-1', + Name: 'Test Track', + Type: 'Audio', + // No ImageTags, no AlbumId, no AlbumArtists, no ArtistItems + } + + const result = getItemImageUrl(mockItem, ImageType.Primary) + + expect(result).toBe('http://example.com/image.jpg') + expect(mockGetItemImageUrlById).toHaveBeenCalledWith('item-1', ImageType.Primary, { + tag: undefined, + maxWidth: 200, + maxHeight: 200, + quality: 90, + }) + }) + + it('should use item ID as last resort when album has no tag and no artists exist', () => { + const mockItem: BaseItemDto = { + Id: 'item-1', + Name: 'Test Track', + Type: 'Audio', + AlbumId: 'album-1', + // No AlbumPrimaryImageTag, so album fallback won't trigger + } + + const result = getItemImageUrl(mockItem, ImageType.Primary) + + expect(result).toBe('http://example.com/image.jpg') + expect(mockGetItemImageUrlById).toHaveBeenCalledWith('item-1', ImageType.Primary, { + tag: undefined, + maxWidth: 200, + maxHeight: 200, + quality: 90, + }) + }) + }) }) diff --git a/src/api/queries/image/utils/index.ts b/src/api/queries/image/utils/index.ts index 1cfcbed1..a8db694f 100644 --- a/src/api/queries/image/utils/index.ts +++ b/src/api/queries/image/utils/index.ts @@ -50,7 +50,7 @@ export function getItemImageUrl( ...imageParams, tag: AlbumPrimaryImageTag ?? undefined, }) - } else { + } else if (AlbumArtists?.[0]?.Id || ArtistItems?.[0]?.Id) { // Fall back to first artist's image (AlbumArtists or ArtistItems for slimified tracks) const artistId = AlbumArtists?.[0]?.Id ?? ArtistItems?.[0]?.Id if (artistId) { @@ -58,6 +58,11 @@ export function getItemImageUrl( ...imageParams, }) } + } else if (Id) { + // Last ditch effort: use the item's own ID without a specific type tag + imageUrl = getImageApi(api).getItemImageUrlById(Id, type, { + ...imageParams, + }) } return imageUrl