aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/root-helpers
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-10-08 11:57:39 +0200
committerChocobozzz <me@florianbigard.com>2021-10-11 09:37:26 +0200
commitdb9df9a72c67a6ba150620f0f1c0838a3c155786 (patch)
tree66563a6d8053a46a14a4be46efa7fbf6a82bb96b /client/src/root-helpers
parente0b1231b2075e81afe06c2df4fdf55e148f05f3a (diff)
downloadPeerTube-db9df9a72c67a6ba150620f0f1c0838a3c155786.tar.gz
PeerTube-db9df9a72c67a6ba150620f0f1c0838a3c155786.tar.zst
PeerTube-db9df9a72c67a6ba150620f0f1c0838a3c155786.zip
Fix local/session storage polyfill
Diffstat (limited to 'client/src/root-helpers')
-rw-r--r--client/src/root-helpers/peertube-web-storage.ts16
1 files changed, 7 insertions, 9 deletions
diff --git a/client/src/root-helpers/peertube-web-storage.ts b/client/src/root-helpers/peertube-web-storage.ts
index 68a2462de..0bbe2c9fc 100644
--- a/client/src/root-helpers/peertube-web-storage.ts
+++ b/client/src/root-helpers/peertube-web-storage.ts
@@ -6,19 +6,17 @@ function proxify (instance: MemoryStorage) {
6 return new Proxy(instance, { 6 return new Proxy(instance, {
7 set: function (obj, prop: string | symbol, value) { 7 set: function (obj, prop: string | symbol, value) {
8 if (Object.prototype.hasOwnProperty.call(MemoryStorage, prop)) { 8 if (Object.prototype.hasOwnProperty.call(MemoryStorage, prop)) {
9 // FIXME: symbol typing issue https://github.com/microsoft/TypeScript/issues/1863 9 instance[prop] = value
10 instance[prop as any] = value
11 } else { 10 } else {
12 instance.setItem(prop, value) 11 instance.setItem(prop, value)
13 } 12 }
13
14 return true 14 return true
15 }, 15 },
16 get: function (target, name: string | symbol | number) { 16 get: function (target, name: string | symbol | number) {
17 if (Object.prototype.hasOwnProperty.call(MemoryStorage, name)) { 17 if (typeof instance[name] === 'function') {
18 // FIXME: symbol typing issue https://github.com/microsoft/TypeScript/issues/1863 18 return instance[name]
19 return instance[name as any] 19 } else if (valuesMap.has(name)) {
20 }
21 if (valuesMap.has(name)) {
22 return instance.getItem(name) 20 return instance.getItem(name)
23 } 21 }
24 } 22 }
@@ -26,7 +24,7 @@ function proxify (instance: MemoryStorage) {
26} 24}
27 25
28class MemoryStorage implements Storage { 26class MemoryStorage implements Storage {
29 [key: string]: any 27 [key: string | symbol]: any
30 28
31 getItem (key: any) { 29 getItem (key: any) {
32 const stringKey = String(key) 30 const stringKey = String(key)
@@ -83,7 +81,7 @@ try {
83} 81}
84 82
85// support Brave and other browsers using null rather than an exception 83// support Brave and other browsers using null rather than an exception
86if (peertubeLocalStorage === null || peertubeSessionStorage === null) { 84if (!peertubeLocalStorage || !peertubeSessionStorage) {
87 reinitStorage() 85 reinitStorage()
88} 86}
89 87