From 227f45740969abb26594eff355e1d9f5c2cd500c Mon Sep 17 00:00:00 2001 From: Matt Gibson Date: Tue, 2 Mar 2021 11:11:27 -0600 Subject: [PATCH] Use download link requests (#859) * Use download link requests * Update jslib * Update jslib --- jslib | 2 +- src/app/send/access.component.ts | 19 ++++++++++++++----- src/locales/en/messages.json | 4 ++++ 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/jslib b/jslib index 301ef455..3942868c 160000 --- a/jslib +++ b/jslib @@ -1 +1 @@ -Subproject commit 301ef455f3df59be9ca26ab98d8686b93c09ef4a +Subproject commit 3942868cf488ed8c1983ffadab2c8900b8c78410 diff --git a/src/app/send/access.component.ts b/src/app/send/access.component.ts index e0a48b86..5724aaa4 100644 --- a/src/app/send/access.component.ts +++ b/src/app/send/access.component.ts @@ -43,6 +43,7 @@ export class AccessComponent implements OnInit { private id: string; private key: string; private decKey: SymmetricCryptoKey; + private accessRequest: SendAccessRequest; constructor(private i18nService: I18nService, private cryptoFunctionService: CryptoFunctionService, private apiService: ApiService, private platformUtilsService: PlatformUtilsService, @@ -90,8 +91,16 @@ export class AccessComponent implements OnInit { return; } + + const downloadData = await this.apiService.getSendFileDownloadData(this.send, this.accessRequest); + + if (Utils.isNullOrWhitespace(downloadData.url)) { + this.platformUtilsService.showToast('error', null, this.i18nService.t('missingSendFile')); + return; + } + this.downloading = true; - const response = await fetch(new Request(this.send.file.url, { cache: 'no-store' })); + const response = await fetch(new Request(downloadData.url, { cache: 'no-store' })); if (response.status !== 200) { this.platformUtilsService.showToast('error', null, this.i18nService.t('errorOccurred')); this.downloading = false; @@ -123,17 +132,17 @@ export class AccessComponent implements OnInit { this.unavailable = false; this.error = false; const keyArray = Utils.fromUrlB64ToArray(this.key); - const accessRequest = new SendAccessRequest(); + this.accessRequest = new SendAccessRequest(); if (this.password != null) { const passwordHash = await this.cryptoFunctionService.pbkdf2(this.password, keyArray, 'sha256', 100000); - accessRequest.password = Utils.fromBufferToB64(passwordHash); + this.accessRequest.password = Utils.fromBufferToB64(passwordHash); } try { let sendResponse: SendAccessResponse = null; if (this.loading) { - sendResponse = await this.apiService.postSendAccess(this.id, accessRequest); + sendResponse = await this.apiService.postSendAccess(this.id, this.accessRequest); } else { - this.formPromise = this.apiService.postSendAccess(this.id, accessRequest); + this.formPromise = this.apiService.postSendAccess(this.id, this.accessRequest); sendResponse = await this.formPromise; } this.passwordRequired = false; diff --git a/src/locales/en/messages.json b/src/locales/en/messages.json index cbb8348d..372d98b6 100644 --- a/src/locales/en/messages.json +++ b/src/locales/en/messages.json @@ -3425,6 +3425,10 @@ "message": "The Send you are trying to access does not exist or is no longer available.", "description": "'Send' is a noun and the name of a feature called 'Bitwarden Send'. It should not be translated." }, + "missingSendFile": { + "message": "The file associated with this Send could not be found.", + "description": "'Send' is a noun and the name of a feature called 'Bitwarden Send'. It should not be translated." + }, "noSendsInList": { "message": "There are no Sends to list.", "description": "'Send' is a noun and the name of a feature called 'Bitwarden Send'. It should not be translated."