X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Froot-helpers%2Fpeertube-web-storage.ts;h=d4cad8a20aa74f6c25ab24ede76117292c590691;hb=8d64a72b4cbd12b01ad4c689f210d219dd91fde3;hp=0db1301bd4fa4846b1e6d3096e0417d49849c527;hpb=4504f09f6e85f09b0489debb547a17209d7176ea;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/root-helpers/peertube-web-storage.ts b/client/src/root-helpers/peertube-web-storage.ts index 0db1301bd..d4cad8a20 100644 --- a/client/src/root-helpers/peertube-web-storage.ts +++ b/client/src/root-helpers/peertube-web-storage.ts @@ -4,17 +4,19 @@ const valuesMap = new Map() function proxify (instance: MemoryStorage) { return new Proxy(instance, { - set: function (obj, prop: string | number, value) { + set: function (obj, prop: string | symbol, value) { if (MemoryStorage.prototype.hasOwnProperty(prop)) { - instance[prop] = value + // FIXME: symbol typing issue https://github.com/microsoft/TypeScript/issues/1863 + instance[prop as any] = value } else { instance.setItem(prop, value) } return true }, - get: function (target, name: string | number) { + get: function (target, name: string | symbol | number) { if (MemoryStorage.prototype.hasOwnProperty(name)) { - return instance[name] + // FIXME: symbol typing issue https://github.com/microsoft/TypeScript/issues/1863 + return instance[name as any] } if (valuesMap.has(name)) { return instance.getItem(name) @@ -23,9 +25,8 @@ function proxify (instance: MemoryStorage) { }) } -class MemoryStorage { +class MemoryStorage implements Storage { [key: string]: any - [index: number]: string getItem (key: any) { const stringKey = String(key) @@ -64,10 +65,8 @@ class MemoryStorage { let peertubeLocalStorage: Storage let peertubeSessionStorage: Storage -try { - peertubeLocalStorage = localStorage - peertubeSessionStorage = sessionStorage -} catch (err) { + +function reinitStorage () { const instanceLocalStorage = new MemoryStorage() const instanceSessionStorage = new MemoryStorage() @@ -75,6 +74,19 @@ try { peertubeSessionStorage = proxify(instanceSessionStorage) } +try { + peertubeLocalStorage = localStorage + peertubeSessionStorage = sessionStorage +} catch (err) { + // support Firefox and other browsers using an exception rather than null + reinitStorage() +} + +// support Brave and other browsers using null rather than an exception +if (peertubeLocalStorage === null || peertubeSessionStorage === null) { + reinitStorage() +} + export { peertubeLocalStorage, peertubeSessionStorage