update frontend to use split operators

This commit is contained in:
Felix Kaspar
2024-07-14 00:53:57 +02:00
parent 4056d87335
commit 40ed0f68db
3 changed files with 31 additions and 35 deletions

View File

@@ -2,7 +2,7 @@ import express, { Request, Response } from "express";
const router = express.Router();
import multer from "multer";
const upload = multer();
import { getOperatorByName } from "@stirling-pdf/shared-operations/src/workflow/operatorAccessor";
import { getOperatorByName, getSchemaByName } from "@stirling-pdf/shared-operations/src/workflow/operatorAccessor";
import { PdfFile } from "@stirling-pdf/shared-operations/src/wrappers/PdfFile";
import { respondWithPdfFiles } from "../../utils/response-utils";
@@ -30,19 +30,26 @@ async function handleEndpoint(req: Request, res: Response) {
}
const pdfFiles: PdfFile[] = validationResults.value;
const operator = await getOperatorByName(req.params.func);
const schema = await getSchemaByName(req.params.func);
if(operator) {
if(schema) {
const action: Action = {type: req.params.func, values: req.body};
const validationResults = operator.schema.validate({input: pdfFiles, values: action.values});
const validationResults = schema.schema.validate({input: pdfFiles, values: action.values});
if(validationResults.error) {
res.status(400).json({error: "Value validation failed", details: validationResults.error.message});
}
else {
action.values = validationResults.value.values;
const operation = new operator(action);
const Operator = await getOperatorByName(req.params.func);
if(!Operator) {
res.status(400).json({error: `the operator of type ${req.params.func} does not exist`});
return
}
const operation = new Operator(action);
operation.run(validationResults.value.input, (progress) => {}).then(pdfFiles => {
respondWithPdfFiles(res, pdfFiles, req.params.func + "_result");
});