standardised the api response, updated contribute

This commit is contained in:
Saud Fatayerji
2023-10-27 01:33:11 +03:00
parent 99ca6b6a26
commit 29a8107ae0
3 changed files with 18 additions and 15 deletions

View File

@@ -1,5 +1,6 @@
import { rotatePages } from '../../src/pdf-operations.js'
import { rotatePages } from '../../src/pdf-operations.js';
import { respondWithBinaryPdf } from '../../src/utils/endpoint-utils.js';
import express from 'express';
const router = express.Router();
@@ -8,18 +9,9 @@ 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'))
const newFilename = req.file.originalname.replace(/(\.[^.]+)$/, '_rotated$1'); // add '_rotated' just before the file extension
respondWithBinaryPdf(res, rotated, newFilename);
});
export default router;