1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-17 08:43:33 +00:00

Added --trash to delete cmd, added restore cmd

This commit is contained in:
Chad Scharf
2020-04-14 13:04:19 -04:00
parent 6e63a79cfd
commit 49f1fac3ed
8 changed files with 105 additions and 11 deletions

View File

@@ -0,0 +1,39 @@
import * as program from 'commander';
import { CipherService } from 'jslib/abstractions/cipher.service';
import { Response } from 'jslib/cli/models/response';
export class RestoreCommand {
constructor(private cipherService: CipherService) { }
async run(object: string, id: string, cmd: program.Command): Promise<Response> {
if (id != null) {
id = id.toLowerCase();
}
switch (object.toLowerCase()) {
case 'item':
return await this.restoreCipher(id, cmd);
default:
return Response.badRequest('Unknown object.');
}
}
private async restoreCipher(id: string, cmd: program.Command) {
const cipher = await this.cipherService.get(id);
if (cipher == null) {
return Response.notFound();
}
if (cipher.deletedDate == null) {
return Response.badRequest('Cipher is not in trash.');
}
try {
await this.cipherService.restoreWithServer(id);
return Response.success();
} catch (e) {
return Response.error(e);
}
}
}