diff options
-rw-r--r-- | client/src/app/shared/misc/peertube-web-storage.ts | 42 |
1 files changed, 24 insertions, 18 deletions
diff --git a/client/src/app/shared/misc/peertube-web-storage.ts b/client/src/app/shared/misc/peertube-web-storage.ts index fff209678..6a152dd98 100644 --- a/client/src/app/shared/misc/peertube-web-storage.ts +++ b/client/src/app/shared/misc/peertube-web-storage.ts | |||
@@ -47,26 +47,32 @@ try { | |||
47 | peertubeLocalStorage = localStorage | 47 | peertubeLocalStorage = localStorage |
48 | peertubeSessionStorage = sessionStorage | 48 | peertubeSessionStorage = sessionStorage |
49 | } catch (err) { | 49 | } catch (err) { |
50 | const instance = new MemoryStorage() | 50 | const instanceLocalStorage = new MemoryStorage() |
51 | const instanceSessionStorage = new MemoryStorage() | ||
51 | 52 | ||
52 | peertubeLocalStorage = sessionStorage = new Proxy(instance, { | 53 | function proxify (instance: MemoryStorage) { |
53 | set: function (obj, prop: string | number, value) { | 54 | return new Proxy(instance, { |
54 | if (MemoryStorage.prototype.hasOwnProperty(prop)) { | 55 | set: function (obj, prop: string | number, value) { |
55 | instance[prop] = value | 56 | if (MemoryStorage.prototype.hasOwnProperty(prop)) { |
56 | } else { | 57 | instance[prop] = value |
57 | instance.setItem(prop, value) | 58 | } else { |
59 | instance.setItem(prop, value) | ||
60 | } | ||
61 | return true | ||
62 | }, | ||
63 | get: function (target, name: string | number) { | ||
64 | if (MemoryStorage.prototype.hasOwnProperty(name)) { | ||
65 | return instance[name] | ||
66 | } | ||
67 | if (valuesMap.has(name)) { | ||
68 | return instance.getItem(name) | ||
69 | } | ||
58 | } | 70 | } |
59 | return true | 71 | }) |
60 | }, | 72 | } |
61 | get: function (target, name: string | number) { | 73 | |
62 | if (MemoryStorage.prototype.hasOwnProperty(name)) { | 74 | peertubeLocalStorage = proxify(instanceLocalStorage) |
63 | return instance[name] | 75 | peertubeSessionStorage = proxify(instanceSessionStorage) |
64 | } | ||
65 | if (valuesMap.has(name)) { | ||
66 | return instance.getItem(name) | ||
67 | } | ||
68 | } | ||
69 | }) | ||
70 | } | 76 | } |
71 | 77 | ||
72 | export { | 78 | export { |