Dynamic access to Operators in both front and backend
This commit is contained in:
@@ -36,10 +36,13 @@
|
||||
"pdf-lib": "^1.17.1",
|
||||
"rollup-plugin-copy": "^3.5.0",
|
||||
"tsconfig-paths": "^4.2.0",
|
||||
"vite-plugin-compile-time": "^0.2.1",
|
||||
"vite-plugin-dynamic-import": "^1.5.0",
|
||||
"vite-plugin-node-polyfills": "^0.19.0",
|
||||
"vite-plugin-top-level-await": "^1.4.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@rollup/plugin-dynamic-import-vars": "^2.1.2",
|
||||
"@rollup/plugin-run": "^3.0.2",
|
||||
"@rollup/plugin-typescript": "^11.1.6",
|
||||
"copyfiles": "^2.4.1",
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
import run from "@rollup/plugin-run";
|
||||
import typescript from '@rollup/plugin-typescript';
|
||||
import json from '@rollup/plugin-json';
|
||||
import copy from 'rollup-plugin-copy'
|
||||
|
||||
import copy from 'rollup-plugin-copy';
|
||||
import compileTime from "vite-plugin-compile-time";
|
||||
import dynamicImportVars from '@rollup/plugin-dynamic-import-vars';
|
||||
|
||||
const isDev = process.env.NODE_ENV !== "production";
|
||||
|
||||
export default {
|
||||
input: "src/index.ts",
|
||||
output: {
|
||||
file: "dist/bundle.js",
|
||||
dir: "dist/",
|
||||
format: "es",
|
||||
},
|
||||
watch: {
|
||||
@@ -18,6 +19,8 @@ export default {
|
||||
plugins: [
|
||||
json(),
|
||||
typescript(),
|
||||
dynamicImportVars(),
|
||||
compileTime(),
|
||||
copy({
|
||||
targets: [
|
||||
{ src: '../shared-operations/public', dest: 'dist' },
|
||||
|
||||
@@ -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};
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
"moduleResolution": "Node", /* Specify how TypeScript looks up a file from a given module specifier. */
|
||||
"baseUrl": "./src", /* Specify the base directory to resolve non-relative module names. */
|
||||
"paths": {
|
||||
"#pdfcpu": ["@stirling-pdf/shared-operations/src/wasm/pdfcpu/pdfcpu-wrapper.server"],
|
||||
"#pdfcpu": ["../shared-operations/src/wasm/pdfcpu/pdfcpu-wrapper.server.js"],
|
||||
"@stirling-pdf/*": [ "../../*" ]
|
||||
}, /* Specify a set of entries that re-map imports to additional lookup locations. */
|
||||
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
|
||||
|
||||
Reference in New Issue
Block a user