Error handeling

(async requests, prevent server from crashing on user-error)
This commit is contained in:
Felix Kaspar
2023-11-21 00:12:35 +01:00
parent 90f0ee0bc5
commit 498f287d57
5 changed files with 83 additions and 94 deletions

View File

@@ -1,6 +1,6 @@
import { Operator } from "../functions";
// TODO: Import other Operators
// TODO: Import other Operators (could make this dynamic?)
import { Impose } from "../functions/impose";
export const Operators = {
Impose: Impose
@@ -23,4 +23,9 @@ export function getOperatorByName(name: string): typeof Operator {
});
return foundClass;
}
export function listOperatorNames(): string[] {
// TODO: Implement this
return
}

View File

@@ -42,78 +42,13 @@ export async function traverseOperations(operations: Action[], input: PdfFile[],
case "wait":
const waitOperation = waitOperations[(action as WaitAction).values.id];
if(Array.isArray(input)) {
waitOperation.input.concat(input); // TODO: May have unexpected concequences. Needs further testing!
}
else {
waitOperation.input.push(input);
}
waitOperation.input.concat(input); // TODO: May have unexpected concequences. Needs further testing!
waitOperation.waitCount--;
if(waitOperation.waitCount == 0 && waitOperation.doneOperation.actions) {
await nextOperation(waitOperation.doneOperation.actions, waitOperation.input, progressCallback);
}
break;
/*case "extract":
yield* nToN(input, action, async (input) => {
const newPdf = await Operations.extractPages({file: input, pageIndexes: action.values["pageIndexes"]});
return newPdf;
});
break;
case "impose":
let impose = new Impose(action);
input = await impose.run(input, progressCallback);
await nextOperation(action.actions, input, progressCallback);
break;
case "merge":
yield* nToOne(input, action, async (inputs) => {
const newPdf = await Operations.mergePDFs({files: inputs});
return newPdf;
});
break;
case "removeBlankPages":
yield* nToN(input, action, async (input) => {
const newPdf = await Operations.removeBlankPages({file: input, whiteThreashold: action.values["whiteThreashold"]});
return newPdf;
});
break;
case "rotate":
yield* nToN(input, action, async (input) => {
const newPdf = await Operations.rotatePages({file: input, rotation: action.values["rotation"]});
return newPdf;
});
break;
case "sortPagesWithPreset":
yield* nToN(input, action, async (input) => {
const newPdf = await Operations.arrangePages({file: input, arrangementConfig: action.values["arrangementConfig"]});
return newPdf;
});
break;
case "split":
// TODO: A split might break the done condition, it may count multiple times. Needs further testing!
yield* oneToN(input, action, async (input) => {
const splitResult = await Operations.splitPdfByIndex({file: input, pageIndexes: action.values["splitAfterPageArray"]});
for (let j = 0; j < splitResult.length; j++) {
splitResult[j].filename = splitResult[j].filename + "_split" + j;
}
return splitResult;
});
break;
case "splitOn":
yield* oneToN(input, action, async (input) => {
const splitResult = await Operations.splitPagesByPreset({file: input, type: action.values["type"], whiteThreashold: action.values["whiteThreashold"]});
for (let j = 0; j < splitResult.length; j++) {
splitResult[j].filename = splitResult[j].filename + "_split" + j;
}
return splitResult;
});
break;
case "updateMetadata":
yield* nToN(input, action, async (input) => {
const newPdf = await Operations.updateMetadata({file: input, ...action.values["metadata"]});
return newPdf;
});
break;*/
default:
const operator = getOperatorByName(action.type);
if(operator) {