Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
557 changes: 514 additions & 43 deletions ddm/core/static/ddm_core/frontend/questionnaire/js/chunk-vendors.js

Large diffs are not rendered by default.

Large diffs are not rendered by default.

38 changes: 3 additions & 35 deletions ddm/core/static/ddm_core/frontend/questionnaire/webpack-stats.json
Original file line number Diff line number Diff line change
@@ -1,38 +1,6 @@
{
"status": "done",
"assets": {
"css/ddm_questionnaire_frontend.css": {
"name": "css/ddm_questionnaire_frontend.css",
"path": "css\\ddm_questionnaire_frontend.css",
"publicPath": "/static/ddm_core/frontend/questionnaire/css/ddm_questionnaire_frontend.css"
},
"js/chunk-vendors.js": {
"name": "js/chunk-vendors.js",
"path": "js\\chunk-vendors.js",
"publicPath": "/static/ddm_core/frontend/questionnaire/js/chunk-vendors.js"
},
"js/chunk-vendors.js.map": {
"name": "js/chunk-vendors.js.map",
"path": "js\\chunk-vendors.js.map",
"publicPath": "/static/ddm_core/frontend/questionnaire/js/chunk-vendors.js.map"
},
"js/ddm_questionnaire_frontend.js": {
"name": "js/ddm_questionnaire_frontend.js",
"path": "js\\ddm_questionnaire_frontend.js",
"publicPath": "/static/ddm_core/frontend/questionnaire/js/ddm_questionnaire_frontend.js"
},
"js/ddm_questionnaire_frontend.js.map": {
"name": "js/ddm_questionnaire_frontend.js.map",
"path": "js\\ddm_questionnaire_frontend.js.map",
"publicPath": "/static/ddm_core/frontend/questionnaire/js/ddm_questionnaire_frontend.js.map"
}
},
"chunks": {
"ddm_questionnaire_frontend": [
"js/chunk-vendors.js",
"css/ddm_questionnaire_frontend.css",
"js/ddm_questionnaire_frontend.js"
]
},
"status": "compile",
"assets": {},
"chunks": {},
"publicPath": "/static/ddm_core/frontend/questionnaire/"
}
859 changes: 798 additions & 61 deletions ddm/core/static/ddm_core/frontend/uploader/js/chunk-vendors.js

Large diffs are not rendered by default.

1,407 changes: 1,405 additions & 2 deletions ddm/core/static/ddm_core/frontend/uploader/js/ddm_uploader_frontend.js

Large diffs are not rendered by default.

28 changes: 6 additions & 22 deletions ddm/core/static/ddm_core/frontend/uploader/webpack-stats.json
Original file line number Diff line number Diff line change
@@ -1,60 +1,44 @@
{
"status": "done",
"assets": {
"css/ddm_uploader_frontend.css": {
"name": "css/ddm_uploader_frontend.css",
"path": "css\\ddm_uploader_frontend.css",
"publicPath": "/static/ddm_core/frontend/uploader/css/ddm_uploader_frontend.css"
},
"js/chunk-vendors.js": {
"name": "js/chunk-vendors.js",
"path": "js\\chunk-vendors.js",
"path": "js/chunk-vendors.js",
"publicPath": "/static/ddm_core/frontend/uploader/js/chunk-vendors.js"
},
"js/chunk-vendors.js.map": {
"name": "js/chunk-vendors.js.map",
"path": "js\\chunk-vendors.js.map",
"publicPath": "/static/ddm_core/frontend/uploader/js/chunk-vendors.js.map"
},
"js/ddm_uploader_frontend.js": {
"name": "js/ddm_uploader_frontend.js",
"path": "js\\ddm_uploader_frontend.js",
"path": "js/ddm_uploader_frontend.js",
"publicPath": "/static/ddm_core/frontend/uploader/js/ddm_uploader_frontend.js"
},
"js/ddm_uploader_frontend.js.map": {
"name": "js/ddm_uploader_frontend.js.map",
"path": "js\\ddm_uploader_frontend.js.map",
"publicPath": "/static/ddm_core/frontend/uploader/js/ddm_uploader_frontend.js.map"
},
"locale/de.json": {
"name": "locale/de.json",
"path": "locale\\de.json",
"path": "locale/de.json",
"publicPath": "/static/ddm_core/frontend/uploader/locale/de.json",
"sourceFilename": "src/locales/de.json"
},
"locale/en.json": {
"name": "locale/en.json",
"path": "locale\\en.json",
"path": "locale/en.json",
"publicPath": "/static/ddm_core/frontend/uploader/locale/en.json",
"sourceFilename": "src/locales/en.json"
},
"locale/fr.json": {
"name": "locale/fr.json",
"path": "locale\\fr.json",
"path": "locale/fr.json",
"publicPath": "/static/ddm_core/frontend/uploader/locale/fr.json",
"sourceFilename": "src/locales/fr.json"
},
"locale/it.json": {
"name": "locale/it.json",
"path": "locale\\it.json",
"path": "locale/it.json",
"publicPath": "/static/ddm_core/frontend/uploader/locale/it.json",
"sourceFilename": "src/locales/it.json"
}
},
"chunks": {
"ddm_uploader_frontend": [
"js/chunk-vendors.js",
"css/ddm_uploader_frontend.css",
"js/ddm_uploader_frontend.js"
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,91 @@ import {BlueprintExtractionOutcome} from "@uploader/classes/BlueprintExtractionO
import {ProcessingError} from "@uploader/types/ProcessingError";
import {processContent} from "@uploader/composables/useFileProcessor/contentParsers";


/* Currently, the file extraction logic will match file names using regex patterns.
If there are multiple files matching a pattern, all will be processed and the extracted
fields will be aggregated in the blueprint outcome. For example, for the following file
strucutre:
- archive.zip
- data1.json
- folder1/
- data1.json

if the given file path is "data1.json", both files will be processed and their extracted
fields combined in the blueprint outcome.

This behavior is perserved for the nested zip files as well. For example:
- archive.zip
- data1.json
- folder1/
- data1.json
- nested.zip
- data1.json

In this case, all three data1.json files will be processed.
*/

/* max depth of nested ZIP files we will process. */
const MAX_NESTED_ZIP_DEPTH = 3;

type ExtractedZipFile = {
fullPath: string;
entry: JSZip.JSZipObject;
};

function normalizePath(path: string): string {
return path.replace(/^\.\/+/, '').replace(/\\/g, '/');
}

async function collectZipEntries(
zip: JSZip,
generalErrors: ProcessingError[],
depth = 0,
parentPath = ''
): Promise<ExtractedZipFile[]> {
const entries: ExtractedZipFile[] = [];

for (const entry of Object.values(zip.files)) {
if (entry.dir) {
continue;
}

const normalizedName = normalizePath(entry.name);
const parentBase = parentPath.split('/').filter(Boolean).pop();
const entryPath = parentPath
? `${parentPath}/${normalizedName}`
: normalizedName;

if (entry.name.toLowerCase().endsWith('.zip') && depth < MAX_NESTED_ZIP_DEPTH) {
try {
const nestedBuffer = await entry.async('arraybuffer');
const nestedZip = await JSZip.loadAsync(nestedBuffer);

// Use the ZIP's actual filename as the prefix
const nestedParent = parentPath
? `${parentPath}/${normalizedName}`
: normalizedName;

const nestedEntries = await collectZipEntries(
nestedZip,
generalErrors,
depth + 1,
nestedParent.replace(/\.zip$/i, '.zip')
);

entries.push(...nestedEntries);
continue;
} catch (error) {
registerGeneralError(generalErrors, ERROR_CATALOG.ZIP_READ_FAIL, { error });
}
}

entries.push({ fullPath: entryPath, entry });
}

return entries;
}

/**
* Processes a ZIP archive by extracting and processing matching files.
*
Expand Down Expand Up @@ -49,6 +134,9 @@ export async function handleZipFile(
return;
}

const extractedFiles = await collectZipEntries(zip, generalErrors);
const availableFiles = Array.from(new Set(extractedFiles.map(entry => entry.fullPath)));

for (const blueprint of blueprints) {
let re: RegExp;
try {
Expand All @@ -58,17 +146,16 @@ export async function handleZipFile(
continue;
}

const matchingFiles = zip.file(re);
const matchingFiles = extractedFiles.filter(entry => re.test(entry.fullPath));
if (matchingFiles.length === 0) {
const availableFiles = Object.keys(zip.files);
const errorContext = { regexPath: blueprint.regex_path, availableFiles: availableFiles }
blueprintOutcomeMap[blueprint.id].registerError(ERROR_CATALOG.NO_FILE_MATCH, errorContext);
continue;
}

for (const zipEntry of matchingFiles) {
try {
const content = await zipEntry.async("string");
const content = await zipEntry.entry.async("string");
processContent(content, blueprint, blueprintOutcomeMap);
} catch (error) {
blueprintOutcomeMap[blueprint.id].registerError(ERROR_CATALOG.FILE_PROCESSING_FAIL_GENERAL, {error: error});
Expand Down
6 changes: 6 additions & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.