cleaned up node server
This commit is contained in:
@@ -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;
|
||||
25
server-node/routes/api/operations.js
Normal file
25
server-node/routes/api/operations.js
Normal 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;
|
||||
@@ -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."});
|
||||
|
||||
Reference in New Issue
Block a user