fix lots of images not showing up

This commit is contained in:
Violet Caulfield
2026-02-20 09:56:52 -06:00
parent 6ca7e18e40
commit f9f6de4100
2 changed files with 47 additions and 1 deletions

View File

@@ -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,
})
})
})
})

View File

@@ -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