1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-14 07:13:32 +00:00

move last sync and generapte password out to other commands

This commit is contained in:
Kyle Spearrin
2018-05-16 13:53:12 -04:00
parent 8a337893da
commit 3a53e2d208
4 changed files with 66 additions and 50 deletions

View File

@@ -5,8 +5,6 @@ import { CipherType } from 'jslib/enums/cipherType';
import { CipherService } from 'jslib/abstractions/cipher.service';
import { CollectionService } from 'jslib/abstractions/collection.service';
import { FolderService } from 'jslib/abstractions/folder.service';
import { PasswordGenerationService } from 'jslib/abstractions/passwordGeneration.service';
import { SyncService } from 'jslib/abstractions/sync.service';
import { TotpService } from 'jslib/abstractions/totp.service';
import { CipherView } from 'jslib/models/view/cipherView';
@@ -34,14 +32,9 @@ import { CliUtils } from '../utils';
export class GetCommand {
constructor(private cipherService: CipherService, private folderService: FolderService,
private collectionService: CollectionService, private totpService: TotpService,
private syncService: SyncService, private passwordGenerationService: PasswordGenerationService) { }
private collectionService: CollectionService, private totpService: TotpService) { }
async run(object: string, id: string, cmd: program.Command): Promise<Response> {
if (id == null && object !== 'lastsync' && object !== 'password') {
return Response.badRequest('`id` argument is required.');
}
if (id != null) {
id = id.toLowerCase();
}
@@ -57,10 +50,6 @@ export class GetCommand {
return await this.getCollection(id);
case 'template':
return await this.getTemplate(id);
case 'lastsync':
return await this.getLastSync();
case 'password':
return await this.getPassword(cmd);
default:
return Response.badRequest('Unknown object.');
}
@@ -206,31 +195,4 @@ export class GetCommand {
const res = new TemplateResponse(template);
return Response.success(res);
}
private async getLastSync() {
const lastSyncDate = await this.syncService.getLastSync();
const res = new StringResponse(lastSyncDate == null ? null : lastSyncDate.toISOString());
return Response.success(res);
}
private async getPassword(cmd: program.Command) {
const options = {
uppercase: cmd.uppercase || false,
lowercase: cmd.lowercase || false,
number: cmd.number || false,
special: cmd.special || false,
length: cmd.length || 14,
};
if (!options.uppercase && !options.lowercase && !options.special && !options.number) {
options.lowercase = true;
options.uppercase = true;
options.number = true;
}
if (options.length < 5) {
options.length = 5;
}
const password = await this.passwordGenerationService.generatePassword(options);
const res = new StringResponse(password);
return Response.success(res);
}
}