Skip to content

armgit / ente

Public Imported from GitHub
0

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

Remove firefox specific workaround

Manav Rathibdadc839e008
diff --git a/web/packages/shared/storage/cache.ts b/web/packages/shared/storage/cache.ts
index 035d029c1d..3b585116e2 100644
--- a/web/packages/shared/storage/cache.ts
+++ b/web/packages/shared/storage/cache.ts
@@ -1,5 +1,3 @@
-import log from "@/next/log";
-
export enum CACHES {
THUMBS = "thumbs",
FACE_CROPS = "face-crops",
@@ -7,7 +5,7 @@ export enum CACHES {
FILES = "files",
}
-export interface LimitedCacheStorage {
+interface LimitedCacheStorage {
open: (
cacheName: string,
cacheLimitInBytes?: number,
@@ -26,62 +24,33 @@ export interface LimitedCache {
class cacheStorageFactory {
getCacheStorage(): LimitedCacheStorage {
- return transformBrowserCacheStorageToLimitedCacheStorage(caches);
+ return {
+ async open(cacheName) {
+ const cache = await caches.open(cacheName);
+ return {
+ match: (key) => {
+ // options are not supported in the browser
+ return cache.match(key);
+ },
+ put: cache.put.bind(cache),
+ delete: cache.delete.bind(cache),
+ };
+ },
+ delete: caches.delete.bind(caches),
+ };
}
}
export const CacheStorageFactory = new cacheStorageFactory();
-function transformBrowserCacheStorageToLimitedCacheStorage(
- caches: CacheStorage,
-): LimitedCacheStorage {
- return {
- async open(cacheName) {
- const cache = await caches.open(cacheName);
- return {
- match: (key) => {
- // options are not supported in the browser
- return cache.match(key);
- },
- put: cache.put.bind(cache),
- delete: cache.delete.bind(cache),
- };
- },
- delete: caches.delete.bind(caches),
- };
-}
-
-const SecurityError = "SecurityError";
-const INSECURE_OPERATION = "The operation is insecure.";
-
async function openCache(cacheName: string, cacheLimit?: number) {
- try {
- return await CacheStorageFactory.getCacheStorage().open(
- cacheName,
- cacheLimit,
- );
- } catch (e) {
- // ignoring insecure operation error, as it is thrown in incognito mode in firefox
- if (e.name === SecurityError && e.message === INSECURE_OPERATION) {
- // no-op
- } else {
- // log and ignore, we don't want to break the caller flow, when cache is not available
- log.error("openCache failed", e);
- }
- }
+ return await CacheStorageFactory.getCacheStorage().open(
+ cacheName,
+ cacheLimit,
+ );
}
async function deleteCache(cacheName: string) {
- try {
- return await CacheStorageFactory.getCacheStorage().delete(cacheName);
- } catch (e) {
- // ignoring insecure operation error, as it is thrown in incognito mode in firefox
- if (e.name === SecurityError && e.message === INSECURE_OPERATION) {
- // no-op
- } else {
- // log and ignore, we don't want to break the caller flow, when cache is not available
- log.error("deleteCache failed", e);
- }
- }
+ return await CacheStorageFactory.getCacheStorage().delete(cacheName);
}
export const CacheStorageService = { open: openCache, delete: deleteCache };