Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

thumb2

Manav Rathib32c13fe313c
diff --git a/web/apps/photos/src/services/download/index.ts b/web/apps/photos/src/services/download/index.ts
index 98540ddb6e..d64f158a7d 100644
--- a/web/apps/photos/src/services/download/index.ts
+++ b/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) {
diff --git a/web/packages/next/blob-cache.ts b/web/packages/next/blob-cache.ts
index 0e155c83ee..dfca8a80a4 100644
--- a/web/packages/next/blob-cache.ts
+++ b/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