diff --git a/client/package.json b/client/package.json index 0a1cfe43b..5b2440fa1 100644 --- a/client/package.json +++ b/client/package.json @@ -59,6 +59,7 @@ "css-element-queries": "^1.2.3", "exceljs": "1.15.0", "file-saver": "^2.0.2", + "jszip": "^3.5.0", "lz4js": "^0.2.0", "material-icon-font": "git+https://github.com/petergng/materialIconFont.git", "moment": "^2.24.0", diff --git a/client/src/app/core/core-services/http.service.ts b/client/src/app/core/core-services/http.service.ts index fbf1f01fc..8ae0f375d 100644 --- a/client/src/app/core/core-services/http.service.ts +++ b/client/src/app/core/core-services/http.service.ts @@ -273,4 +273,26 @@ export class HttpService { public async delete(path: string, data?: any, queryParams?: QueryParams, header?: HttpHeaders): Promise { return await this.send(path, HTTPMethod.DELETE, data, queryParams, header); } + + /** + * Retrieves a binary file from the url and returns a base64 value + * + * @param url file url + * @returns a promise with a base64 string + */ + public async downloadAsBase64(url: string): Promise { + return new Promise(async (resolve, reject) => { + const headers = new HttpHeaders(); + const file = await this.get(url, {}, {}, headers, 'blob'); + const reader = new FileReader(); + reader.readAsDataURL(file); + reader.onload = () => { + const resultStr: string = reader.result as string; + resolve(resultStr.split(',')[1]); + }; + reader.onerror = error => { + reject(error); + }; + }); + } } diff --git a/client/src/app/core/pdf-services/pdf-document.service.ts b/client/src/app/core/pdf-services/pdf-document.service.ts index 30f3c69d1..2de10d19d 100644 --- a/client/src/app/core/pdf-services/pdf-document.service.ts +++ b/client/src/app/core/pdf-services/pdf-document.service.ts @@ -1,4 +1,3 @@ -import { HttpHeaders } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { MatSnackBar } from '@angular/material/snack-bar'; @@ -100,7 +99,7 @@ export class PdfDocumentService { ); const promises = fontPathList.map(fontPath => { - return this.convertUrlToBase64(fontPath).then(base64 => { + return this.httpService.downloadAsBase64(fontPath).then(base64 => { return { [fontPath.split('/').pop()]: base64 }; @@ -117,29 +116,6 @@ export class PdfDocumentService { return vfs; } - /** - * Retrieves a binary file from the url and returns a base64 value - * - * @param url file url - * @returns a promise with a base64 string - */ - private async convertUrlToBase64(url: string): Promise { - return new Promise((resolve, reject) => { - const headers = new HttpHeaders(); - this.httpService.get(url, {}, {}, headers, 'blob').then(file => { - const reader = new FileReader(); - reader.readAsDataURL(file); - reader.onload = () => { - const resultStr: string = reader.result as string; - resolve(resultStr.split(',')[1]); - }; - reader.onerror = error => { - reject(error); - }; - }); - }); - } - /** * Returns the name of a font from the value of the given * config variable. @@ -665,7 +641,7 @@ export class PdfDocumentService { } if (!vfs[url]) { - const base64 = await this.convertUrlToBase64(url); + const base64 = await this.httpService.downloadAsBase64(url); vfs[url] = base64; } } diff --git a/client/src/app/core/repositories/mediafiles/mediafile-repository.service.ts b/client/src/app/core/repositories/mediafiles/mediafile-repository.service.ts index 7a2c7d309..c48b20263 100644 --- a/client/src/app/core/repositories/mediafiles/mediafile-repository.service.ts +++ b/client/src/app/core/repositories/mediafiles/mediafile-repository.service.ts @@ -2,6 +2,8 @@ import { HttpHeaders } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { TranslateService } from '@ngx-translate/core'; +import { saveAs } from 'file-saver'; +import * as JSZip from 'jszip'; import { BehaviorSubject, Observable } from 'rxjs'; import { first, map } from 'rxjs/operators'; @@ -136,6 +138,18 @@ export class MediafileRepositoryService extends BaseIsListOfSpeakersContentObjec return this.httpService.post('/rest/mediafiles/mediafile/', file, {}, emptyHeader); } + public async downloadArchive(archiveName: string, files: ViewMediafile[]): Promise { + const zip = new JSZip(); + for (const file of files) { + if (!file.is_directory) { + const base64Data = await this.httpService.downloadAsBase64(file.url); + zip.file(file.filename, base64Data, { base64: true }); + } + } + const archive = await zip.generateAsync({ type: 'blob' }); + saveAs(archive, archiveName); + } + public getDirectoryBehaviorSubject(): BehaviorSubject { return this.directoryBehaviorSubject; } diff --git a/client/src/app/site/mediafiles/components/mediafile-list/mediafile-list.component.html b/client/src/app/site/mediafiles/components/mediafile-list/mediafile-list.component.html index 812baa65e..c0b1cf11c 100644 --- a/client/src/app/site/mediafiles/components/mediafile-list/mediafile-list.component.html +++ b/client/src/app/site/mediafiles/components/mediafile-list/mediafile-list.component.html @@ -229,12 +229,20 @@
+
+