Skip to content
Snippets Groups Projects
Unverified Commit 10633fc2 authored by Bekerle, Patrizio's avatar Bekerle, Patrizio :fire:
Browse files

Prevent duplicate file names in ZIP file (VPU/Middleware/API#40)

parent f1fce191
No related branches found
No related tags found
No related merge requests found
Pipeline #9592 passed with warnings
......@@ -44,3 +44,14 @@ export const getDataURIContentType = (dataURI) => {
return dataURI.substring(5, base64Index);
};
export const baseName = (str) =>
{
let base = String(str).substring(str.lastIndexOf('/') + 1);
if(base.lastIndexOf(".") !== -1) {
base = base.substring(0, base.lastIndexOf("."));
}
return base;
};
......@@ -102,12 +102,19 @@ class SignaturePdfUpload extends VPUSignatureLitElement {
// see: https://stuk.github.io/jszip/
let zip = new JSZip();
const that = this;
let fileNames = [];
// add all signed pdf files
this.files.forEach((file) => {
console.log(file);
// TODO: check for duplicate file names
zip.file(file.fileName, utils.getPDFFileBase64Content(file), {base64: true});
let fileName = file.fileName;
//
if (fileNames.indexOf(fileName) !== -1) {
fileName = utils.baseName(fileName) + "-" + Math.random().toString(36).substring(7) + ".pdf";
}
fileNames.push(fileName);
zip.file(fileName, utils.getPDFFileBase64Content(file), {base64: true});
});
zip.generateAsync({type:"blob"})
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment