mirror of
https://github.com/ente-io/ente.git
synced 2025-08-14 10:16:10 +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 {
|
export enum CACHES {
|
||||||
THUMBS = "thumbs",
|
THUMBS = "thumbs",
|
||||||
FACE_CROPS = "face-crops",
|
FACE_CROPS = "face-crops",
|
||||||
@@ -7,7 +5,7 @@ export enum CACHES {
|
|||||||
FILES = "files",
|
FILES = "files",
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface LimitedCacheStorage {
|
interface LimitedCacheStorage {
|
||||||
open: (
|
open: (
|
||||||
cacheName: string,
|
cacheName: string,
|
||||||
cacheLimitInBytes?: number,
|
cacheLimitInBytes?: number,
|
||||||
@@ -26,62 +24,33 @@ export interface LimitedCache {
|
|||||||
|
|
||||||
class cacheStorageFactory {
|
class cacheStorageFactory {
|
||||||
getCacheStorage(): LimitedCacheStorage {
|
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();
|
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) {
|
async function openCache(cacheName: string, cacheLimit?: number) {
|
||||||
try {
|
return await CacheStorageFactory.getCacheStorage().open(
|
||||||
return await CacheStorageFactory.getCacheStorage().open(
|
cacheName,
|
||||||
cacheName,
|
cacheLimit,
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
async function deleteCache(cacheName: string) {
|
async function deleteCache(cacheName: string) {
|
||||||
try {
|
return await CacheStorageFactory.getCacheStorage().delete(cacheName);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const CacheStorageService = { open: openCache, delete: deleteCache };
|
export const CacheStorageService = { open: openCache, delete: deleteCache };
|
||||||
|
Reference in New Issue
Block a user