handles zips in zip correctly

This commit is contained in:
2026-06-12 13:42:48 +02:00
parent 33f0804c53
commit b400bf2f7c
3 changed files with 51 additions and 17 deletions
+26 -8
View File
@@ -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<ProcessedZipArchive> => {
const archiveBytes = new Uint8Array(await file.arrayBuffer());
const extractZipEntries = async (archiveBytes: Uint8Array, fallbackName: string): Promise<ProcessedZipArchive[]> => {
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<ProcessedZipArchive
continue;
}
if (isZipArchive(path)) {
const childArchives = await extractZipEntries(data, baseName);
nestedArchives.push(...childArchives);
continue;
}
if (isPdf(path)) {
attachments.push({
name: baseName,
@@ -229,10 +236,21 @@ export const extractZipArchive = async (file: File): Promise<ProcessedZipArchive
const documentNames = xjustizNachrichtXml ? getXJustizDocumentNames(xjustizNachrichtXml) : [];
const orderedAttachments = orderAttachmentsByDocumentNames(attachments, documentNames);
const archiveName = documentNames[0] ? getBaseName(documentNames[0]) : file.name;
const archiveName = documentNames[0] ? getBaseName(documentNames[0]) : fallbackName;
const archives: ProcessedZipArchive[] = [];
return {
name: archiveName,
attachments: orderedAttachments
};
if (orderedAttachments.length > 0) {
archives.push({
name: archiveName,
attachments: orderedAttachments,
});
}
return [...archives, ...nestedArchives];
};
export const extractZipArchives = async (file: File): Promise<ProcessedZipArchive[]> => {
const archiveBytes = new Uint8Array(await file.arrayBuffer());
return extractZipEntries(archiveBytes, file.name);
};
+3 -3
View File
@@ -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 {