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
1 changed files with 16 additions and 1 deletions

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) {