2022-06-29 23:15:29 +02:00
|
|
|
import { Injectable } from "@angular/core";
|
|
|
|
|
2023-06-06 22:34:53 +02:00
|
|
|
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";
|
2022-06-29 23:15:29 +02:00
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class DesktopFileDownloadService implements FileDownloadService {
|
|
|
|
download(request: FileDownloadRequest): void {
|
|
|
|
const a = window.document.createElement("a");
|
|
|
|
a.href = URL.createObjectURL(new FileDownloadBuilder(request).blob);
|
|
|
|
a.download = request.fileName;
|
|
|
|
a.style.position = "fixed";
|
|
|
|
window.document.body.appendChild(a);
|
|
|
|
a.click();
|
|
|
|
window.document.body.removeChild(a);
|
|
|
|
}
|
|
|
|
}
|