1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-16 00:03:56 +00:00

[fix] Force send attachment to always download and never open (#2908)

* [refactor] Introduce a file download service

* [refactor] Point platformUtilsService.saveFile() callers to fileDownloadService.download() instead

* [refactor] Remove platformUtilsService.saveFile()

* [fix] Force send attachments to always download and never open

* [fix] Remove the window property from FileDownloadRequest

* [fix] Move FileDownloadRequest to /abstractions/fileDownload

* [fix] Simplify FileDownloadRequest to a type

* [fix] Move BrowserApi.saveFile logic into BrowserFileDownloadService

* [fix] Use proper blob types for file downloads

* [fix] forceDownload -> downloadMethod on FileDownloadRequest

* [fix] Remove fileType from FileDownloadRequest

* [fix] Make fileType private
This commit is contained in:
Addison Beck
2022-06-29 14:15:29 -07:00
committed by GitHub
parent a89b745f0b
commit bb7dce031c
35 changed files with 297 additions and 155 deletions

View File

@@ -4,6 +4,7 @@ import { ActivatedRoute } from "@angular/router";
import { ApiService } from "@bitwarden/common/abstractions/api.service";
import { CryptoService } from "@bitwarden/common/abstractions/crypto.service";
import { CryptoFunctionService } from "@bitwarden/common/abstractions/cryptoFunction.service";
import { FileDownloadService } from "@bitwarden/common/abstractions/fileDownload/fileDownload.service";
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service";
import { SEND_KDF_ITERATIONS } from "@bitwarden/common/enums/kdfType";
@@ -44,7 +45,8 @@ export class AccessComponent implements OnInit {
private apiService: ApiService,
private platformUtilsService: PlatformUtilsService,
private route: ActivatedRoute,
private cryptoService: CryptoService
private cryptoService: CryptoService,
private fileDownloadService: FileDownloadService
) {}
get sendText() {
@@ -109,7 +111,11 @@ export class AccessComponent implements OnInit {
try {
const buf = await response.arrayBuffer();
const decBuf = await this.cryptoService.decryptFromBytes(buf, this.decKey);
this.platformUtilsService.saveFile(window, decBuf, null, this.send.file.fileName);
this.fileDownloadService.download({
fileName: this.send.file.fileName,
blobData: decBuf,
downloadMethod: "save",
});
} catch (e) {
this.platformUtilsService.showToast("error", null, this.i18nService.t("errorOccurred"));
}