From 3304f32ef050b50b1f63fd663ee6e74452b40d6a Mon Sep 17 00:00:00 2001 From: Sli Date: Sun, 28 Jul 2024 23:53:18 +0200 Subject: [PATCH] Add image download progress bar and fix output name of pictures --- core/templates/core/user_pictures.jinja | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/core/templates/core/user_pictures.jinja b/core/templates/core/user_pictures.jinja index 522200d4..871ab900 100644 --- a/core/templates/core/user_pictures.jinja +++ b/core/templates/core/user_pictures.jinja @@ -21,6 +21,7 @@
{% if can_edit(profile, user) %} + {% endif %} {% for album, pictures in albums|items %}

{{ album }}

@@ -59,14 +60,21 @@ async function download(url) { let zip = new JSZip(); - let size = 0; let pictures = await (await fetch(url)).json(); + let progressBar = document.getElementById("download_progress"); + let picturesDownloaded = 0; + let button = document.getElementById("download"); + + button.disabled = true; + progressBar.value = picturesDownloaded; + progressBar.hidden = false; + pictures.forEach(async (picture) => { - size += picture.size; zip.file( - "IMG_" + picture.date + picture.name.slice(picture.name.lastIndexOf(".")), + "IMG_" + picture.date.replaceAll(":", "_").replaceAll("-", "_") + picture.name.slice(picture.name.lastIndexOf(".")), new Promise(function (resolve, reject) { JSZipUtils.getBinaryContent(picture.full_size_url, (err, data) => { + progressBar.value = picturesDownloaded++ * 100 / (pictures.length - 1); if (err) { reject(err); return; @@ -96,6 +104,9 @@ .on("error", (err) => console.error(err)) .on("end", () => writeStream.close()) .resume(); + + button.disabled = false; + progressBar.hidden = true; }