Skip to content
This repository has been archived by the owner on Aug 23, 2024. It is now read-only.

Remove custom image caching #192

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
20 changes: 2 additions & 18 deletions src/components/card/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ import { Icon } from 'rsuite';
import { useHistory } from 'react-router-dom';
import { useTranslation } from 'react-i18next';
import { LazyLoadImage } from 'react-lazy-load-image-component';
import cacheImage from '../shared/cacheImage';
import { useAppDispatch, useAppSelector } from '../../redux/hooks';
import {
appendPlayQueue,
clearPlayQueue,
fixPlayer2Index,
setPlayQueue,
} from '../../redux/playQueueSlice';
import { filterPlayQueue, getPlayedSongsNotification, isCached } from '../../shared/utils';
import { filterPlayQueue, getPlayedSongsNotification } from '../../shared/utils';

import {
CardPanel,
Expand Down Expand Up @@ -47,8 +46,6 @@ const Card = ({
lazyLoad,
playClick,
size,
cacheImages,
cachePath,
handleFavorite,
notVisibleByDefault,
noInfoPanel,
Expand Down Expand Up @@ -268,23 +265,10 @@ const Card = ({
<CardImgWrapper size={size} onClick={handleClick}>
{lazyLoad ? (
<LazyCardImg
src={
isCached(`${cachePath}${rest.details.cacheType}_${rest.details.id}.jpg`)
? `${cachePath}${rest.details.cacheType}_${rest.details.id}.jpg`
: rest.coverArt
}
src={rest.coverArt}
alt="img"
effect="opacity"
cardsize={size}
visibleByDefault={!notVisibleByDefault}
afterLoad={() => {
if (cacheImages) {
cacheImage(
`${rest.details.cacheType}_${rest.details.id}.jpg`,
rest.coverArt.replaceAll(/=150/gi, '=350')
);
}
}}
/>
) : (
<CardImg src={rest.coverArt} alt="img" onClick={handleClick} cardsize={size} />
Expand Down
20 changes: 6 additions & 14 deletions src/components/layout/GenericPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React, { useEffect, useState } from 'react';
import { Divider } from 'rsuite';
import { useAppSelector } from '../../redux/hooks';
import { PageContainer, PageHeader, PageContent } from './styled';
import { isCached } from '../../shared/utils';

const GenericPage = ({ header, children, hideDivider, ...rest }: any) => {
const playQueue = useAppSelector((state) => state.playQueue);
Expand All @@ -11,23 +10,16 @@ const GenericPage = ({ header, children, hideDivider, ...rest }: any) => {

useEffect(() => {
if (misc.dynamicBackground) {
const cachedImagePath = `${misc.imageCachePath}album_${playQueue.current?.albumId}.jpg`;
const serverImagePath = playQueue.current?.image.replace(/size=\d+/, 'size=500');
const cssBackgroundImagePath = `${misc.imageCachePath}album_${playQueue.current?.albumId}.jpg`.replaceAll(
'\\',
'/'
);
const preloadImage = new Image();
preloadImage.src = serverImagePath;
const imagePath = serverImagePath;

if (!isCached(cachedImagePath)) {
const preloadImage = new Image();
preloadImage.src = serverImagePath;
if (imagePath) {
setBackgroundImage(imagePath);
}

const imagePath = isCached(cachedImagePath) ? cssBackgroundImagePath : serverImagePath;

setBackgroundImage(imagePath);
}
}, [misc.imageCachePath, misc.dynamicBackground, playQueue]);
}, [misc.dynamicBackground, playQueue]);

return (
<PageContainer
Expand Down
10 changes: 0 additions & 10 deletions src/components/layout/GenericPageHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
PageHeaderTitle,
PageHeaderWrapper,
} from './styled';
import cacheImage from '../shared/cacheImage';
import CustomTooltip from '../shared/CustomTooltip';

const GenericPageHeader = ({
Expand All @@ -35,7 +34,6 @@ const GenericPageHeader = ({
handleListClick,
handleGridClick,
viewTypeSetting,
cacheImages,
showTitleTooltip,
isDark,
}: any) => {
Expand All @@ -54,14 +52,6 @@ const GenericPageHeader = ({
alt="header-img"
height={imageHeight || '195px'}
visibleByDefault
afterLoad={() => {
if (cacheImages.enabled) {
cacheImage(
`${cacheImages.cacheType}_${cacheImages.id}.jpg`,
image.replaceAll(/=150/gi, '=350')
);
}
}}
/>
)}
</CoverArtWrapper>
Expand Down
1 change: 1 addition & 0 deletions src/components/layout/styled.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ export const PageHeaderWrapper = styled.div<{
imageHeight: string;
isDark?: boolean;
}>`
user-select: none;
display: ${(props) => (props.hasImage ? 'inline-block' : 'undefined')};
width: ${(props) => (props.hasImage ? `calc(100% - ${props.imageHeight + 15}px)` : '100%')};
margin-left: ${(props) => (props.hasImage ? '15px' : '0px')};
Expand Down
5 changes: 0 additions & 5 deletions src/components/library/AlbumList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -451,11 +451,6 @@ const AlbumList = () => {
handleRowClick={handleRowClick}
handleRowDoubleClick={handleRowDoubleClick}
handleRating={handleRowRating}
cacheImages={{
enabled: settings.getSync('cacheImages'),
cacheType: 'album',
cacheIdProperty: 'albumId',
}}
page="albumListPage"
listType="album"
virtualized
Expand Down
25 changes: 2 additions & 23 deletions src/components/library/AlbumView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import {
formatDuration,
getAlbumSize,
getPlayedSongsNotification,
isCached,
} from '../../shared/utils';
import {
LinkWrapper,
Expand Down Expand Up @@ -298,13 +297,7 @@ const AlbumView = ({ ...rest }: any) => {
// which causes the background-image to flicker
expanded={misc.expandSidebar}
style={{
backgroundImage: `url(${
!data?.image.match('placeholder')
? isCached(`${misc.imageCachePath}album_${albumId}.jpg`)
? `${misc.imageCachePath}album_${albumId}.jpg`.replaceAll('\\', '/')
: data.image
: 'null'
})`,
backgroundImage: `url(${!data?.image.match('placeholder') ? data.image : 'null'})`,
}}
/>
</BlurredBackgroundWrapper>
Expand All @@ -319,11 +312,7 @@ const AlbumView = ({ ...rest }: any) => {
<Card
title="None"
subtitle=""
coverArt={
isCached(`${misc.imageCachePath}album_${albumId}.jpg`)
? `${misc.imageCachePath}album_${albumId}.jpg`
: data.image
}
coverArt={data.image}
size={200}
hasHoverButtons
noInfoPanel
Expand All @@ -334,11 +323,6 @@ const AlbumView = ({ ...rest }: any) => {
handleFavorite={handleFavorite}
/>
}
cacheImages={{
enabled: settings.getSync('cacheImages'),
cacheType: 'album',
id: data.albumId,
}}
imageHeight={200}
title={data.title}
showTitleTooltip
Expand Down Expand Up @@ -560,11 +544,6 @@ const AlbumView = ({ ...rest }: any) => {
virtualized
rowHeight={Number(settings.getSync('musicListRowHeight'))}
fontSize={Number(settings.getSync('musicListFontSize'))}
cacheImages={{
enabled: settings.getSync('cacheImages'),
cacheType: 'album',
cacheIdProperty: 'albumId',
}}
page="albumPage"
listType="music"
isModal={rest.isModal}
Expand Down
5 changes: 0 additions & 5 deletions src/components/library/ArtistList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,6 @@ const ArtistList = () => {
handleRowClick={handleRowClick}
handleRowDoubleClick={handleRowDoubleClick}
handleRating={handleRowRating}
cacheImages={{
enabled: settings.getSync('cacheImages'),
cacheType: 'artist',
cacheIdProperty: 'id',
}}
page="artistListPage"
listType="artist"
virtualized
Expand Down
40 changes: 5 additions & 35 deletions src/components/library/ArtistView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,7 @@ import {
setRate,
} from '../../redux/playQueueSlice';
import { notifyToast } from '../shared/toast';
import {
filterPlayQueue,
formatDuration,
getPlayedSongsNotification,
isCached,
} from '../../shared/utils';
import { filterPlayQueue, formatDuration, getPlayedSongsNotification } from '../../shared/utils';
import {
LinkWrapper,
SectionTitle,
Expand Down Expand Up @@ -467,9 +462,7 @@ const ArtistView = ({ ...rest }: any) => {

useEffect(() => {
if (!isLoading) {
const img = isCached(`${misc.imageCachePath}artist_${data?.id}.jpg`)
? `${misc.imageCachePath}artist_${data?.id}.jpg`
: data?.image?.includes('placeholder')
const img = data?.image?.includes('placeholder')
? data?.info?.imageUrl
? data?.info?.imageUrl
: data?.image
Expand Down Expand Up @@ -503,7 +496,7 @@ const ArtistView = ({ ...rest }: any) => {
};
setAvgColor(img);
}
}, [data?.id, data?.image, data?.info, isLoading, misc.imageCachePath]);
}, [data?.id, data?.image, data?.info, isLoading]);

useEffect(() => {
const allAlbumDurations = _.sum(_.map(data?.album, 'duration'));
Expand Down Expand Up @@ -545,9 +538,7 @@ const ArtistView = ({ ...rest }: any) => {
title={t('None')}
subtitle=""
coverArt={
isCached(`${misc.imageCachePath}artist_${data?.id}.jpg`)
? `${misc.imageCachePath}artist_${data?.id}.jpg`
: data?.image?.includes('placeholder')
data?.image?.includes('placeholder')
? data?.info?.imageUrl
? data?.info?.imageUrl
: data?.image
Expand All @@ -565,11 +556,6 @@ const ArtistView = ({ ...rest }: any) => {
handleFavorite={handleFavorite}
/>
}
cacheImages={{
enabled: settings.getSync('cacheImages'),
cacheType: 'artist',
id: data.id,
}}
imageHeight={
location.pathname.match('/songs|/albums|/compilationalbums|/topsongs') ? 180 : 225
}
Expand Down Expand Up @@ -751,7 +737,7 @@ const ArtistView = ({ ...rest }: any) => {
</StyledPopover>
}
>
<CustomTooltip text="{t('Info')}">
<CustomTooltip text={t('Info')}>
<StyledButton appearance="subtle" size="lg">
<Icon icon="info-circle" />
</StyledButton>
Expand All @@ -778,11 +764,6 @@ const ArtistView = ({ ...rest }: any) => {
virtualized
rowHeight={config.lookAndFeel.listView.music.rowHeight}
fontSize={config.lookAndFeel.listView.music.fontSize}
cacheImages={{
enabled: settings.getSync('cacheImages'),
cacheType: 'album',
cacheIdProperty: 'albumId',
}}
listType="music"
dnd
disabledContextMenuOptions={['deletePlaylist', 'viewInModal']}
Expand Down Expand Up @@ -810,11 +791,6 @@ const ArtistView = ({ ...rest }: any) => {
virtualized
rowHeight={config.lookAndFeel.listView.album.rowHeight}
fontSize={config.lookAndFeel.listView.album.fontSize}
cacheImages={{
enabled: settings.getSync('cacheImages'),
cacheType: 'album',
cacheIdProperty: 'albumId',
}}
page="artistPage"
listType="album"
isModal={rest.isModal}
Expand Down Expand Up @@ -863,11 +839,6 @@ const ArtistView = ({ ...rest }: any) => {
virtualized
rowHeight={config.lookAndFeel.listView.music.rowHeight}
fontSize={config.lookAndFeel.listView.music.fontSize}
cacheImages={{
enabled: settings.getSync('cacheImages'),
cacheType: 'album',
cacheIdProperty: 'albumId',
}}
listType="music"
dnd
disabledContextMenuOptions={['deletePlaylist', 'viewInModal']}
Expand Down Expand Up @@ -934,7 +905,6 @@ const ArtistView = ({ ...rest }: any) => {
rowHeight={config.lookAndFeel.listView.music.rowHeight}
fontSize={config.lookAndFeel.listView.music.fontSize}
listType="music"
cacheImages={{ enabled: false }}
isModal={false}
miniView={false}
handleFavorite={(rowData: any) =>
Expand Down
5 changes: 0 additions & 5 deletions src/components/library/FolderList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,6 @@ const FolderList = () => {
handleRowDoubleClick={handleRowDoubleClick}
handleFavorite={handleRowFavorite}
handleRating={handleRowRating}
cacheImages={{
enabled: settings.getSync('cacheImages'),
cacheType: 'folder',
cacheIdProperty: 'albumId',
}}
page="folderListPage"
listType="folder"
virtualized
Expand Down
6 changes: 0 additions & 6 deletions src/components/library/MusicList.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { useEffect, useRef, useState } from 'react';
import _ from 'lodash';
import settings from 'electron-settings';
import { ButtonToolbar } from 'rsuite';
import { useQuery, useQueryClient } from 'react-query';
import { useTranslation } from 'react-i18next';
Expand Down Expand Up @@ -313,11 +312,6 @@ const MusicList = () => {
handleRowClick={handleRowClick}
handleRowDoubleClick={handleRowDoubleClick}
handleRating={handleRowRating}
cacheImages={{
enabled: settings.getSync('cacheImages'),
cacheType: 'album',
cacheIdProperty: 'albumId',
}}
page="musicListPage"
listType="music"
virtualized
Expand Down
5 changes: 0 additions & 5 deletions src/components/player/NowPlayingMiniView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -506,11 +506,6 @@ const NowPlayingMiniView = () => {
virtualized
rowHeight={config.lookAndFeel.listView.mini.rowHeight}
fontSize={config.lookAndFeel.listView.mini.fontSize}
cacheImages={{
enabled: settings.getSync('cacheImages'),
cacheType: 'album',
cacheIdProperty: 'albumId',
}}
listType="music"
miniView
nowPlaying
Expand Down
5 changes: 0 additions & 5 deletions src/components/player/NowPlayingView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -535,11 +535,6 @@ const NowPlayingView = () => {
virtualized
rowHeight={config.lookAndFeel.listView.music.rowHeight}
fontSize={config.lookAndFeel.listView.music.fontSize}
cacheImages={{
enabled: settings.getSync('cacheImages'),
cacheType: 'album',
cacheIdProperty: 'albumId',
}}
listType="music"
nowPlaying
dnd
Expand Down
Loading