File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -77,9 +77,9 @@ app.use(cors({
7777// Webhook routes need raw body
7878app . use ( '/api/webhooks' , express . raw ( { type : 'application/json' } ) ) ;
7979
80- // Regular JSON parsing for other routes
81- app . use ( express . json ( ) ) ;
82- app . use ( express . urlencoded ( { extended : true } ) ) ;
80+ // Regular JSON parsing for other routes - increased limit for certificate data URLs
81+ app . use ( express . json ( { limit : '50mb' } ) ) ;
82+ app . use ( express . urlencoded ( { extended : true , limit : '50mb' } ) ) ;
8383app . use ( limiter ) ;
8484
8585// Serve uploaded files
Original file line number Diff line number Diff line change @@ -3,8 +3,21 @@ import fetch from 'node-fetch';
33
44export const generateCertificate = async ( templateUrl , mapping , data ) => {
55 try {
6- // 1. Fetch the template
7- const existingPdfBytes = await fetch ( templateUrl ) . then ( res => res . arrayBuffer ( ) ) ;
6+ // 1. Fetch the template - handle both URLs and base64 data URLs
7+ let existingPdfBytes ;
8+
9+ if ( templateUrl . startsWith ( 'data:' ) ) {
10+ // Handle base64 data URL
11+ const base64Data = templateUrl . split ( ',' ) [ 1 ] ;
12+ existingPdfBytes = Buffer . from ( base64Data , 'base64' ) ;
13+ } else {
14+ // Handle regular URL
15+ const response = await fetch ( templateUrl ) ;
16+ if ( ! response . ok ) {
17+ throw new Error ( `Failed to fetch template: ${ response . status } ${ response . statusText } ` ) ;
18+ }
19+ existingPdfBytes = await response . arrayBuffer ( ) ;
20+ }
821
922 // 2. Load PDF
1023 const pdfDoc = await PDFDocument . load ( existingPdfBytes ) ;
You can’t perform that action at this time.
0 commit comments