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
+22 -6
View File
@@ -3,9 +3,7 @@
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="89f9fc3a-63ad-41cb-8d25-f07df352eb98" name="Changes" comment=""> <list default="true" id="89f9fc3a-63ad-41cb-8d25-f07df352eb98" name="Changes" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/lib/components/AttachmentPreview.svelte" beforeDir="false" afterPath="$PROJECT_DIR$/src/lib/components/AttachmentPreview.svelte" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/lib/zip-processing.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/lib/zip-processing.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/lib/components/ProcessedZipArchiveEditor.svelte" beforeDir="false" afterPath="$PROJECT_DIR$/src/lib/components/ProcessedZipArchiveEditor.svelte" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/routes/+page.svelte" beforeDir="false" afterPath="$PROJECT_DIR$/src/routes/+page.svelte" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -51,7 +49,7 @@
<option name="presentableId" value="Default" /> <option name="presentableId" value="Default" />
<updated>1781169139290</updated> <updated>1781169139290</updated>
<workItem from="1781169141138" duration="309000" /> <workItem from="1781169141138" duration="309000" />
<workItem from="1781251694220" duration="11612000" /> <workItem from="1781251694220" duration="12340000" />
</task> </task>
<task id="LOCAL-00001" summary="adapts styling of rvg.legal"> <task id="LOCAL-00001" summary="adapts styling of rvg.legal">
<option name="closed" value="true" /> <option name="closed" value="true" />
@@ -101,7 +99,23 @@
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1781261986439</updated> <updated>1781261986439</updated>
</task> </task>
<option name="localTasksCounter" value="7" /> <task id="LOCAL-00007" summary="renders thumbnails">
<option name="closed" value="true" />
<created>1781263980882</created>
<option name="number" value="00007" />
<option name="presentableId" value="LOCAL-00007" />
<option name="project" value="LOCAL" />
<updated>1781263980882</updated>
</task>
<task id="LOCAL-00008" summary="ignores mac special folders">
<option name="closed" value="true" />
<created>1781264183729</created>
<option name="number" value="00008" />
<option name="presentableId" value="LOCAL-00008" />
<option name="project" value="LOCAL" />
<updated>1781264183729</updated>
</task>
<option name="localTasksCounter" value="9" />
<servers /> <servers />
</component> </component>
<component name="TypeScriptGeneratedFilesManager"> <component name="TypeScriptGeneratedFilesManager">
@@ -117,7 +131,9 @@
<MESSAGE value="parses xjustiz and orders attachments" /> <MESSAGE value="parses xjustiz and orders attachments" />
<MESSAGE value="renders preview of zips" /> <MESSAGE value="renders preview of zips" />
<MESSAGE value="design anpassungen" /> <MESSAGE value="design anpassungen" />
<option name="LAST_COMMIT_MESSAGE" value="design anpassungen" /> <MESSAGE value="renders thumbnails" />
<MESSAGE value="ignores mac special folders" />
<option name="LAST_COMMIT_MESSAGE" value="ignores mac special folders" />
</component> </component>
<component name="XDebuggerManager"> <component name="XDebuggerManager">
<breakpoint-manager> <breakpoint-manager>
+24 -6
View File
@@ -56,6 +56,8 @@ const isPdf = (path: string) => getExtension(path) === ".pdf";
const isImage = (path: string) => IMAGE_EXTENSIONS.has(getExtension(path)); 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 normalizeKey = (value: string) => value.replaceAll("\\", "/").toLowerCase().trim();
const isMacMetadataEntry = (path: string) => { const isMacMetadataEntry = (path: string) => {
@@ -188,11 +190,10 @@ const orderAttachmentsByDocumentNames = (attachments: ZipAttachment[], documentN
return orderedAttachments; return orderedAttachments;
}; };
export const extractZipArchive = async (file: File): Promise<ProcessedZipArchive> => { const extractZipEntries = async (archiveBytes: Uint8Array, fallbackName: string): Promise<ProcessedZipArchive[]> => {
const archiveBytes = new Uint8Array(await file.arrayBuffer());
const files = await unzipArchive(archiveBytes); const files = await unzipArchive(archiveBytes);
const attachments: ZipAttachment[] = []; const attachments: ZipAttachment[] = [];
const nestedArchives: ProcessedZipArchive[] = [];
let xjustizNachrichtXml: Uint8Array | null = null; let xjustizNachrichtXml: Uint8Array | null = null;
for (const [path, data] of Object.entries(files)) { for (const [path, data] of Object.entries(files)) {
@@ -207,6 +208,12 @@ export const extractZipArchive = async (file: File): Promise<ProcessedZipArchive
continue; continue;
} }
if (isZipArchive(path)) {
const childArchives = await extractZipEntries(data, baseName);
nestedArchives.push(...childArchives);
continue;
}
if (isPdf(path)) { if (isPdf(path)) {
attachments.push({ attachments.push({
name: baseName, name: baseName,
@@ -229,10 +236,21 @@ export const extractZipArchive = async (file: File): Promise<ProcessedZipArchive
const documentNames = xjustizNachrichtXml ? getXJustizDocumentNames(xjustizNachrichtXml) : []; const documentNames = xjustizNachrichtXml ? getXJustizDocumentNames(xjustizNachrichtXml) : [];
const orderedAttachments = orderAttachmentsByDocumentNames(attachments, documentNames); 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 { if (orderedAttachments.length > 0) {
archives.push({
name: archiveName, name: archiveName,
attachments: orderedAttachments 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 Card from "$lib/components/Card.svelte";
import ProcessedZipArchiveEditor from "$lib/components/ProcessedZipArchiveEditor.svelte"; import ProcessedZipArchiveEditor from "$lib/components/ProcessedZipArchiveEditor.svelte";
import ZipDropzone from "$lib/components/ZipDropzone.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"; const THUMBNAIL_WIDTH_STORAGE_KEY = "thumbnailWidth";
@@ -49,8 +49,8 @@
pendingZipCount += 1; pendingZipCount += 1;
try { try {
const processedZipArchive = await extractZipArchive(file); const processedZipArchives = await extractZipArchives(file);
processedZipFiles = [...processedZipFiles, processedZipArchive]; processedZipFiles = [...processedZipFiles, ...processedZipArchives];
} catch (error) { } catch (error) {
console.error(`Failed to process ${file.name}`, error); console.error(`Failed to process ${file.name}`, error);
} finally { } finally {