mirror of
https://github.com/bitwarden/browser.git
synced 2024-10-09 05:57:40 +02:00
89751f46d6
* 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>
26 lines
1.1 KiB
TypeScript
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);
|
|
}
|
|
}
|