1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-25 04:33:34 +00:00

get vault working

This commit is contained in:
Kyle Spearrin
2018-06-06 17:25:57 -04:00
parent cc9410602c
commit a89cf28812
18 changed files with 960 additions and 151 deletions

View File

@@ -1,23 +1,27 @@
import { StorageService } from 'jslib/abstractions/storage.service';
export class WebStorageService implements StorageService {
private store: any = {};
get<T>(key: string): Promise<T> {
const val = this.store[key];
if (val == null) {
const json = window.sessionStorage.getItem(key);
if (json == null) {
return Promise.resolve(null);
}
return Promise.resolve(val as T);
const obj = JSON.parse(json);
return Promise.resolve(obj as T);
}
save(key: string, obj: any): Promise<any> {
this.store[key] = obj;
if (obj == null) {
this.remove(key);
return;
}
const json = JSON.stringify(obj);
window.sessionStorage.setItem(key, json);
return Promise.resolve();
}
remove(key: string): Promise<any> {
delete this.store[key];
window.sessionStorage.removeItem(key);
return Promise.resolve();
}