From b400bf2f7cc79b62e89bf7c15ac7d366a54db393 Mon Sep 17 00:00:00 2001 From: rehlert Date: Fri, 12 Jun 2026 13:42:48 +0200 Subject: [PATCH] handles zips in zip correctly --- .idea/workspace.xml | 28 ++++++++++++++++++++++------ src/lib/zip-processing.ts | 34 ++++++++++++++++++++++++++-------- src/routes/+page.svelte | 6 +++--- 3 files changed, 51 insertions(+), 17 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 1dd26a5..d430727 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -3,9 +3,7 @@ - - - + @@ -117,7 +131,9 @@ - diff --git a/src/lib/zip-processing.ts b/src/lib/zip-processing.ts index d1e4768..8ff3c8d 100644 --- a/src/lib/zip-processing.ts +++ b/src/lib/zip-processing.ts @@ -56,6 +56,8 @@ const isPdf = (path: string) => getExtension(path) === ".pdf"; const isImage = (path: string) => IMAGE_EXTENSIONS.has(getExtension(path)); +const isZipArchive = (path: string) => getExtension(path) === ".zip"; + const normalizeKey = (value: string) => value.replaceAll("\\", "/").toLowerCase().trim(); const isMacMetadataEntry = (path: string) => { @@ -188,11 +190,10 @@ const orderAttachmentsByDocumentNames = (attachments: ZipAttachment[], documentN return orderedAttachments; }; -export const extractZipArchive = async (file: File): Promise => { - const archiveBytes = new Uint8Array(await file.arrayBuffer()); +const extractZipEntries = async (archiveBytes: Uint8Array, fallbackName: string): Promise => { const files = await unzipArchive(archiveBytes); - const attachments: ZipAttachment[] = []; + const nestedArchives: ProcessedZipArchive[] = []; let xjustizNachrichtXml: Uint8Array | null = null; for (const [path, data] of Object.entries(files)) { @@ -207,6 +208,12 @@ export const extractZipArchive = async (file: File): Promise 0) { + archives.push({ + name: archiveName, + attachments: orderedAttachments, + }); + } + + return [...archives, ...nestedArchives]; +}; + +export const extractZipArchives = async (file: File): Promise => { + const archiveBytes = new Uint8Array(await file.arrayBuffer()); + + return extractZipEntries(archiveBytes, file.name); }; diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 9e52527..42c6017 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -3,7 +3,7 @@ import Card from "$lib/components/Card.svelte"; import ProcessedZipArchiveEditor from "$lib/components/ProcessedZipArchiveEditor.svelte"; import ZipDropzone from "$lib/components/ZipDropzone.svelte"; - import { extractZipArchive, type ProcessedZipArchive } from "$lib/zip-processing"; + import { extractZipArchives, type ProcessedZipArchive } from "$lib/zip-processing"; const THUMBNAIL_WIDTH_STORAGE_KEY = "thumbnailWidth"; @@ -49,8 +49,8 @@ pendingZipCount += 1; try { - const processedZipArchive = await extractZipArchive(file); - processedZipFiles = [...processedZipFiles, processedZipArchive]; + const processedZipArchives = await extractZipArchives(file); + processedZipFiles = [...processedZipFiles, ...processedZipArchives]; } catch (error) { console.error(`Failed to process ${file.name}`, error); } finally {