1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-27 12:36:14 +01:00

Get Attachment Download url from server (#295)

This commit is contained in:
Matt Gibson 2021-04-29 09:49:04 -05:00 committed by GitHub
parent 9c55d78ffc
commit 63f522026b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -32,6 +32,7 @@ import { FolderView } from 'jslib/models/view/folderView';
import { EncString } from 'jslib/models/domain/encString';
import { ErrorResponse } from 'jslib/models/response/errorResponse';
import { Response } from 'jslib/cli/models/response';
import { StringResponse } from 'jslib/cli/models/response/stringResponse';
@ -287,9 +288,23 @@ export class GetCommand extends DownloadCommand {
}
}
let url: string;
try {
const attachmentDownloadResponse = await this.apiService.getAttachmentData(cipher.id, attachments[0].id);
url = attachmentDownloadResponse.url;
} catch (e) {
if (e instanceof ErrorResponse && (e as ErrorResponse).statusCode === 404) {
url = attachments[0].url;
} else if (e instanceof ErrorResponse) {
throw new Error((e as ErrorResponse).getSingleMessage());
} else {
throw e;
}
}
const key = attachments[0].key != null ? attachments[0].key :
await this.cryptoService.getOrgKey(cipher.organizationId);
return await this.saveAttachmentToFile(attachments[0].url, key, attachments[0].fileName, options.output);
return await this.saveAttachmentToFile(url, key, attachments[0].fileName, options.output);
}
private async getFolder(id: string) {