|
|
@ -19,7 +19,7 @@ class LocalStorage<Storage extends Record<string, any>> { |
|
|
|
private cache: Partial<Storage> = {}; |
|
|
|
private cache: Partial<Storage> = {}; |
|
|
|
private useStorage = true; |
|
|
|
private useStorage = true; |
|
|
|
|
|
|
|
|
|
|
|
constructor(private preserveKeys: (keyof Storage)[]) { |
|
|
|
constructor(/* private preserveKeys: (keyof Storage)[] */) { |
|
|
|
if(Modes.test) { |
|
|
|
if(Modes.test) { |
|
|
|
this.prefix = 't_'; |
|
|
|
this.prefix = 't_'; |
|
|
|
} |
|
|
|
} |
|
|
@ -42,6 +42,8 @@ class LocalStorage<Storage extends Record<string, any>> { |
|
|
|
} catch(err) { |
|
|
|
} catch(err) { |
|
|
|
//console.error(err);
|
|
|
|
//console.error(err);
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
value = undefined; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return value; |
|
|
|
return value; |
|
|
@ -76,12 +78,16 @@ class LocalStorage<Storage extends Record<string, any>> { |
|
|
|
delete this.cache[key]; |
|
|
|
delete this.cache[key]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(this.useStorage) { |
|
|
|
//if(this.useStorage) {
|
|
|
|
localStorage.removeItem(this.prefix + key); |
|
|
|
try { |
|
|
|
} |
|
|
|
localStorage.removeItem(this.prefix + key); |
|
|
|
|
|
|
|
} catch(err) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
//}
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public clear(preserveKeys: (keyof Storage)[] = this.preserveKeys) { |
|
|
|
/* public clear(preserveKeys: (keyof Storage)[] = this.preserveKeys) { |
|
|
|
// if(this.useStorage) {
|
|
|
|
// if(this.useStorage) {
|
|
|
|
try { |
|
|
|
try { |
|
|
|
let obj: Partial<Storage> = {}; |
|
|
|
let obj: Partial<Storage> = {}; |
|
|
@ -103,6 +109,18 @@ class LocalStorage<Storage extends Record<string, any>> { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
} */ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public clear() { |
|
|
|
|
|
|
|
const keys: string[] = ['dc', 'server_time_offset', 'xt_instance', 'user_auth']; |
|
|
|
|
|
|
|
for(let i = 1; i <= 5; ++i) { |
|
|
|
|
|
|
|
keys.push(`dc${i}_server_salt`); |
|
|
|
|
|
|
|
keys.push(`dc${i}_auth_key`); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for(let key of keys) { |
|
|
|
|
|
|
|
this.delete(key, true); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public toggleStorage(enabled: boolean) { |
|
|
|
public toggleStorage(enabled: boolean) { |
|
|
@ -138,11 +156,11 @@ export default class LocalStorageController<Storage extends Record<string, any>> |
|
|
|
|
|
|
|
|
|
|
|
private storage: LocalStorage<Storage>; |
|
|
|
private storage: LocalStorage<Storage>; |
|
|
|
|
|
|
|
|
|
|
|
constructor(private preserveKeys: (keyof Storage)[] = []) { |
|
|
|
constructor(/* private preserveKeys: (keyof Storage)[] = [] */) { |
|
|
|
LocalStorageController.STORAGES.push(this); |
|
|
|
LocalStorageController.STORAGES.push(this); |
|
|
|
|
|
|
|
|
|
|
|
if(!isWorker) { |
|
|
|
if(!isWorker) { |
|
|
|
this.storage = new LocalStorage(preserveKeys); |
|
|
|
this.storage = new LocalStorage(/* preserveKeys */); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -196,8 +214,8 @@ export default class LocalStorageController<Storage extends Record<string, any>> |
|
|
|
return this.proxy<void>('delete', key, saveLocal); |
|
|
|
return this.proxy<void>('delete', key, saveLocal); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public clear(preserveKeys?: (keyof Storage)[]) { |
|
|
|
public clear(/* preserveKeys?: (keyof Storage)[] */) { |
|
|
|
return this.proxy<void>('clear', preserveKeys); |
|
|
|
return this.proxy<void>('clear'/* , preserveKeys */); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public toggleStorage(enabled: boolean) { |
|
|
|
public toggleStorage(enabled: boolean) { |
|
|
|