mirror of
https://github.com/bitwarden/browser
synced 2025-12-19 01:33:33 +00:00
Export to stdout (#152)
* describe file-saving and add helper to write to stdout if appropriate * allow writing attachments to stdout * allow writing export to stdout * add help texts for export and get
This commit is contained in:
committed by
GitHub
parent
9f72e0e316
commit
f2530c133e
@@ -35,27 +35,24 @@ export class ExportCommand {
|
||||
if (cmd.organizationid != null && !Utils.isGuid(cmd.organizationid)) {
|
||||
return Response.error('`' + cmd.organizationid + '` is not a GUID.');
|
||||
}
|
||||
let csv: string = null;
|
||||
let exportContent: string = null;
|
||||
try {
|
||||
csv = cmd.organizationid != null ?
|
||||
exportContent = cmd.organizationid != null ?
|
||||
await this.exportService.getOrganizationExport(cmd.organizationid, format) :
|
||||
await this.exportService.getExport(format);
|
||||
} catch (e) {
|
||||
return Response.error(e);
|
||||
}
|
||||
return await this.saveFile(csv, cmd, format);
|
||||
return await this.saveFile(exportContent, cmd, format);
|
||||
} else {
|
||||
return Response.error('Invalid master password.');
|
||||
}
|
||||
}
|
||||
|
||||
async saveFile(csv: string, cmd: program.Command, format: string): Promise<Response> {
|
||||
async saveFile(exportContent: string, cmd: program.Command, format: string): Promise<Response> {
|
||||
try {
|
||||
const filePath = await CliUtils.saveFile(csv, cmd.output,
|
||||
this.exportService.getFileName(cmd.organizationid != null ? 'org' : null, format));
|
||||
const res = new MessageResponse('Saved ' + filePath, null);
|
||||
res.raw = filePath;
|
||||
return Response.success(res);
|
||||
const fileName = this.exportService.getFileName(cmd.organizationid != null ? 'org' : null, format);
|
||||
return await CliUtils.saveResultToFile(exportContent, cmd.output, fileName);
|
||||
} catch (e) {
|
||||
return Response.error(e.toString());
|
||||
}
|
||||
|
||||
@@ -283,10 +283,7 @@ export class GetCommand {
|
||||
const key = attachments[0].key != null ? attachments[0].key :
|
||||
await this.cryptoService.getOrgKey(cipher.organizationId);
|
||||
const decBuf = await this.cryptoService.decryptFromBytes(buf, key);
|
||||
const filePath = await CliUtils.saveFile(Buffer.from(decBuf), cmd.output, attachments[0].fileName);
|
||||
const res = new MessageResponse('Saved ' + filePath, null);
|
||||
res.raw = filePath;
|
||||
return Response.success(res);
|
||||
return await CliUtils.saveResultToFile(Buffer.from(decBuf), cmd.output, attachments[0].fileName);
|
||||
} catch (e) {
|
||||
if (typeof (e) === 'string') {
|
||||
return Response.error(e);
|
||||
|
||||
Reference in New Issue
Block a user