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