diff options
author | Chocobozzz <me@florianbigard.com> | 2020-05-20 10:37:46 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2020-05-20 10:37:46 +0200 |
commit | 6189b699fbc2d428d6baf09473356ed4568ea2a6 (patch) | |
tree | 1c392550d886ec056e812ad37630f227a12fc782 /client/src/app/shared/misc/peertube-web-storage.ts | |
parent | 572bf73be68f63ac28beb27bde289925c15be239 (diff) | |
download | PeerTube-6189b699fbc2d428d6baf09473356ed4568ea2a6.tar.gz PeerTube-6189b699fbc2d428d6baf09473356ed4568ea2a6.tar.zst PeerTube-6189b699fbc2d428d6baf09473356ed4568ea2a6.zip |
Fix broken client when cookies are disabled
Diffstat (limited to 'client/src/app/shared/misc/peertube-web-storage.ts')
-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 { |