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

setup storage service and log in

This commit is contained in:
Kyle Spearrin
2018-05-13 00:19:14 -04:00
parent 8f49b58d2e
commit 70c7b182ae
9 changed files with 151 additions and 8 deletions

View File

@@ -0,0 +1,7 @@
import { MessagingService } from 'jslib/abstractions/messaging.service';
export class NodeMessagingService implements MessagingService {
send(subscriber: string, arg: any = {}) {
// TODO
}
}

View File

@@ -10,8 +10,8 @@ export class NodePlatformUtilsService implements PlatformUtilsService {
private deviceCache: DeviceType = null;
constructor(private i18nService: I18nService, private isDesktopApp: boolean) {
this.identityClientId = 'cli';
constructor() {
this.identityClientId = 'desktop'; // TODO: cli
}
getDevice(): DeviceType {

View File

@@ -1,15 +1,42 @@
import { StorageService } from 'jslib/abstractions/storage.service';
import { Utils } from 'jslib/misc/utils';
let localStorage = Utils.isBrowser ? window.localStorage : null;
export class NodeStorageService implements StorageService {
constructor(dirLocation: string) {
if (Utils.isNode && localStorage == null) {
const LocalStorage = require('node-localstorage').LocalStorage;
localStorage = new LocalStorage(dirLocation);
}
}
get<T>(key: string): Promise<T> {
const val = localStorage.getItem(key);
if (val != null) {
try {
const obj = JSON.parse(val);
if (obj != null && obj[key] != null) {
return Promise.resolve(obj[key] as T);
}
} catch{ }
}
return Promise.resolve(null);
}
save(key: string, obj: any): Promise<any> {
let val: string = null;
if (obj != null) {
const o: any = {};
o[key] = obj;
val = JSON.stringify(o);
}
localStorage.setItem(key, val);
return Promise.resolve();
}
remove(key: string): Promise<any> {
localStorage.removeItem(key);
return Promise.resolve();
}
}