support for attachment key on get
This commit is contained in:
parent
89dfa4e4f8
commit
2bc488b956
2
jslib
2
jslib
|
@ -1 +1 @@
|
||||||
Subproject commit 739d308498ab68df3e37772265733c81b27f2cc2
|
Subproject commit 9283a29d35a18f058f3c84f8aaa919b911f1940a
|
|
@ -84,7 +84,7 @@ export class GetCommand {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async getCipher(id: string) {
|
private async getCipherView(id: string): Promise<CipherView | string[]> {
|
||||||
let decCipher: CipherView = null;
|
let decCipher: CipherView = null;
|
||||||
if (this.isGuid(id)) {
|
if (this.isGuid(id)) {
|
||||||
const cipher = await this.cipherService.get(id);
|
const cipher = await this.cipherService.get(id);
|
||||||
|
@ -95,16 +95,24 @@ export class GetCommand {
|
||||||
let ciphers = await this.cipherService.getAllDecrypted();
|
let ciphers = await this.cipherService.getAllDecrypted();
|
||||||
ciphers = this.searchService.searchCiphersBasic(ciphers, id);
|
ciphers = this.searchService.searchCiphersBasic(ciphers, id);
|
||||||
if (ciphers.length > 1) {
|
if (ciphers.length > 1) {
|
||||||
return Response.multipleResults(ciphers.map((c) => c.id));
|
return ciphers.map((c) => c.id);
|
||||||
}
|
}
|
||||||
if (ciphers.length > 0) {
|
if (ciphers.length > 0) {
|
||||||
decCipher = ciphers[0];
|
decCipher = ciphers[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return decCipher;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async getCipher(id: string) {
|
||||||
|
const decCipher = await this.getCipherView(id);
|
||||||
if (decCipher == null) {
|
if (decCipher == null) {
|
||||||
return Response.notFound();
|
return Response.notFound();
|
||||||
}
|
}
|
||||||
|
if (Array.isArray(decCipher)) {
|
||||||
|
return Response.multipleResults(decCipher);
|
||||||
|
}
|
||||||
const res = new CipherResponse(decCipher);
|
const res = new CipherResponse(decCipher);
|
||||||
return Response.success(res);
|
return Response.success(res);
|
||||||
}
|
}
|
||||||
|
@ -221,8 +229,8 @@ export class GetCommand {
|
||||||
return cipherResponse;
|
return cipherResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
const cipher = cipherResponse.data as CipherResponse;
|
const cipher = await this.getCipherView(itemId);
|
||||||
if (cipher.attachments == null || cipher.attachments.length === 0) {
|
if (cipher == null || Array.isArray(cipher) || cipher.attachments.length === 0) {
|
||||||
return Response.error('No attachments available for this item.');
|
return Response.error('No attachments available for this item.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -249,7 +257,8 @@ export class GetCommand {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const buf = await response.arrayBuffer();
|
const buf = await response.arrayBuffer();
|
||||||
const key = await this.cryptoService.getOrgKey(cipher.organizationId);
|
const key = attachments[0].key != null ? attachments[0].key :
|
||||||
|
await this.cryptoService.getOrgKey(cipher.organizationId);
|
||||||
const decBuf = await this.cryptoService.decryptFromBytes(buf, key);
|
const decBuf = await this.cryptoService.decryptFromBytes(buf, key);
|
||||||
const filePath = await CliUtils.saveFile(Buffer.from(decBuf), cmd.output, attachments[0].fileName);
|
const filePath = await CliUtils.saveFile(Buffer.from(decBuf), cmd.output, attachments[0].fileName);
|
||||||
const res = new MessageResponse('Saved ' + filePath, null);
|
const res = new MessageResponse('Saved ' + filePath, null);
|
||||||
|
|
Loading…
Reference in New Issue