Dynamic access to Operators in both front and backend
This commit is contained in:
@@ -6,6 +6,7 @@ const PORT = 8000;
|
||||
|
||||
// server-node: backend api
|
||||
import api from "./routes/api/api-controller";
|
||||
import { listOperatorNames } from "@stirling-pdf/shared-operations/src/workflow/operatorAccessor";
|
||||
app.use("/api", api);
|
||||
|
||||
// serve
|
||||
@@ -16,3 +17,5 @@ app.listen(PORT, () => {
|
||||
process.on('unhandledRejection', (reason, promise) => {
|
||||
console.error('Unhandled Rejection at:', promise, 'reason:', reason);
|
||||
});
|
||||
|
||||
console.log("Available Modules: ", listOperatorNames())
|
||||
@@ -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