1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-10-09 05:57:40 +02:00
bitwarden-browser/apps/web/src/app/core/web-file-download.service.ts
Jason Ng 89751f46d6
[PM-254] Set PDF Attachments in Web to download, add success toast (#10757)
* add success toast to pdf attachment download in web

* update desktop attachments for toastService

* removed trailing comma

---------

Co-authored-by: gbubemismith <gsmithwalter@gmail.com>
Co-authored-by: SmithThe4th <gsmith@bitwarden.com>
2024-09-11 15:27:53 -04:00

26 lines
1.1 KiB
TypeScript

import { Injectable } from "@angular/core";
import { FileDownloadBuilder } from "@bitwarden/common/platform/abstractions/file-download/file-download.builder";
import { FileDownloadRequest } from "@bitwarden/common/platform/abstractions/file-download/file-download.request";
import { FileDownloadService } from "@bitwarden/common/platform/abstractions/file-download/file-download.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
@Injectable()
export class WebFileDownloadService implements FileDownloadService {
constructor(private platformUtilsService: PlatformUtilsService) {}
download(request: FileDownloadRequest): void {
const builder = new FileDownloadBuilder(request);
const a = window.document.createElement("a");
if (!this.platformUtilsService.isSafari()) {
a.rel = "noreferrer";
a.target = "_blank";
}
a.href = URL.createObjectURL(builder.blob);
a.download = request.fileName;
window.document.body.appendChild(a);
a.click();
window.document.body.removeChild(a);
}
}