This commit is contained in:
Manav Rathi
2024-04-13 08:48:39 +05:30
parent c52fd4383c
commit b32c13fe31
2 changed files with 17 additions and 23 deletions

View File

@@ -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) {

View File

@@ -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