Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LB-1103: Only show front cover art in ListenCards #3167

Merged
merged 1 commit into from
Feb 10, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions frontend/js/src/utils/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,8 @@ export type CAAThumbnailSizes = 250 | 500 | 1200 | "small" | "large";

const getThumbnailFromCAAResponse = (
body: CoverArtArchiveResponse,
size: CAAThumbnailSizes = 250
size: CAAThumbnailSizes = 250,
frontOnly = false
): string | undefined => {
if (!body.images?.length) {
return undefined;
Expand All @@ -735,6 +736,14 @@ const getThumbnailFromCAAResponse = (
const { id } = frontImage;
return generateAlbumArtThumbnailLink(id, releaseMBID);
}
if (frontImage) {
const { thumbnails, image } = frontImage;
return thumbnails[size] ?? thumbnails.small ?? image;
}
if (frontOnly) {
// We don't have a front image in the response, and are expecting a front image only, so return
return undefined;
}

// No front image? Fallback to whatever the first image is
const { thumbnails, image } = body.images[0];
Expand Down Expand Up @@ -772,7 +781,7 @@ const getAlbumArtFromReleaseGroupMBID = async (
);
if (CAAResponse.ok) {
const body: CoverArtArchiveResponse = await CAAResponse.json();
const coverArt = getThumbnailFromCAAResponse(body, optionalSize);
const coverArt = getThumbnailFromCAAResponse(body, optionalSize, true);
if (coverArt) {
// Cache the successful result
await setCoverArtCache(cacheKey, coverArt);
Expand All @@ -793,7 +802,8 @@ const getAlbumArtFromReleaseMBID = async (
userSubmittedReleaseMBID: string,
useReleaseGroupFallback: boolean | string = false,
APIService?: APIServiceClass,
optionalSize?: CAAThumbnailSizes
optionalSize?: CAAThumbnailSizes,
frontOnly?: boolean
): Promise<string | undefined> => {
try {
// Check cache first
Expand All @@ -809,15 +819,20 @@ const getAlbumArtFromReleaseMBID = async (
);
if (CAAResponse.ok) {
const body: CoverArtArchiveResponse = await CAAResponse.json();
const coverArt = getThumbnailFromCAAResponse(body, optionalSize);
const coverArt = getThumbnailFromCAAResponse(
body,
optionalSize,
frontOnly
);
// Here, make sure there is a front image, otherwise discard the hit.
if (coverArt) {
// Cache the successful result
await setCoverArtCache(cacheKey, coverArt);
}
return coverArt;
}

if (CAAResponse.status === 404 && useReleaseGroupFallback) {
if (useReleaseGroupFallback) {
let releaseGroupMBID = useReleaseGroupFallback;
if (!_.isString(useReleaseGroupFallback) && APIService) {
const releaseGroupResponse = (await APIService.lookupMBRelease(
Expand Down Expand Up @@ -933,7 +948,9 @@ const getAlbumArtFromListenMetadata = async (
const userSubmittedReleaseAlbumArt = await getAlbumArtFromReleaseMBID(
userSubmittedReleaseMBID,
Boolean(caaReleaseMbid) && userSubmittedReleaseMBID !== caaReleaseMbid,
APIService
APIService,
undefined,
true // we only want front images, otherwise skip
);
if (userSubmittedReleaseAlbumArt) {
return userSubmittedReleaseAlbumArt;
Expand Down