mirror of
https://github.com/ente-io/ente.git
synced 2025-08-13 17:57:31 +00:00
Remove firefox specific workaround
In a quick (but possibly incomplete) test I wasn't able to reproduce this in an incognito window. Throwing the error from here has a potential for breaking things though, I'll try to verify this as I go through the flows individually.
This commit is contained in:
@@ -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 };
|
||||
|
Reference in New Issue
Block a user