mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 08:13:56 +10:00
🎨 🧹
This commit is contained in:
@ -48,8 +48,7 @@ async function getHandler(req: NextApiRequest, res: NextApiResponse) {
|
||||
`attachment; filename=${document.title}`
|
||||
);
|
||||
|
||||
res.status(200).send(buffer);
|
||||
return;
|
||||
return res.status(200).send(buffer);
|
||||
}
|
||||
|
||||
async function deleteHandler(req: NextApiRequest, res: NextApiResponse) {
|
||||
|
||||
@ -3,15 +3,12 @@ import type { NextApiRequest, NextApiResponse } from "next";
|
||||
import { defaultHandler, defaultResponder } from "@documenso/lib/server";
|
||||
import prisma from "@documenso/prisma";
|
||||
|
||||
type responseData = {
|
||||
status: string;
|
||||
};
|
||||
|
||||
// Return a healthy 200 status code for uptime monitoring and render.com zero-downtime-deploy
|
||||
async function getHandler(req: NextApiRequest, res: NextApiResponse) {
|
||||
// A generic database access to make sure the service is healthy.
|
||||
// Some generic database access to make sure the service is healthy.
|
||||
const users = await prisma.user.findFirst();
|
||||
res.status(200).json({ message: "Api up and running :)" });
|
||||
|
||||
return res.status(200).json({ message: "Api up and running :)" });
|
||||
}
|
||||
|
||||
export default defaultHandler({
|
||||
|
||||
@ -12,19 +12,15 @@ import { addDigitalSignature } from "@documenso/signing/addDigitalSignature";
|
||||
async function getHandler(req: NextApiRequest, res: NextApiResponse) {
|
||||
const documentId = req.query.id || 1;
|
||||
const document: PrismaDocument = await getDocument(+documentId, req, res);
|
||||
const signedDocumentAsBase64 = await addDigitalSignature(
|
||||
document.document.toString()
|
||||
);
|
||||
const buffer: Buffer = Buffer.from(signedDocumentAsBase64, "base64");
|
||||
const signedDocument = await addDigitalSignature(document.document);
|
||||
res.setHeader("Content-Type", "application/pdf");
|
||||
res.setHeader("Content-Length", signedDocument.length);
|
||||
res.setHeader(
|
||||
"Content-Disposition",
|
||||
`attachment; filename=${document.title}`
|
||||
);
|
||||
res.setHeader("Content-Length", buffer.length);
|
||||
|
||||
res.status(200).send(buffer);
|
||||
return;
|
||||
return res.status(200).send(signedDocument);
|
||||
}
|
||||
|
||||
export default defaultHandler({
|
||||
|
||||
@ -10,16 +10,11 @@ import {
|
||||
|
||||
export const addDigitalSignature = async (
|
||||
documentAsBase64: string
|
||||
): Promise<any> => {
|
||||
): Promise<string> => {
|
||||
// Custom code to add Byterange to PDF
|
||||
const PDFArrayCustom = require("./PDFArrayCustom");
|
||||
|
||||
// The PDF we're going to sign
|
||||
const pdfBuffer = Buffer.from(documentAsBase64, "base64");
|
||||
|
||||
// The p12 certificate we're going to sign with
|
||||
const p12Buffer = fs.readFileSync("ressources/certificate.p12");
|
||||
|
||||
const SIGNATURE_LENGTH = 4540;
|
||||
|
||||
const pdfDoc = await PDFDocument.load(pdfBuffer);
|
||||
@ -70,11 +65,9 @@ export const addDigitalSignature = async (
|
||||
const modifiedPdfBuffer = Buffer.from(modifiedPdfBytes);
|
||||
|
||||
const signObj = new signer.SignPdf();
|
||||
const signedPdfBuffer = signObj.sign(modifiedPdfBuffer, p12Buffer, {
|
||||
const signedPdfBuffer: Buffer = signObj.sign(modifiedPdfBuffer, p12Buffer, {
|
||||
passphrase: "",
|
||||
});
|
||||
|
||||
// Write the signed file
|
||||
// fs.writeFileSync("./signed.pdf", signedPdfBuffer);
|
||||
return signedPdfBuffer;
|
||||
return signedPdfBuffer.toString("base64");
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user