This commit is contained in:
Peter Maquiran
2023-07-12 13:54:20 +01:00
parent cadf84a0d4
commit 1087e68690
9 changed files with 35 additions and 45 deletions
+10 -6
View File
@@ -6,7 +6,7 @@ function prefix() {
return environment.version.lastCommitNumber + environment.id+"-";
}
export function GET({key, localStorage, instance}) {
export function GET({key, instance}) {
if(environment.storageProduction) {
try {
@@ -26,7 +26,8 @@ export function GET({key, localStorage, instance}) {
}
} else {
const restoredData = JSON.parse(localStorage.getItem(prefix() + key))
const newKey = prefix() + key
const restoredData = JSON.parse(localStorage.getItem(newKey))
Object.assign(instance, restoredData);
return restoredData
@@ -34,7 +35,7 @@ export function GET({key, localStorage, instance}) {
}
export function SAVE({key, localStorage, instance, dataToSave}) {
export function SAVE({key, instance, dataToSave}) {
if(environment.storageProduction) {
const newKey = prefix() + SHA1(key).toString()
const stringifyData = JSON.stringify(dataToSave)
@@ -45,16 +46,19 @@ export function SAVE({key, localStorage, instance, dataToSave}) {
} else {
const stringifyData = JSON.stringify(dataToSave)
localStorage.setItem(prefix() + key, stringifyData)
const newKey = prefix() + key
localStorage.setItem(newKey, stringifyData)
}
}
export function DELETE({key, localStorage, instance}) {
export function DELETE({key, instance}) {
if(environment.storageProduction) {
const newKey = prefix() + SHA1(key).toString()
localStorage.removeItem(newKey)
} else {
localStorage.removeItem(prefix() + key)
const newKey = prefix() + key
localStorage.removeItem(newKey)
}
}