cleaned up node server

This commit is contained in:
Saud Fatayerji
2023-10-26 21:53:02 +03:00
parent 02f98fb378
commit 13c4f664c2
24 changed files with 181 additions and 1261 deletions

View File

@@ -1,15 +0,0 @@
import express from 'express';
import workflow from './workflow.js';
import fileUpload from 'express-fileupload';
const router = express.Router();
router.use(fileUpload());
router.get("/", function (req, res, next) {
// TODO: Implement root api endpoint
res.status(501).json({"Error": "Unfinished Endpoint. This sould probably send some api docs?"});
});
router.use("/workflow", workflow);
export default router;

View File

@@ -0,0 +1,25 @@
import { rotatePages } from '../../src/pdf-operations.js'
import express from 'express';
const router = express.Router();
import multer from 'multer'
const upload = multer();
router.post('/rotate-pdf', upload.single("pdfFile"), async function(req, res, next) {
console.debug("rotating pdf:", req.file)
const rotated = await rotatePages(req.file.buffer, 90)
// add '_rotated' just before the file extension
const newFilename = req.file.originalname.replace(/(\.[^.]+)$/, '_rotated$1');
res.writeHead(200, {
'Content-Type': "application/pdf",
'Content-disposition': 'attachment;filename=' + newFilename,
'Content-Length': rotated.length
});
res.end(Buffer.from(rotated, 'binary'))
});
export default router;

View File

@@ -2,8 +2,10 @@ import express from 'express';
import crypto from 'crypto';
import stream from "stream";
import Archiver from 'archiver';
import multer from 'multer'
const upload = multer();
import * as Functions from "../../public/pdf-operations.js";
import * as Functions from "../../src/pdf-operations.js";
import { traverseOperations } from "../../public/traverseOperations.js";
const activeWorkflows = {};
@@ -11,6 +13,7 @@ const activeWorkflows = {};
const router = express.Router();
router.post("/:workflowUuid?", [
upload.any(),
async (req, res) => {
if(req.files == null) {
res.status(400).json({"error": "No files were uploaded."});