Files
convertisseur-images/js/zipExporter.js
T

23 lines
701 B
JavaScript

/**
* Compresse les fichiers en ZIP et déclenche le téléchargement.
* @param {{ name: string, blob: Blob }[]} processedFiles
* @returns {Promise<void>}
*/
export async function downloadAllAsZip(processedFiles) {
const zip = new JSZip();
for (const { name, blob } of processedFiles) {
zip.file(name, blob);
}
const zipBlob = await zip.generateAsync({ type: 'blob' });
const url = URL.createObjectURL(zipBlob);
const a = document.createElement('a');
a.href = url;
a.download = `photos-produits-${new Date().toISOString().slice(0, 10)}.zip`;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
setTimeout(() => URL.revokeObjectURL(url), 10_000);
}