rewrote impose to use new Operator class,

dependencies (pdfcpu) can be made environment-aware using tsconfig.json
This commit is contained in:
Felix Kaspar
2023-11-20 21:04:49 +01:00
parent 42904788bf
commit a5060f0fd3
17 changed files with 188 additions and 187 deletions

View File

@@ -1,3 +1,3 @@
declare module '@stirling-pdf/shared-operations/src/wasm/pdfcpu/pdfcpu-wrapper-node.js' {
declare module '#pdfcpu' {
export function oneToOne(wasmArray: string[], snapshot: Uint8Array): Promise<Uint8Array>;
}

View File

@@ -1,6 +0,0 @@
{
"watch": ["src", "../shared-operations/src"],
"ext": "ts,json",
"ignore": ["src/**/*.spec.ts"],
"exec": "node --trace-warnings --experimental-specifier-resolution=node --loader ts-node/esm ./src/index.ts"
}

View File

@@ -6,7 +6,7 @@
"scripts": {
"build": "npx tsc",
"start": "node dist/index.js",
"dev": "nodemon"
"dev": "npx tsx watch src/index.ts"
},
"keywords": [],
"author": "",
@@ -21,9 +21,11 @@
"jsqr": "^1.4.0",
"multer": "^1.4.5-lts.1",
"nodemon": "^3.0.1",
"pdf-lib": "^1.17.1"
"pdf-lib": "^1.17.1",
"tsconfig-paths": "^4.2.0"
},
"devDependencies": {
"@types/archiver": "^6.0.1",
"@types/express": "^4.17.21",
"@types/multer": "^1.4.10",
"ts-node-dev": "^2.0.0",

View File

@@ -1,8 +1,8 @@
import express, { Request, Response } from 'express';
import workflow from './workflow-controller';
import operations from './operations-controller';
import conversions from './conversions-controller';
// import operations from './operations-controller';
// import conversions from './conversions-controller';
const router = express.Router();
@@ -11,8 +11,8 @@ router.get("/", (req: Request, res: Response) => {
res.status(501).json({"Error": "Unfinished Endpoint. This sould probably send some api docs?"});
});
router.use("/operations", operations);
router.use("/conversions", conversions);
// router.use("/operations", operations);
// router.use("/conversions", conversions);
router.use("/workflow", workflow);
export default router;

View File

@@ -1,9 +1,7 @@
import Operations from '../../utils/pdf-operations';
import { respondWithPdfFile, respondWithPdfFiles, response_mustHaveExactlyOneFile } from '../../utils/endpoint-utils';
import { PdfFile, /*PdfFileSchema*/ } from '@stirling-pdf/shared-operations/src/wrappers/PdfFile'
//import { ScalePageSchema } from '@stirling-pdf/shared-operations/src/functions/scalePage'
import { OperatorType } from '@stirling-pdf/shared-operations/src';
import express, { Request, Response, RequestHandler } from 'express';
const router = express.Router();
@@ -14,7 +12,7 @@ import Joi from 'joi';
function registerEndpoint(endpoint: string,
nameToAppend: string,
fileHandler: RequestHandler,
operator: OperatorType
operator: any
): void {
router.post(endpoint, fileHandler, async function(req: Request, res: Response) {
const body = req.body;
@@ -79,7 +77,7 @@ registerEndpoint("/remove-pages", "", upload.single("file"), Operations.removePa
pageSelector: Joi.string().required(),
}).required());
*/
registerEndpoint("/impose", "", upload.single("file"), Operations.Impose);
// registerEndpoint("/impose", "", upload.single("file"), Operations.Impose);
/*
registerEndpoint("/scale-pages", "", upload.single("file"), Operations.scalePage, ScalePageSchema.required());

View File

@@ -3,7 +3,6 @@ import crypto from 'crypto';
import multer from 'multer'
const upload = multer();
import Operations from "../../utils/pdf-operations";
import { traverseOperations } from "@stirling-pdf/shared-operations/src/workflow/traverseOperations";
import { PdfFile, RepresentationType } from '@stirling-pdf/shared-operations/src/wrappers/PdfFile';
import { respondWithPdfFiles } from '../../utils/endpoint-utils';
@@ -33,7 +32,7 @@ router.post("/:workflowUuid?", [
if(req.body.async === "false") {
console.log("Don't do async");
const traverse = traverseOperations(workflow.operations, inputs, Operations);
const traverse = traverseOperations(workflow.operations, inputs);
let pdfResults;
let iteration;
@@ -74,7 +73,7 @@ router.post("/:workflowUuid?", [
}
});
const traverse = traverseOperations(workflow.operations, inputs, Operations);
const traverse = traverseOperations(workflow.operations, inputs);
let pdfResults;
let iteration;

View File

@@ -1,16 +0,0 @@
import SharedOperations, { OperatorsType, OperatorParametersType } from "@stirling-pdf/shared-operations/src"
import { PdfFile } from "@stirling-pdf/shared-operations/src/wrappers/PdfFile"
// Import injected libraries here!
import * as pdfcpuWrapper from "@stirling-pdf/shared-operations/src/wasm/pdfcpu/pdfcpu-wrapper-node.js";
async function impose(params: OperatorParametersType["Impose"]): Promise<PdfFile> {
return SharedOperations.Impose.exec(params, pdfcpuWrapper);
}
const toExport: OperatorsType = {
...SharedOperations,
Impose: {exec: impose, spec: SharedOperations.Impose.spec},
}
export default toExport;

View File

@@ -28,8 +28,10 @@
"module": "ES2020", /* Specify what module code is generated. */
// "rootDir": "./", /* Specify the root folder within your source files. */
"moduleResolution": "Node", /* Specify how TypeScript looks up a file from a given module specifier. */
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
"baseUrl": "./src", /* Specify the base directory to resolve non-relative module names. */
"paths": {
"#pdfcpu": ["../../shared-operations/src/wasm/pdfcpu/pdfcpu-wrapper.server"],
}, /* 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. */
// "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
@@ -110,7 +112,7 @@
"include": [
"src",
"declarations/*.d.ts"
],
, "../shared-operations/src/wasm/pdfcpu/PdfcpuWrapper.d.ts" ],
"ts-node": {
"experimentalSpecifierResolution": "node",
"transpileOnly": true,