mirror of
https://github.com/documenso/documenso.git
synced 2026-06-22 04:12:06 +10:00
refactor: improve logger for wrong pdf placeholders
This commit is contained in:
@@ -57,7 +57,10 @@ export const UNSAFE_createEnvelopeItems = async ({
|
|||||||
flattenForm: envelope.type !== 'TEMPLATE',
|
flattenForm: envelope.type !== 'TEMPLATE',
|
||||||
});
|
});
|
||||||
|
|
||||||
const { cleanedPdf, placeholders } = await extractPdfPlaceholders(normalized);
|
const { cleanedPdf, placeholders } = await extractPdfPlaceholders(normalized, {
|
||||||
|
envelopeId: envelope.id,
|
||||||
|
fileName: file.name,
|
||||||
|
});
|
||||||
|
|
||||||
const { documentData } = await putPdfFileServerSide({
|
const { documentData } = await putPdfFileServerSide({
|
||||||
name: file.name,
|
name: file.name,
|
||||||
|
|||||||
@@ -85,7 +85,10 @@ export const UNSAFE_replaceEnvelopeItemPdf = async ({
|
|||||||
flattenForm: envelope.type !== 'TEMPLATE',
|
flattenForm: envelope.type !== 'TEMPLATE',
|
||||||
});
|
});
|
||||||
|
|
||||||
const { cleanedPdf, placeholders } = await extractPdfPlaceholders(normalized);
|
const { cleanedPdf, placeholders } = await extractPdfPlaceholders(normalized, {
|
||||||
|
envelopeId: envelope.id,
|
||||||
|
fileName: data.file.name,
|
||||||
|
});
|
||||||
|
|
||||||
// Upload the new PDF and get a new DocumentData record.
|
// Upload the new PDF and get a new DocumentData record.
|
||||||
const { documentData: newDocumentData, filePageCount } = await putPdfFileServerSide({
|
const { documentData: newDocumentData, filePageCount } = await putPdfFileServerSide({
|
||||||
|
|||||||
@@ -68,7 +68,15 @@ export type FieldToCreate = TFieldAndMeta & {
|
|||||||
height: number;
|
height: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const extractPlaceholdersFromPDF = async (pdf: Buffer): Promise<PlaceholderInfo[]> => {
|
type ExtractPlaceholdersLogContext = {
|
||||||
|
envelopeId?: string;
|
||||||
|
fileName?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const extractPlaceholdersFromPDF = async (
|
||||||
|
pdf: Buffer,
|
||||||
|
logContext?: ExtractPlaceholdersLogContext,
|
||||||
|
): Promise<PlaceholderInfo[]> => {
|
||||||
const pdfDoc = await PDF.load(new Uint8Array(pdf));
|
const pdfDoc = await PDF.load(new Uint8Array(pdf));
|
||||||
|
|
||||||
const placeholders: PlaceholderInfo[] = [];
|
const placeholders: PlaceholderInfo[] = [];
|
||||||
@@ -149,6 +157,8 @@ export const extractPlaceholdersFromPDF = async (pdf: Buffer): Promise<Placehold
|
|||||||
|
|
||||||
logger.warn(
|
logger.warn(
|
||||||
{
|
{
|
||||||
|
envelopeId: logContext?.envelopeId,
|
||||||
|
fileName: logContext?.fileName,
|
||||||
placeholder,
|
placeholder,
|
||||||
page: page.index + 1,
|
page: page.index + 1,
|
||||||
code: appError.code,
|
code: appError.code,
|
||||||
@@ -224,8 +234,9 @@ export const removePlaceholdersFromPDF = async (pdf: Buffer, placeholders?: Plac
|
|||||||
*/
|
*/
|
||||||
export const extractPdfPlaceholders = async (
|
export const extractPdfPlaceholders = async (
|
||||||
pdf: Buffer,
|
pdf: Buffer,
|
||||||
|
logContext?: ExtractPlaceholdersLogContext,
|
||||||
): Promise<{ cleanedPdf: Buffer; placeholders: PlaceholderInfo[] }> => {
|
): Promise<{ cleanedPdf: Buffer; placeholders: PlaceholderInfo[] }> => {
|
||||||
const placeholders = await extractPlaceholdersFromPDF(pdf);
|
const placeholders = await extractPlaceholdersFromPDF(pdf, logContext);
|
||||||
|
|
||||||
if (placeholders.length === 0) {
|
if (placeholders.length === 0) {
|
||||||
return { cleanedPdf: pdf, placeholders: [] };
|
return { cleanedPdf: pdf, placeholders: [] };
|
||||||
|
|||||||
@@ -124,7 +124,9 @@ export const createEnvelopeRouteCaller = async ({
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Todo: Embeds - Might need to add this for client-side embeds in the future.
|
// Todo: Embeds - Might need to add this for client-side embeds in the future.
|
||||||
const { cleanedPdf, placeholders } = await extractPdfPlaceholders(normalized);
|
const { cleanedPdf, placeholders } = await extractPdfPlaceholders(normalized, {
|
||||||
|
fileName: file.name,
|
||||||
|
});
|
||||||
|
|
||||||
const { documentData } = await putPdfFileServerSide({
|
const { documentData } = await putPdfFileServerSide({
|
||||||
name: file.name,
|
name: file.name,
|
||||||
|
|||||||
Reference in New Issue
Block a user