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:
7
src/services/nodeMessaging.service.ts
Normal file
7
src/services/nodeMessaging.service.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { MessagingService } from 'jslib/abstractions/messaging.service';
|
||||
|
||||
export class NodeMessagingService implements MessagingService {
|
||||
send(subscriber: string, arg: any = {}) {
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
@@ -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 {
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user