1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-26 13:13:22 +00:00
Files
browser/apps/cli/src/commands/restore.command.ts
2022-06-14 17:10:53 +02:00

37 lines
958 B
TypeScript

import { CipherService } from "@bitwarden/common/abstractions/cipher.service";
import { Response } from "@bitwarden/node/cli/models/response";
export class RestoreCommand {
constructor(private cipherService: CipherService) {}
async run(object: string, id: string): Promise<Response> {
if (id != null) {
id = id.toLowerCase();
}
switch (object.toLowerCase()) {
case "item":
return await this.restoreCipher(id);
default:
return Response.badRequest("Unknown object.");
}
}
private async restoreCipher(id: string) {
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);
}
}
}