fix: pictures download button

fix #1225
This commit is contained in:
imperosol
2025-11-07 14:30:11 +01:00
parent 9c64dae7fe
commit 9a311d8cee
5 changed files with 18 additions and 14 deletions

View File

@@ -5,12 +5,13 @@ import type { PictureSchema } from "#openapi";
document.addEventListener("alpine:init", () => {
Alpine.data("pictures_download", () => ({
isDownloading: false,
downloadPictures: [] as PictureSchema[],
async downloadZip() {
this.isDownloading = true;
const bar = this.$refs.progress;
bar.value = 0;
bar.max = this.pictures.length;
bar.max = this.downloadPictures.length;
const incrementProgressBar = (_total: number): undefined => {
bar.value++;
@@ -29,7 +30,7 @@ document.addEventListener("alpine:init", () => {
const zipWriter = new ZipWriter(await fileHandle.createWritable());
await Promise.all(
this.pictures.map((p: PictureSchema) => {
this.downloadPictures.map(async (p: PictureSchema) => {
const imgName = `${p.album}/IMG_${p.date.replace(/[:\-]/g, "_")}${p.name.slice(p.name.lastIndexOf("."))}`;
return zipWriter.add(imgName, new HttpReader(p.full_size_url), {
level: 9,

View File

@@ -57,5 +57,9 @@ document.addEventListener("alpine:init", () => {
}
this.loading = false;
},
allPictures(): PictureSchema[] {
return this.albums.flatMap((album: Album) => album.pictures);
},
}));
});