feat: add file preview modal (#945)

This commit is contained in:
Aman Harwara
2022-03-24 00:13:44 +05:30
committed by GitHub
parent 8715a8b8f4
commit 12e3bb0959
15 changed files with 445 additions and 135 deletions

View File

@@ -24,6 +24,8 @@ type ZippableData = {
content: Blob;
}[];
type ObjectURL = string;
export class ArchiveManager {
private readonly application: WebApplication;
private textFile?: string;
@@ -32,6 +34,10 @@ export class ArchiveManager {
this.application = application;
}
public async getMimeType(ext: string) {
return (await import('@zip.js/zip.js')).getMimeType(ext);
}
public async downloadBackup(encrypted: boolean): Promise<void> {
const intent = encrypted
? EncryptionIntent.FileEncrypted
@@ -150,10 +156,10 @@ export class ArchiveManager {
return this.textFile;
}
downloadData(data: Blob, fileName: string) {
downloadData(data: Blob | ObjectURL, fileName: string) {
const link = document.createElement('a');
link.setAttribute('download', fileName);
link.href = this.hrefForData(data);
link.href = typeof data === 'string' ? data : this.hrefForData(data);
document.body.appendChild(link);
link.click();
link.remove();