From f6d02d8fc6693ea3a256f51bfccb4eb796585cda Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 22 Aug 2021 12:17:48 -0500 Subject: [PATCH] Cache the camera url without the width and height added (#9778) --- src/data/camera.ts | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/src/data/camera.ts b/src/data/camera.ts index 0927e50e53..945fe474f9 100644 --- a/src/data/camera.ts +++ b/src/data/camera.ts @@ -36,30 +36,28 @@ export interface Stream { export const computeMJPEGStreamUrl = (entity: CameraEntity) => `/api/camera_proxy_stream/${entity.entity_id}?token=${entity.attributes.access_token}`; -export const fetchThumbnailUrlWithCache = ( - hass: HomeAssistant, - entityId: string, - width: number, - height: number -) => - timeCachePromiseFunc( - "_cameraTmbUrl", - 9000, - fetchThumbnailUrl, - hass, - entityId, - width, - height - ); - -export const fetchThumbnailUrl = async ( +export const fetchThumbnailUrlWithCache = async ( hass: HomeAssistant, entityId: string, width: number, height: number +) => { + const base_url = await timeCachePromiseFunc( + "_cameraTmbUrl", + 9000, + fetchThumbnailUrl, + hass, + entityId + ); + return `${base_url}&width=${width}&height=${height}`; +}; + +export const fetchThumbnailUrl = async ( + hass: HomeAssistant, + entityId: string ) => { const path = await getSignedPath(hass, `/api/camera_proxy/${entityId}`); - return hass.hassUrl(`${path.path}&width=${width}&height=${height}`); + return hass.hassUrl(path.path); }; export const fetchStreamUrl = async (