thumb2
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user