Skip to content

Commit 990e97e

Browse files
committed
fix(media): fallback to signed artwork urls in production
1 parent e5f7799 commit 990e97e

2 files changed

Lines changed: 27 additions & 2 deletions

File tree

src/app/features/media/components/media-card/use-media-card-controller.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { homeAssistantService } from '@/app/services/home-assistant.service';
77
import { homeAssistantSelectors } from '@/app/stores/selectors';
88
import {
99
isHomeAssistantProxyUrl,
10+
resolveHomeAssistantAbsoluteUrl,
1011
resolveHomeAssistantProxyUrl,
1112
} from '@/app/utils/home-assistant-url';
1213

@@ -106,6 +107,14 @@ export function useMediaCardController({
106107
return normalizedArtworkUrl;
107108
}, [authConfig, entityPicture, failedArtworkUrl]);
108109

110+
const directAlbumArt = useMemo(() => {
111+
if (!entityPicture) {
112+
return null;
113+
}
114+
115+
return resolveHomeAssistantAbsoluteUrl(entityPicture, authConfig?.url);
116+
}, [authConfig?.url, entityPicture]);
117+
109118
useEffect(() => {
110119
if (!albumArt) {
111120
if (objectUrlRef.current) {
@@ -157,7 +166,7 @@ export function useMediaCardController({
157166

158167
if (shouldAvoidProxyFallback) {
159168
if (!cancelled) {
160-
setResolvedAlbumArt(null);
169+
setResolvedAlbumArt(directAlbumArt);
161170
}
162171
return;
163172
}
@@ -200,7 +209,7 @@ export function useMediaCardController({
200209
cancelled = true;
201210
controller.abort();
202211
};
203-
}, [albumArt, authConfig?.token, authConfig?.url, connection, entityId]);
212+
}, [albumArt, authConfig?.token, authConfig?.url, connection, directAlbumArt, entityId]);
204213

205214
useEffect(() => {
206215
if (previousEntityPictureRef.current !== entityPicture) {

src/app/utils/home-assistant-url.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,22 @@ function isAbsoluteHttpUrl(value: string) {
44
return value.startsWith('http://') || value.startsWith('https://');
55
}
66

7+
export function resolveHomeAssistantAbsoluteUrl(resourceUrl: string, hassUrl?: string) {
8+
if (!resourceUrl) {
9+
return null;
10+
}
11+
12+
if (resourceUrl.startsWith('blob:') || resourceUrl.startsWith('data:')) {
13+
return resourceUrl;
14+
}
15+
16+
if (resourceUrl.startsWith('/')) {
17+
return hassUrl ? `${hassUrl}${resourceUrl}` : resourceUrl;
18+
}
19+
20+
return resourceUrl;
21+
}
22+
723
export function resolveHomeAssistantProxyUrl(resourceUrl: string, hassUrl?: string) {
824
if (!resourceUrl) {
925
return null;

0 commit comments

Comments
 (0)