1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-13 14:53:33 +00:00

Add CoreModule (#3149)

This commit is contained in:
Oscar Hinton
2022-07-26 19:34:45 +02:00
committed by GitHub
parent 2011131bb2
commit 797938881e
34 changed files with 59 additions and 44 deletions

View File

@@ -0,0 +1,26 @@
import { Injectable } from "@angular/core";
import { FileDownloadService } from "@bitwarden/common/abstractions/fileDownload/fileDownload.service";
import { FileDownloadBuilder } from "@bitwarden/common/abstractions/fileDownload/fileDownloadBuilder";
import { FileDownloadRequest } from "@bitwarden/common/abstractions/fileDownload/fileDownloadRequest";
import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.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 (builder.downloadMethod === "save") {
a.download = request.fileName;
} else if (!this.platformUtilsService.isSafari()) {
a.target = "_blank";
}
a.href = URL.createObjectURL(builder.blob);
a.style.position = "fixed";
window.document.body.appendChild(a);
a.click();
window.document.body.removeChild(a);
}
}