handles zips in zip correctly
This commit is contained in:
Generated
+22
-6
@@ -3,9 +3,7 @@
|
||||
<component name="ChangeListManager">
|
||||
<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$/src/lib/components/AttachmentPreview.svelte" beforeDir="false" afterPath="$PROJECT_DIR$/src/lib/components/AttachmentPreview.svelte" 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" />
|
||||
<change beforePath="$PROJECT_DIR$/src/lib/zip-processing.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/lib/zip-processing.ts" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
@@ -51,7 +49,7 @@
|
||||
<option name="presentableId" value="Default" />
|
||||
<updated>1781169139290</updated>
|
||||
<workItem from="1781169141138" duration="309000" />
|
||||
<workItem from="1781251694220" duration="11612000" />
|
||||
<workItem from="1781251694220" duration="12340000" />
|
||||
</task>
|
||||
<task id="LOCAL-00001" summary="adapts styling of rvg.legal">
|
||||
<option name="closed" value="true" />
|
||||
@@ -101,7 +99,23 @@
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1781261986439</updated>
|
||||
</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 />
|
||||
</component>
|
||||
<component name="TypeScriptGeneratedFilesManager">
|
||||
@@ -117,7 +131,9 @@
|
||||
<MESSAGE value="parses xjustiz and orders attachments" />
|
||||
<MESSAGE value="renders preview of zips" />
|
||||
<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 name="XDebuggerManager">
|
||||
<breakpoint-manager>
|
||||
|
||||
@@ -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 {
|
||||
if (orderedAttachments.length > 0) {
|
||||
archives.push({
|
||||
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,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 {
|
||||
|
||||
Reference in New Issue
Block a user