[bugfix/feat]: always fetch artist image for Navidrome (#317)
* [bugfix/feat]: always fetch artist image for Navidrome * Add error fallback to library header image --------- Co-authored-by: jeffvli <jeffvictorli@gmail.com>
This commit is contained in:
parent
74cab01013
commit
452ef783f2
2 changed files with 19 additions and 7 deletions
|
@ -20,10 +20,6 @@ const getImageUrl = (args: { url: string | null }) => {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (url?.match('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9')) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return url;
|
return url;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -186,7 +182,16 @@ const normalizeAlbumArtist = (
|
||||||
},
|
},
|
||||||
server: ServerListItem | null,
|
server: ServerListItem | null,
|
||||||
): AlbumArtist => {
|
): 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 {
|
return {
|
||||||
albumCount: item.albumCount,
|
albumCount: item.albumCount,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { Group } from '@mantine/core';
|
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 { Link } from 'react-router-dom';
|
||||||
import styles from './library-header.module.scss';
|
import styles from './library-header.module.scss';
|
||||||
import { LibraryItem } from '/@/renderer/api/types';
|
import { LibraryItem } from '/@/renderer/api/types';
|
||||||
|
@ -20,6 +20,12 @@ export const LibraryHeader = forwardRef(
|
||||||
{ imageUrl, imagePlaceholderUrl, background, title, item, children }: LibraryHeaderProps,
|
{ imageUrl, imagePlaceholderUrl, background, title, item, children }: LibraryHeaderProps,
|
||||||
ref: Ref<HTMLDivElement>,
|
ref: Ref<HTMLDivElement>,
|
||||||
) => {
|
) => {
|
||||||
|
const [isImageError, setIsImageError] = useState<boolean | null>(false);
|
||||||
|
|
||||||
|
const onImageError = () => {
|
||||||
|
setIsImageError(true);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
ref={ref}
|
ref={ref}
|
||||||
|
@ -31,13 +37,14 @@ export const LibraryHeader = forwardRef(
|
||||||
/>
|
/>
|
||||||
<div className={styles.backgroundOverlay} />
|
<div className={styles.backgroundOverlay} />
|
||||||
<div className={styles.imageSection}>
|
<div className={styles.imageSection}>
|
||||||
{imageUrl ? (
|
{imageUrl && !isImageError ? (
|
||||||
<img
|
<img
|
||||||
alt="cover"
|
alt="cover"
|
||||||
className={styles.image}
|
className={styles.image}
|
||||||
placeholder={imagePlaceholderUrl || 'var(--placeholder-bg)'}
|
placeholder={imagePlaceholderUrl || 'var(--placeholder-bg)'}
|
||||||
src={imageUrl}
|
src={imageUrl}
|
||||||
style={{ height: '' }}
|
style={{ height: '' }}
|
||||||
|
onError={onImageError}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<ItemImagePlaceholder itemType={item.type} />
|
<ItemImagePlaceholder itemType={item.type} />
|
||||||
|
|
Reference in a new issue