Files
doneit-web/src/app/services/storage.service.ts
T

65 lines
1.5 KiB
TypeScript
Raw Normal View History

2020-08-05 15:39:16 +01:00
import { Injectable } from '@angular/core';
2021-02-25 12:41:29 +01:00
import { Storage } from '@ionic/storage';
2021-08-31 09:00:33 +01:00
import { AnimationController, ModalController,Platform } from '@ionic/angular';
import { SHA1 } from 'crypto-js'
import { localstoreService } from '../store/localstore.service';
2021-02-23 16:10:14 +01:00
/* import { Plugins } from '@capacitor/core';
const { Storage } = Plugins; */
2020-08-05 15:39:16 +01:00
@Injectable({
providedIn: 'root'
2020-08-06 14:31:07 +01:00
})
export class StorageService {
2021-08-31 09:00:33 +01:00
private keyName: string;
constructor(private storage:Storage,
private platform: Platform
) {}
2021-08-31 13:46:39 +01:00
key(key:string): string {
2023-01-12 15:27:09 +01:00
return (SHA1('service'+"StorageService"+key)).toString()
2021-08-31 13:46:39 +01:00
}
2020-08-06 14:31:07 +01:00
2023-01-05 12:11:50 +01:00
async keyExist(key:string) {
return await localstoreService.keyExist(this.key(key))
}
2021-02-25 12:41:29 +01:00
// Store the value
2021-08-31 09:00:33 +01:00
async store(key: string, value: any) {
2021-08-31 19:30:08 +01:00
await localstoreService.set(this.key(key), value)
2021-08-31 09:00:33 +01:00
2020-08-06 14:31:07 +01:00
}
2021-02-25 12:41:29 +01:00
// Get the value
2021-08-31 19:30:08 +01:00
async get(key: string): Promise<any> {
2021-08-31 09:00:33 +01:00
2021-08-31 19:30:08 +01:00
return new Promise((resolve, reject)=>{
const data = localstoreService.get(this.key(key), false)
if(data) resolve(data)
else reject(data)
})
2021-08-31 09:00:33 +01:00
2021-02-26 08:38:33 +01:00
}
2021-08-18 17:36:40 +01:00
async remove(key: string){
2021-08-31 09:00:33 +01:00
2021-08-31 19:30:08 +01:00
await localstoreService.delete(this.key(key))
2021-08-31 09:00:33 +01:00
2021-08-18 17:36:40 +01:00
}
2021-08-20 12:31:14 +01:00
/*
2021-01-13 10:02:30 +01:00
// Get the value
async get(storageKey: string) {
const ret = await Storage.get({ key: storageKey });
return JSON.parse(unescape(atob(ret.value)));
2020-08-06 14:31:07 +01:00
}
2021-01-13 10:02:30 +01:00
async removeStorageItem(storageKey: string) {
await Storage.remove({ key: storageKey });
}
2020-08-05 15:39:16 +01:00
2020-08-06 14:31:07 +01:00
// Clear storage
async clear() {
2021-01-13 10:02:30 +01:00
await Storage.clear();
2021-02-23 16:10:14 +01:00
} */
2020-08-05 15:39:16 +01:00
}