Skip to content

armgit / ente

Public Imported from GitHub
0

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

Remove indirection

Manav Rathia56cf55ffa73
diff --git a/web/apps/photos/src/services/download/index.ts b/web/apps/photos/src/services/download/index.ts
index e654078057..79fff4da90 100644
--- a/web/apps/photos/src/services/download/index.ts
+++ b/web/apps/photos/src/services/download/index.ts
@@ -1,4 +1,4 @@
-import { CacheStorageService, type EnteCache } from "@/next/cache";
+import { openCache, type EnteCache } from "@/next/cache";
import log from "@/next/log";
import { APPS } from "@ente/shared/apps/constants";
import ComlinkCryptoWorker from "@ente/shared/crypto";
@@ -513,7 +513,7 @@ export default DownloadManager;
async function openThumbnailCache() {
try {
- return await CacheStorageService.open("thumbs");
+ return await openCache("thumbs");
} catch (e) {
log.error("Failed to open thumbnail cache", e);
if (isInternalUser()) {
@@ -529,7 +529,7 @@ async function openDiskFileCache() {
if (!isElectron()) {
throw Error(CustomError.NOT_AVAILABLE_ON_WEB);
}
- return await CacheStorageService.open("files");
+ return await openCache("files");
} catch (e) {
log.error("Failed to open file cache", e);
if (isInternalUser()) {
diff --git a/web/apps/photos/src/utils/machineLearning/faceCrop.ts b/web/apps/photos/src/utils/machineLearning/faceCrop.ts
index 86f9bae979..f96e43ce8b 100644
--- a/web/apps/photos/src/utils/machineLearning/faceCrop.ts
+++ b/web/apps/photos/src/utils/machineLearning/faceCrop.ts
@@ -1,4 +1,4 @@
-import { CacheStorageService } from "@/next/cache";
+import { openCache } from "@/next/cache";
import { BlobOptions } from "types/image";
import {
FaceAlignment,
@@ -54,7 +54,7 @@ async function storeFaceCropForBlob(
) {
const faceCropUrl = `/${faceId}`;
const faceCropResponse = new Response(faceCropBlob);
- const faceCropCache = await CacheStorageService.open("face-crops");
+ const faceCropCache = await openCache("face-crops");
await faceCropCache.put(faceCropUrl, faceCropResponse);
return {
imageUrl: faceCropUrl,
diff --git a/web/packages/next/cache.ts b/web/packages/next/cache.ts
index 840f941753..c33e54e668 100644
--- a/web/packages/next/cache.ts
+++ b/web/packages/next/cache.ts
@@ -76,7 +76,7 @@ export interface EnteCache {
* {@link CacheName} which group related data and allow us to use the same key
* across namespaces.
*/
-const openCache = async (name: CacheName) =>
+export const openCache = async (name: CacheName) =>
globalThis.electron ? openWebCache(name) : openOPFSCacheWeb(name);
/** An implementation of {@link EnteCache} using Web Cache APIs */
@@ -111,14 +111,12 @@ const openOPFSCacheWeb = async (name: CacheName) => {
};
};
-export const CacheStorageService = { open: openCache };
-
export async function cached(
cacheName: CacheName,
id: string,
get: () => Promise<Blob>,
): Promise<Blob> {
- const cache = await CacheStorageService.open(cacheName);
+ const cache = await openCache(cacheName);
const cacheResponse = await cache.match(id);
let result: Blob;