Manav Rathi 1 år sedan
förälder
incheckning
b32c13fe31
2 ändrade filer med 17 tillägg och 23 borttagningar
  1. 13 23
      web/apps/photos/src/services/download/index.ts
  2. 4 0
      web/packages/next/blob-cache.ts

+ 13 - 23
web/apps/photos/src/services/download/index.ts

@@ -154,30 +154,20 @@ class DownloadManagerImpl {
     };
 
     async getThumbnail(file: EnteFile, localOnly = false) {
-        try {
-            if (!this.ready) {
-                throw Error(CustomError.DOWNLOAD_MANAGER_NOT_READY);
-            }
-            const cachedThumb = await this.thumbnailCache.get(`${file.id}`);
-            if (cachedThumb) {
-                return new Uint8Array(await cachedThumb.arrayBuffer());
-            }
-            if (localOnly) {
-                return null;
-            }
-            const thumb = await this.downloadThumb(file);
-
-            this.thumbnailCache
-                ?.put(file.id.toString(), new Response(thumb))
-                .catch((e) => {
-                    log.error("thumb cache put failed", e);
-                    // TODO: handle storage full exception.
-                });
-            return thumb;
-        } catch (e) {
-            log.error("getThumbnail failed", e);
-            throw e;
+        if (!this.ready) {
+            throw Error(CustomError.DOWNLOAD_MANAGER_NOT_READY);
+        }
+        const key = `${file.id}`;
+        const cachedThumb = await this.thumbnailCache.get(key);
+        if (cachedThumb) {
+            return new Uint8Array(await cachedThumb.arrayBuffer());
+        }
+        if (localOnly) {
+            return null;
         }
+        const thumb = await this.downloadThumb(file);
+        this.thumbnailCache?.put2(key, new Blob([thumb]));
+        return thumb;
     }
 
     async getThumbnailForPreview(file: EnteFile, localOnly = false) {

+ 4 - 0
web/packages/next/blob-cache.ts

@@ -115,6 +115,10 @@ export const openCache = async (
  *
  *     await blob.arrayBuffer()
  *
+ * To convert from an ArrayBuffer or Uint8Array to Blob
+ *
+ *     new Blob([arrayBuffer, andOrAnyArray, andOrstring])
+ *
  * Refs:
  * - https://github.com/yigitunallar/arraybuffer-vs-blob
  * - https://stackoverflow.com/questions/11821096/what-is-the-difference-between-an-arraybuffer-and-a-blob