mirror of
https://github.com/documenso/documenso.git
synced 2025-11-21 20:21:38 +10:00
chore: review
This commit is contained in:
@ -28,7 +28,7 @@ export const renderPdfToImage = async (pdfBytes: Uint8Array) => {
|
||||
try {
|
||||
const scale = 2;
|
||||
|
||||
const pages = await Promise.all(
|
||||
const results = await Promise.allSettled(
|
||||
Array.from({ length: pdf.numPages }, async (_, index) => {
|
||||
const pageNumber = index + 1;
|
||||
const page = await pdf.getPage(pageNumber);
|
||||
@ -54,6 +54,26 @@ export const renderPdfToImage = async (pdfBytes: Uint8Array) => {
|
||||
}),
|
||||
);
|
||||
|
||||
const pages = results
|
||||
.filter(
|
||||
(
|
||||
result,
|
||||
): result is PromiseFulfilledResult<{
|
||||
image: Buffer;
|
||||
pageNumber: number;
|
||||
width: number;
|
||||
height: number;
|
||||
}> => result.status === 'fulfilled',
|
||||
)
|
||||
.map((result) => result.value);
|
||||
|
||||
if (results.some((result) => result.status === 'rejected')) {
|
||||
console.error(
|
||||
'Some pages failed to render:',
|
||||
results.filter((result) => result.status === 'rejected').map((result) => result.reason),
|
||||
);
|
||||
}
|
||||
|
||||
return pages;
|
||||
} finally {
|
||||
await pdf.destroy();
|
||||
|
||||
@ -1,16 +1,35 @@
|
||||
export type TDetectedFormField = {
|
||||
boundingBox: number[];
|
||||
label:
|
||||
| 'SIGNATURE'
|
||||
| 'INITIALS'
|
||||
| 'NAME'
|
||||
| 'EMAIL'
|
||||
| 'DATE'
|
||||
| 'TEXT'
|
||||
| 'NUMBER'
|
||||
| 'RADIO'
|
||||
| 'CHECKBOX'
|
||||
| 'DROPDOWN';
|
||||
pageNumber: number;
|
||||
recipientId: number;
|
||||
};
|
||||
import { z } from 'zod';
|
||||
|
||||
export const ZDetectedFormFieldSchema = z.object({
|
||||
boundingBox: z
|
||||
.array(z.number().min(0).max(1000))
|
||||
.length(4)
|
||||
.describe('Bounding box [ymin, xmin, ymax, xmax] in normalized 0-1000 range'),
|
||||
label: z
|
||||
.enum([
|
||||
'SIGNATURE',
|
||||
'INITIALS',
|
||||
'NAME',
|
||||
'EMAIL',
|
||||
'DATE',
|
||||
'TEXT',
|
||||
'NUMBER',
|
||||
'RADIO',
|
||||
'CHECKBOX',
|
||||
'DROPDOWN',
|
||||
])
|
||||
.describe('Documenso field type inferred from nearby label text or visual characteristics'),
|
||||
pageNumber: z
|
||||
.number()
|
||||
.int()
|
||||
.positive()
|
||||
.describe('1-indexed page number where field was detected'),
|
||||
recipientId: z
|
||||
.number()
|
||||
.int()
|
||||
.describe(
|
||||
'ID of the recipient (from the provided envelope recipients) who should own the field',
|
||||
),
|
||||
});
|
||||
|
||||
export type TDetectedFormField = z.infer<typeof ZDetectedFormFieldSchema>;
|
||||
|
||||
Reference in New Issue
Block a user