Skip to content

Commit

Permalink
[bugfix/feat]: always fetch artist image for Navidrome (#317)
Browse files Browse the repository at this point in the history
* [bugfix/feat]: always fetch artist image for Navidrome

* Add error fallback to library header image

---------

Co-authored-by: jeffvli <[email protected]>
  • Loading branch information
kgarner7 and jeffvli authored Oct 22, 2023
1 parent 74cab01 commit 452ef78
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
15 changes: 10 additions & 5 deletions src/renderer/api/navidrome/navidrome-normalize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ const getImageUrl = (args: { url: string | null }) => {
return null;
}

if (url?.match('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9')) {
return null;
}

return url;
};

Expand Down Expand Up @@ -186,7 +182,16 @@ const normalizeAlbumArtist = (
},
server: ServerListItem | null,
): AlbumArtist => {
const imageUrl = getImageUrl({ url: item?.largeImageUrl || null });
let imageUrl = getImageUrl({ url: item?.largeImageUrl || null });

if (!imageUrl) {
imageUrl = getCoverArtUrl({
baseUrl: server?.url,
coverArtId: `ar-${item.id}`,
credential: server?.credential,
size: 100,
});
}

return {
albumCount: item.albumCount,
Expand Down
11 changes: 9 additions & 2 deletions src/renderer/features/shared/components/library-header.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Group } from '@mantine/core';
import { forwardRef, ReactNode, Ref } from 'react';
import { forwardRef, ReactNode, Ref, useState } from 'react';
import { Link } from 'react-router-dom';
import styles from './library-header.module.scss';
import { LibraryItem } from '/@/renderer/api/types';
Expand All @@ -20,6 +20,12 @@ export const LibraryHeader = forwardRef(
{ imageUrl, imagePlaceholderUrl, background, title, item, children }: LibraryHeaderProps,
ref: Ref<HTMLDivElement>,
) => {
const [isImageError, setIsImageError] = useState<boolean | null>(false);

const onImageError = () => {
setIsImageError(true);
};

return (
<div
ref={ref}
Expand All @@ -31,13 +37,14 @@ export const LibraryHeader = forwardRef(
/>
<div className={styles.backgroundOverlay} />
<div className={styles.imageSection}>
{imageUrl ? (
{imageUrl && !isImageError ? (
<img
alt="cover"
className={styles.image}
placeholder={imagePlaceholderUrl || 'var(--placeholder-bg)'}
src={imageUrl}
style={{ height: '' }}
onError={onImageError}
/>
) : (
<ItemImagePlaceholder itemType={item.type} />
Expand Down

1 comment on commit 452ef78

@vercel
Copy link

@vercel vercel bot commented on 452ef78 Oct 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

feishin – ./

feishin-git-development-jeffvli.vercel.app
feishin-jeffvli.vercel.app
feishin.vercel.app

Please sign in to comment.