Skip to content

armgit / ente

Public Imported from GitHub
0

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

Cleanup

Manav Rathi5082124aa51e
diff --git a/web/apps/photos/src/components/ml/PeopleList.tsx b/web/apps/photos/src/components/ml/PeopleList.tsx
index 54d2843f21..75748206bb 100644
--- a/web/apps/photos/src/components/ml/PeopleList.tsx
+++ b/web/apps/photos/src/components/ml/PeopleList.tsx
@@ -1,3 +1,4 @@
+import { cachedOrNew } from "@/next/blob-cache";
import { ensureLocalUser } from "@/next/local-user";
import log from "@/next/log";
import { Skeleton, styled } from "@mui/material";
diff --git a/web/apps/photos/src/services/download/index.ts b/web/apps/photos/src/services/download/index.ts
index fd1771aebf..124d5b4b24 100644
--- a/web/apps/photos/src/services/download/index.ts
+++ b/web/apps/photos/src/services/download/index.ts
@@ -135,21 +135,6 @@ class DownloadManagerImpl {
this.progressUpdater = progressUpdater;
}
- private async getCachedFile(file: EnteFile): Promise<Response> {
- const fileCache = this.fileCache;
- if (!fileCache) return null;
-
- try {
- const cacheResp: Response = await fileCache.match(
- file.id.toString(),
- );
- return cacheResp?.clone();
- } catch (e) {
- log.error("failed to get cached file", e);
- throw e;
- }
- }
-
private downloadThumb = async (file: EnteFile) => {
const encrypted = await this.downloadClient.downloadThumbnail(file);
const decrypted = await this.cryptoWorker.decryptThumbnail(
@@ -169,7 +154,7 @@ class DownloadManagerImpl {
if (localOnly) return null;
const thumb = await this.downloadThumb(file);
- this.thumbnailCache?.put2(key, new Blob([thumb]));
+ this.thumbnailCache?.put(key, new Blob([thumb]));
return thumb;
}
@@ -292,10 +277,7 @@ class DownloadManagerImpl {
onDownloadProgress,
);
encryptedArrayBuffer = array.buffer;
- this.fileCache?.put2(
- cacheKey,
- new Blob([encryptedArrayBuffer]),
- );
+ this.fileCache?.put(cacheKey, new Blob([encryptedArrayBuffer]));
}
this.clearDownloadProgress(file.id);
try {
@@ -321,7 +303,7 @@ class DownloadManagerImpl {
if (cachedBlob) res = new Response(cachedBlob);
else {
res = await this.downloadClient.downloadFileStream(file);
- this?.fileCache.put2(cacheKey, await res.blob());
+ this?.fileCache.put(cacheKey, await res.blob());
}
const reader = res.body.getReader();
diff --git a/web/apps/photos/src/utils/machineLearning/faceCrop.ts b/web/apps/photos/src/utils/machineLearning/faceCrop.ts
index 9d2c530b3e..74f25cac14 100644
--- a/web/apps/photos/src/utils/machineLearning/faceCrop.ts
+++ b/web/apps/photos/src/utils/machineLearning/faceCrop.ts
@@ -53,9 +53,8 @@ async function storeFaceCropForBlob(
faceCropBlob: Blob,
) {
const faceCropUrl = `/${faceId}`;
- const faceCropResponse = new Response(faceCropBlob);
const faceCropCache = await openCache("face-crops");
- await faceCropCache.put(faceCropUrl, faceCropResponse);
+ await faceCropCache.put(faceCropUrl, faceCropBlob);
return {
imageUrl: faceCropUrl,
imageBox: imageBox,
diff --git a/web/packages/next/blob-cache.ts b/web/packages/next/blob-cache.ts
index dfca8a80a4..cc94b93f83 100644
--- a/web/packages/next/blob-cache.ts
+++ b/web/packages/next/blob-cache.ts
@@ -58,12 +58,10 @@ export interface BlobCache {
* Get the data corresponding to {@link key} (if found) from the cache.
*/
get: (key: string) => Promise<Blob | undefined>;
- match: (key: string) => Promise<Response | undefined>;
/**
* Add the given {@link key}-value ({@link blob}) pair to the cache.
*/
- put2: (key: string, blob: Blob) => Promise<void>;
- put: (key: string, data: Response) => Promise<void>;
+ put: (key: string, blob: Blob) => Promise<void>;
/**
* Delete the blob corresponding to the given {@link key}.
*
@@ -133,13 +131,7 @@ const openWebCache = async (name: BlobCacheNamespace) => {
console.log("found cache hit", key, res);
return await res?.blob();
},
- match: (key: string) => {
- return cache.match(key);
- },
- put2: (key: string, blob: Blob) => cache.put(key, new Response(blob)),
- put: (key: string, data: Response) => {
- return cache.put(key, data);
- },
+ put: (key: string, blob: Blob) => cache.put(key, new Response(blob)),
delete: (key: string) => cache.delete(key),
};
};
@@ -154,17 +146,16 @@ const openOPFSCacheWeb = async (name: BlobCacheNamespace) => {
//
// So for our purpose, these can serve as the doc for what's available:
// https://web.dev/articles/origin-private-file-system
- const cache = await caches.open(name);
const root = await navigator.storage.getDirectory();
- const _caches = await root.getDirectoryHandle("cache", { create: true });
+ const caches = await root.getDirectoryHandle("cache", { create: true });
// eslint-disable-next-line @typescript-eslint/no-unused-vars
- const _cache = await _caches.getDirectoryHandle(name, { create: true });
+ const cache = await caches.getDirectoryHandle(name, { create: true });
return {
get: async (key: string) => {
try {
- const fileHandle = await _cache.getFileHandle(key);
+ const fileHandle = await cache.getFileHandle(key);
return await fileHandle.getFile();
} catch (e) {
if (e instanceof DOMException && e.name == "NotFoundError")
@@ -172,23 +163,17 @@ const openOPFSCacheWeb = async (name: BlobCacheNamespace) => {
throw e;
}
},
- match: (key: string) => {
- return cache.match(key);
- },
- put2: async (key: string, blob: Blob) => {
- const fileHandle = await _cache.getFileHandle(key, {
+ put: async (key: string, blob: Blob) => {
+ const fileHandle = await cache.getFileHandle(key, {
create: true,
});
const writable = await fileHandle.createWritable();
await writable.write(blob);
await writable.close();
},
- put: async (key: string, data: Response) => {
- await cache.put(key, data);
- },
delete: async (key: string) => {
try {
- await _cache.removeEntry(key);
+ await cache.removeEntry(key);
return true;
} catch (e) {
if (e instanceof DOMException && e.name == "NotFoundError")
@@ -214,7 +199,7 @@ export const cachedOrNew = async (
if (cachedBlob) return cachedBlob;
const blob = await get();
- await cache.put2(key, blob);
+ await cache.put(key, blob);
return blob;
};