diff --git a/public/traverseOperations.js b/public/traverseOperations.js index a831c2f9..48b71720 100644 --- a/public/traverseOperations.js +++ b/public/traverseOperations.js @@ -1,19 +1,31 @@ import { organizeWaitOperations } from "./organizeWaitOperations.js"; +/** + * @typedef PDF + * @property {string} originalFileName + * @property {string} fileName + * @property {Uint8Array} buffer + */ + /** * - * @param {*} operations - * @param {*} input + * @param {JSON} operations + * @param {PDF|PDF[]} input * @param {import('./functions.js')} Functions - * @returns + * @returns {} */ export async function * traverseOperations(operations, input, Functions) { const waitOperations = organizeWaitOperations(operations); - let results = []; + /** @type {PDF[]} */ let results = []; yield* nextOperation(operations, input); - console.log("Done2"); return results; + /** + * + * @param {JSON} operations + * @param {PDF|PDF[]} input + * @returns {undefined} + */ async function * nextOperation(operations, input) { if(Array.isArray(operations) && operations.length == 0) { // isEmpty if(Array.isArray(input)) { @@ -33,6 +45,12 @@ export async function * traverseOperations(operations, input, Functions) { } } + /** + * + * @param {JSON} operation + * @param {PDF|PDF[]} input + * @returns {undefined} + */ async function * computeOperation(operation, input) { yield "Starting: " + operation.type; switch (operation.type) { @@ -135,15 +153,25 @@ export async function * traverseOperations(operations, input, Functions) { } } + /** + * + * @param {PDF|PDF[]} input + * @param {JSON} operation + * @returns {undefined} + */ async function * nToOne(inputs, operation, callback) { - if(!Array.isArray(inputs)) { - inputs = [inputs]; - } + inputs = Array.from(inputs); // Convert single values to array, keep arrays as is. inputs = await callback(inputs); yield* nextOperation(operation.operations, inputs); } + /** + * + * @param {PDF|PDF[]} input + * @param {JSON} operation + * @returns {undefined} + */ async function * oneToN(input, operation, callback) { if(Array.isArray(input)) { let output = []; @@ -158,6 +186,12 @@ export async function * traverseOperations(operations, input, Functions) { } } + /** + * + * @param {PDF|PDF[]} input + * @param {JSON} operation + * @returns {undefined} + */ async function * nToN(input, operation, callback) { if(Array.isArray(input)) { for (let i = 0; i < input.length; i++) { diff --git a/routes/api/workflow.js b/routes/api/workflow.js index 499484d4..43a931b2 100644 --- a/routes/api/workflow.js +++ b/routes/api/workflow.js @@ -17,12 +17,7 @@ router.post("/:workflowUuid?", [ return; } - if(Array.isArray(req.files.files)) { - req.files = req.files.files; - } - else { - req.files = [req.files.files]; - } + req.files = Array.from(req.files.files); // Convert single values to array, keep arrays as is. const workflow = JSON.parse(req.body.workflow); // TODO: Validate input further (json may fail or not be a valid workflow) @@ -80,7 +75,7 @@ router.post("/:workflowUuid?", [ } }); - const traverse = traverseOperations(workflow.operations, inputs); + const traverse = traverseOperations(workflow.operations, inputs, Functions); let pdfResults; let iteration;