mirror of
https://github.com/Frooodle/Stirling-PDF.git
synced 2025-01-10 00:06:51 +01:00
Better Types
This commit is contained in:
parent
a006937e6e
commit
7186c6c3e0
@ -1,19 +1,31 @@
|
|||||||
import { organizeWaitOperations } from "./organizeWaitOperations.js";
|
import { organizeWaitOperations } from "./organizeWaitOperations.js";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef PDF
|
||||||
|
* @property {string} originalFileName
|
||||||
|
* @property {string} fileName
|
||||||
|
* @property {Uint8Array} buffer
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param {*} operations
|
* @param {JSON} operations
|
||||||
* @param {*} input
|
* @param {PDF|PDF[]} input
|
||||||
* @param {import('./functions.js')} Functions
|
* @param {import('./functions.js')} Functions
|
||||||
* @returns
|
* @returns {}
|
||||||
*/
|
*/
|
||||||
export async function * traverseOperations(operations, input, Functions) {
|
export async function * traverseOperations(operations, input, Functions) {
|
||||||
const waitOperations = organizeWaitOperations(operations);
|
const waitOperations = organizeWaitOperations(operations);
|
||||||
let results = [];
|
/** @type {PDF[]} */ let results = [];
|
||||||
yield* nextOperation(operations, input);
|
yield* nextOperation(operations, input);
|
||||||
console.log("Done2");
|
|
||||||
return results;
|
return results;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {JSON} operations
|
||||||
|
* @param {PDF|PDF[]} input
|
||||||
|
* @returns {undefined}
|
||||||
|
*/
|
||||||
async function * nextOperation(operations, input) {
|
async function * nextOperation(operations, input) {
|
||||||
if(Array.isArray(operations) && operations.length == 0) { // isEmpty
|
if(Array.isArray(operations) && operations.length == 0) { // isEmpty
|
||||||
if(Array.isArray(input)) {
|
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) {
|
async function * computeOperation(operation, input) {
|
||||||
yield "Starting: " + operation.type;
|
yield "Starting: " + operation.type;
|
||||||
switch (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) {
|
async function * nToOne(inputs, operation, callback) {
|
||||||
if(!Array.isArray(inputs)) {
|
inputs = Array.from(inputs); // Convert single values to array, keep arrays as is.
|
||||||
inputs = [inputs];
|
|
||||||
}
|
|
||||||
|
|
||||||
inputs = await callback(inputs);
|
inputs = await callback(inputs);
|
||||||
yield* nextOperation(operation.operations, inputs);
|
yield* nextOperation(operation.operations, inputs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {PDF|PDF[]} input
|
||||||
|
* @param {JSON} operation
|
||||||
|
* @returns {undefined}
|
||||||
|
*/
|
||||||
async function * oneToN(input, operation, callback) {
|
async function * oneToN(input, operation, callback) {
|
||||||
if(Array.isArray(input)) {
|
if(Array.isArray(input)) {
|
||||||
let output = [];
|
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) {
|
async function * nToN(input, operation, callback) {
|
||||||
if(Array.isArray(input)) {
|
if(Array.isArray(input)) {
|
||||||
for (let i = 0; i < input.length; i++) {
|
for (let i = 0; i < input.length; i++) {
|
||||||
|
@ -17,12 +17,7 @@ router.post("/:workflowUuid?", [
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Array.isArray(req.files.files)) {
|
req.files = Array.from(req.files.files); // Convert single values to array, keep arrays as is.
|
||||||
req.files = req.files.files;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
req.files = [req.files.files];
|
|
||||||
}
|
|
||||||
|
|
||||||
const workflow = JSON.parse(req.body.workflow);
|
const workflow = JSON.parse(req.body.workflow);
|
||||||
// TODO: Validate input further (json may fail or not be a valid 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 pdfResults;
|
||||||
let iteration;
|
let iteration;
|
||||||
|
Loading…
Reference in New Issue
Block a user