Fix broken client when cookies are disabled

This commit is contained in:
Chocobozzz 2020-05-20 10:37:46 +02:00
parent 572bf73be6
commit 6189b699fb
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
1 changed files with 24 additions and 18 deletions

View File

@ -47,26 +47,32 @@ try {
peertubeLocalStorage = localStorage
peertubeSessionStorage = sessionStorage
} catch (err) {
const instance = new MemoryStorage()
const instanceLocalStorage = new MemoryStorage()
const instanceSessionStorage = new MemoryStorage()
peertubeLocalStorage = sessionStorage = new Proxy(instance, {
set: function (obj, prop: string | number, value) {
if (MemoryStorage.prototype.hasOwnProperty(prop)) {
instance[prop] = value
} else {
instance.setItem(prop, value)
function proxify (instance: MemoryStorage) {
return new Proxy(instance, {
set: function (obj, prop: string | number, value) {
if (MemoryStorage.prototype.hasOwnProperty(prop)) {
instance[prop] = value
} else {
instance.setItem(prop, value)
}
return true
},
get: function (target, name: string | number) {
if (MemoryStorage.prototype.hasOwnProperty(name)) {
return instance[name]
}
if (valuesMap.has(name)) {
return instance.getItem(name)
}
}
return true
},
get: function (target, name: string | number) {
if (MemoryStorage.prototype.hasOwnProperty(name)) {
return instance[name]
}
if (valuesMap.has(name)) {
return instance.getItem(name)
}
}
})
})
}
peertubeLocalStorage = proxify(instanceLocalStorage)
peertubeSessionStorage = proxify(instanceSessionStorage)
}
export {