mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 04:57:52 +00:00
Fix storage service
This commit is contained in:
@@ -11,7 +11,6 @@ const { Storage } = Plugins; */
|
||||
export class StorageService {
|
||||
private keyName: string;
|
||||
|
||||
|
||||
constructor(private storage:Storage,
|
||||
private platform: Platform
|
||||
) {}
|
||||
@@ -22,50 +21,27 @@ const { Storage } = Plugins; */
|
||||
|
||||
// Store the value
|
||||
async store(key: string, value: any) {
|
||||
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
|
||||
await localstoreService.set(this.key(key), value)
|
||||
} else {
|
||||
const encryptedValue = btoa(escape(JSON.stringify(value)));
|
||||
await this.storage.set(key, encryptedValue);
|
||||
}
|
||||
|
||||
await localstoreService.set(this.key(key), value)
|
||||
|
||||
}
|
||||
// Get the value
|
||||
async get(key: string) {
|
||||
|
||||
|
||||
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
|
||||
return new Promise((resolve, reject)=>{
|
||||
const data = localstoreService.get(this.key(key), false)
|
||||
if(data) resolve(data)
|
||||
else reject(data)
|
||||
})
|
||||
} else {
|
||||
const ret = await this.storage.get(key).then((val) => { return val; });
|
||||
try {
|
||||
return JSON.parse(unescape(atob(ret)));
|
||||
} catch (error) {
|
||||
if(ret == 'ée') {
|
||||
throw(key+' not found')
|
||||
}
|
||||
return unescape(atob(ret))
|
||||
}
|
||||
}
|
||||
async get(key: string): Promise<any> {
|
||||
|
||||
return new Promise((resolve, reject)=>{
|
||||
const data = localstoreService.get(this.key(key), false)
|
||||
if(data) resolve(data)
|
||||
else reject(data)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
async remove(key: string){
|
||||
|
||||
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
|
||||
await localstoreService.delete(this.key(key))
|
||||
} else {
|
||||
await this.storage.remove(key);
|
||||
}
|
||||
await localstoreService.delete(this.key(key))
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
// Get the value
|
||||
async get(storageKey: string) {
|
||||
|
||||
Reference in New Issue
Block a user