mirror of
https://github.com/Frooodle/Stirling-PDF.git
synced 2026-02-17 13:52:14 +01:00
Dynamic access to Operators in both front and backend
This commit is contained in:
@@ -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/getOperatorByName";
|
||||
import { getOperatorByName } from "@stirling-pdf/shared-operations/src/workflow/operatorAccessor";
|
||||
import { Operator } from "@stirling-pdf/shared-operations/src/functions";
|
||||
|
||||
import { PdfFile } from "@stirling-pdf/shared-operations/src/wrappers/PdfFile";
|
||||
@@ -11,14 +11,14 @@ import { Action } from "@stirling-pdf/shared-operations/declarations/Action";
|
||||
import { JoiPDFFileSchema } from "@stirling-pdf/shared-operations/src/wrappers/PdfFileJoi";
|
||||
|
||||
router.post("/:func", upload.array("file"), async function(req: Request, res: Response) {
|
||||
handleEndpoint(req, res);
|
||||
await handleEndpoint(req, res);
|
||||
});
|
||||
|
||||
router.post("/:dir/:func", upload.array("file"), async function(req: Request, res: Response) {
|
||||
handleEndpoint(req, res);
|
||||
await handleEndpoint(req, res);
|
||||
});
|
||||
|
||||
function handleEndpoint(req: Request, res: Response) {
|
||||
async function handleEndpoint(req: Request, res: Response) {
|
||||
if(!req.files || req.files.length == 0) {
|
||||
res.status(400).json({error: "no input file(s) were provided"});
|
||||
return;
|
||||
@@ -31,7 +31,8 @@ function handleEndpoint(req: Request, res: Response) {
|
||||
}
|
||||
const pdfFiles: PdfFile[] = validationResults.value;
|
||||
|
||||
const operator = getOperatorByName(req.params.func);
|
||||
const operator = await getOperatorByName(req.params.func);
|
||||
|
||||
if(operator) {
|
||||
const action: Action = {type: req.params.func, values: req.body};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user