mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 08:13:56 +10:00
fix: don't send too much data to background job provider
This commit is contained in:
@ -237,8 +237,10 @@ test('[DIRECT_TEMPLATES]: use direct template link with 1 recipient', async ({ p
|
|||||||
for (const template of [personalDirectTemplate, teamDirectTemplate]) {
|
for (const template of [personalDirectTemplate, teamDirectTemplate]) {
|
||||||
await page.goto(`${WEBAPP_BASE_URL}${formatDocumentsPath(template.team?.url)}`);
|
await page.goto(`${WEBAPP_BASE_URL}${formatDocumentsPath(template.team?.url)}`);
|
||||||
|
|
||||||
// Check that the document is in the 'All' tab.
|
await expect(async () => {
|
||||||
await checkDocumentTabCount(page, 'Completed', 1);
|
// Check that the document is in the 'All' tab.
|
||||||
|
await checkDocumentTabCount(page, 'Completed', 1);
|
||||||
|
}).toPass();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -57,7 +57,6 @@ export const SEAL_DOCUMENT_JOB_DEFINITION = {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
include: {
|
include: {
|
||||||
documentData: true,
|
|
||||||
Recipient: true,
|
Recipient: true,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@ -69,7 +68,17 @@ export const SEAL_DOCUMENT_JOB_DEFINITION = {
|
|||||||
return document.status;
|
return document.status;
|
||||||
});
|
});
|
||||||
|
|
||||||
const { documentData } = document;
|
// This is the same case as above.
|
||||||
|
// eslint-disable-next-line @typescript-eslint/require-await
|
||||||
|
const documentDataId = await io.runTask('get-document-data-id', async () => {
|
||||||
|
return document.documentDataId;
|
||||||
|
});
|
||||||
|
|
||||||
|
const documentData = await prisma.documentData.findFirst({
|
||||||
|
where: {
|
||||||
|
id: documentDataId,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
if (!documentData) {
|
if (!documentData) {
|
||||||
throw new Error(`Document ${document.id} has no document data`);
|
throw new Error(`Document ${document.id} has no document data`);
|
||||||
@ -107,24 +116,11 @@ export const SEAL_DOCUMENT_JOB_DEFINITION = {
|
|||||||
documentData.data = documentData.initialData;
|
documentData.data = documentData.initialData;
|
||||||
}
|
}
|
||||||
|
|
||||||
const pdfData = await io.runTask('get-document-data', async () => {
|
const pdfData = await getFile(documentData);
|
||||||
const data = await getFile(documentData);
|
const certificateData = await getCertificatePdf({ documentId }).catch(() => null);
|
||||||
|
|
||||||
return Buffer.from(data).toString('base64');
|
const newDataId = await io.runTask('decorate-and-sign-pdf', async () => {
|
||||||
});
|
const pdfDoc = await PDFDocument.load(pdfData);
|
||||||
|
|
||||||
const certificateData = await io.runTask('get-certificate-data', async () => {
|
|
||||||
const data = await getCertificatePdf({ documentId }).catch(() => null);
|
|
||||||
|
|
||||||
if (!data) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Buffer.from(data).toString('base64');
|
|
||||||
});
|
|
||||||
|
|
||||||
const pdfBuffer = await io.runTask('decorate-and-sign-pdf', async () => {
|
|
||||||
const pdfDoc = await PDFDocument.load(Buffer.from(pdfData, 'base64'));
|
|
||||||
|
|
||||||
// Normalize and flatten layers that could cause issues with the signature
|
// Normalize and flatten layers that could cause issues with the signature
|
||||||
normalizeSignatureAppearances(pdfDoc);
|
normalizeSignatureAppearances(pdfDoc);
|
||||||
@ -132,7 +128,7 @@ export const SEAL_DOCUMENT_JOB_DEFINITION = {
|
|||||||
flattenAnnotations(pdfDoc);
|
flattenAnnotations(pdfDoc);
|
||||||
|
|
||||||
if (certificateData) {
|
if (certificateData) {
|
||||||
const certificateDoc = await PDFDocument.load(Buffer.from(certificateData, 'base64'));
|
const certificateDoc = await PDFDocument.load(certificateData);
|
||||||
|
|
||||||
const certificatePages = await pdfDoc.copyPages(
|
const certificatePages = await pdfDoc.copyPages(
|
||||||
certificateDoc,
|
certificateDoc,
|
||||||
@ -153,22 +149,17 @@ export const SEAL_DOCUMENT_JOB_DEFINITION = {
|
|||||||
flattenForm(pdfDoc);
|
flattenForm(pdfDoc);
|
||||||
|
|
||||||
const pdfBytes = await pdfDoc.save();
|
const pdfBytes = await pdfDoc.save();
|
||||||
|
const pdfBuffer = await signPdf({ pdf: Buffer.from(pdfBytes) });
|
||||||
|
|
||||||
const buffer = await signPdf({ pdf: Buffer.from(pdfBytes) });
|
|
||||||
|
|
||||||
return buffer.toString('base64');
|
|
||||||
});
|
|
||||||
|
|
||||||
const newData = await io.runTask('store-signed-document', async () => {
|
|
||||||
const { name, ext } = path.parse(document.title);
|
const { name, ext } = path.parse(document.title);
|
||||||
|
|
||||||
const { data } = await putPdfFile({
|
const documentData = await putPdfFile({
|
||||||
name: `${name}_signed${ext}`,
|
name: `${name}_signed${ext}`,
|
||||||
type: 'application/pdf',
|
type: 'application/pdf',
|
||||||
arrayBuffer: async () => Promise.resolve(Buffer.from(pdfBuffer, 'base64')),
|
arrayBuffer: async () => Promise.resolve(pdfBuffer),
|
||||||
});
|
});
|
||||||
|
|
||||||
return data;
|
return documentData.id;
|
||||||
});
|
});
|
||||||
|
|
||||||
const postHog = PostHogServerClient();
|
const postHog = PostHogServerClient();
|
||||||
@ -185,6 +176,12 @@ export const SEAL_DOCUMENT_JOB_DEFINITION = {
|
|||||||
|
|
||||||
await io.runTask('update-document', async () => {
|
await io.runTask('update-document', async () => {
|
||||||
await prisma.$transaction(async (tx) => {
|
await prisma.$transaction(async (tx) => {
|
||||||
|
const newData = await tx.documentData.findFirstOrThrow({
|
||||||
|
where: {
|
||||||
|
id: newDataId,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
await tx.document.update({
|
await tx.document.update({
|
||||||
where: {
|
where: {
|
||||||
id: document.id,
|
id: document.id,
|
||||||
@ -200,7 +197,7 @@ export const SEAL_DOCUMENT_JOB_DEFINITION = {
|
|||||||
id: documentData.id,
|
id: documentData.id,
|
||||||
},
|
},
|
||||||
data: {
|
data: {
|
||||||
data: newData,
|
data: newData.data,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user