From 0317114879bc0fee44cb60ba5cfc4fd557848b95 Mon Sep 17 00:00:00 2001 From: Justin Wong <46082645+uvjustin@users.noreply.github.com> Date: Fri, 5 Aug 2022 02:22:14 +0800 Subject: [PATCH] Use base64 instead of blob URLs --- src/components/thumbnail.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/components/thumbnail.ts b/src/components/thumbnail.ts index b3763668..6c2b0172 100644 --- a/src/components/thumbnail.ts +++ b/src/components/thumbnail.ts @@ -54,10 +54,20 @@ export class FrigateCardThumbnailFeatureEvent extends LitElement { if (this.thumbnail?.startsWith('data:')) { return this.thumbnail; } - return await this.hass - .fetchWithAuth(thumbnail) - .then((response) => response.blob()) - .then((blob) => URL.createObjectURL(blob)); + return new Promise((resolve, reject) => { + //eslint-disable-next-line @typescript-eslint/no-non-null-assertion + this.hass!.fetchWithAuth(thumbnail) + .then((response) => response.blob()) + .then((blob) => { + const reader = new FileReader(); + reader.onload = () => { + const result = reader.result; + resolve(typeof result === 'string' ? result : null); + }; + reader.onerror = (e) => reject(e); + reader.readAsDataURL(blob); + }); + }); } protected render(): TemplateResult | void {