mirror of
https://github.com/Frooodle/Stirling-PDF.git
synced 2024-12-21 19:08:24 +01:00
25 lines
764 B
JavaScript
25 lines
764 B
JavaScript
|
|
||
|
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;
|