application data directory

This commit is contained in:
Kyle Spearrin 2018-05-14 08:26:00 -04:00
parent 70c7b182ae
commit ad2fa7efbb
2 changed files with 13 additions and 6 deletions

View File

@ -2,7 +2,6 @@ import * as program from 'commander';
import { AuthService } from 'jslib/services/auth.service';
import { LoginCommand } from './commands/login.command';
import { CryptoService } from 'jslib/services/crypto.service';
@ -19,13 +18,12 @@ import { NodeMessagingService } from './services/nodeMessaging.service';
const platformUtilsService = new NodePlatformUtilsService();
const cryptoFunctionService = new NodeCryptoFunctionService();
const storageService = new NodeStorageService('./scratch');
const storageService = new NodeStorageService('Bitwarden CLI');
const cryptoService = new CryptoService(storageService, storageService, cryptoFunctionService);
const appIdService = new AppIdService(storageService);
const tokenService = new TokenService(storageService);
const messagingService = new NodeMessagingService();
const apiService = new ApiService(tokenService, platformUtilsService,
(expired: boolean) => { });
const apiService = new ApiService(tokenService, platformUtilsService, (expired: boolean) => { });
const environmentService = new EnvironmentService(apiService, storageService);
const userService = new UserService(tokenService, storageService);
const containerService = new ContainerService(cryptoService, platformUtilsService);

View File

@ -4,10 +4,19 @@ import { Utils } from 'jslib/misc/utils';
let localStorage = Utils.isBrowser ? window.localStorage : null;
export class NodeStorageService implements StorageService {
constructor(dirLocation: string) {
constructor(appDirName: string) {
if (Utils.isNode && localStorage == null) {
const LocalStorage = require('node-localstorage').LocalStorage;
localStorage = new LocalStorage(dirLocation);
let path = null;
if (process.platform === 'darwin') {
path = process.env.HOME + 'Library/Application Support';
} else if (process.platform === 'win32') {
path = process.env.APPDATA;
} else {
path = process.env.HOME + '.config';
}
path += ('/' + appDirName + '/data');
localStorage = new LocalStorage(path);
}
}