n8n-nodes-make-pdf 1.1.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/nodes/MakePdf/MakePdf.node.js +469 -184
- package/package.json +1 -1
|
@@ -10,7 +10,8 @@ class MakePdf {
|
|
|
10
10
|
icon: 'file:MakePdf.svg',
|
|
11
11
|
group: ['transform'],
|
|
12
12
|
version: 1,
|
|
13
|
-
|
|
13
|
+
subtitle: '={{$parameter["method"] + ": " + $parameter["url"]}}',
|
|
14
|
+
description: 'Make HTTP requests to Gotenberg for PDF generation',
|
|
14
15
|
defaults: {
|
|
15
16
|
name: 'Make PDF',
|
|
16
17
|
},
|
|
@@ -18,31 +19,273 @@ class MakePdf {
|
|
|
18
19
|
outputs: ['main'],
|
|
19
20
|
properties: [
|
|
20
21
|
{
|
|
21
|
-
displayName: '
|
|
22
|
-
name: '
|
|
22
|
+
displayName: 'Method',
|
|
23
|
+
name: 'method',
|
|
24
|
+
type: 'options',
|
|
25
|
+
options: [
|
|
26
|
+
{ name: 'DELETE', value: 'DELETE' },
|
|
27
|
+
{ name: 'GET', value: 'GET' },
|
|
28
|
+
{ name: 'HEAD', value: 'HEAD' },
|
|
29
|
+
{ name: 'PATCH', value: 'PATCH' },
|
|
30
|
+
{ name: 'POST', value: 'POST' },
|
|
31
|
+
{ name: 'PUT', value: 'PUT' },
|
|
32
|
+
],
|
|
33
|
+
default: 'POST',
|
|
34
|
+
description: 'The request method to use',
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
displayName: 'URL',
|
|
38
|
+
name: 'url',
|
|
23
39
|
type: 'string',
|
|
24
|
-
default: '
|
|
40
|
+
default: 'http://gotenberg:3000/forms/chromium/convert/html',
|
|
41
|
+
placeholder: 'http://gotenberg:3000/forms/chromium/convert/html',
|
|
42
|
+
description: 'The URL to make the request to',
|
|
25
43
|
required: true,
|
|
26
|
-
description: 'Name of the binary property which contains the HTML data',
|
|
27
|
-
placeholder: 'e.g. data',
|
|
28
44
|
},
|
|
29
45
|
{
|
|
30
|
-
displayName: '
|
|
31
|
-
name: '
|
|
46
|
+
displayName: 'Authentication',
|
|
47
|
+
name: 'authentication',
|
|
48
|
+
type: 'options',
|
|
49
|
+
options: [
|
|
50
|
+
{ name: 'None', value: 'none' },
|
|
51
|
+
{ name: 'Header Auth', value: 'headerAuth' },
|
|
52
|
+
{ name: 'Query Auth', value: 'queryAuth' },
|
|
53
|
+
],
|
|
54
|
+
default: 'none',
|
|
55
|
+
description: 'Authentication method to use',
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
displayName: 'Send Query Parameters',
|
|
59
|
+
name: 'sendQuery',
|
|
60
|
+
type: 'boolean',
|
|
61
|
+
default: false,
|
|
62
|
+
description: 'Whether the request has query params or not',
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
displayName: 'Query Parameters',
|
|
66
|
+
name: 'queryParameters',
|
|
67
|
+
type: 'fixedCollection',
|
|
68
|
+
typeOptions: {
|
|
69
|
+
multipleValues: true,
|
|
70
|
+
},
|
|
71
|
+
placeholder: 'Add Parameter',
|
|
72
|
+
default: { parameters: [] },
|
|
73
|
+
displayOptions: {
|
|
74
|
+
show: {
|
|
75
|
+
sendQuery: [true],
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
options: [
|
|
79
|
+
{
|
|
80
|
+
name: 'parameters',
|
|
81
|
+
displayName: 'Parameter',
|
|
82
|
+
values: [
|
|
83
|
+
{
|
|
84
|
+
displayName: 'Name',
|
|
85
|
+
name: 'name',
|
|
86
|
+
type: 'string',
|
|
87
|
+
default: '',
|
|
88
|
+
description: 'Name of the parameter',
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
displayName: 'Value',
|
|
92
|
+
name: 'value',
|
|
93
|
+
type: 'string',
|
|
94
|
+
default: '',
|
|
95
|
+
description: 'Value of the parameter',
|
|
96
|
+
},
|
|
97
|
+
],
|
|
98
|
+
},
|
|
99
|
+
],
|
|
100
|
+
description: 'The query parameters to send',
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
displayName: 'Send Headers',
|
|
104
|
+
name: 'sendHeaders',
|
|
105
|
+
type: 'boolean',
|
|
106
|
+
default: false,
|
|
107
|
+
description: 'Whether the request has headers or not',
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
displayName: 'Header Parameters',
|
|
111
|
+
name: 'headerParameters',
|
|
112
|
+
type: 'fixedCollection',
|
|
113
|
+
typeOptions: {
|
|
114
|
+
multipleValues: true,
|
|
115
|
+
},
|
|
116
|
+
placeholder: 'Add Header',
|
|
117
|
+
default: { parameters: [] },
|
|
118
|
+
displayOptions: {
|
|
119
|
+
show: {
|
|
120
|
+
sendHeaders: [true],
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
options: [
|
|
124
|
+
{
|
|
125
|
+
name: 'parameters',
|
|
126
|
+
displayName: 'Header',
|
|
127
|
+
values: [
|
|
128
|
+
{
|
|
129
|
+
displayName: 'Name',
|
|
130
|
+
name: 'name',
|
|
131
|
+
type: 'string',
|
|
132
|
+
default: '',
|
|
133
|
+
description: 'Name of the header',
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
displayName: 'Value',
|
|
137
|
+
name: 'value',
|
|
138
|
+
type: 'string',
|
|
139
|
+
default: '',
|
|
140
|
+
description: 'Value of the header',
|
|
141
|
+
},
|
|
142
|
+
],
|
|
143
|
+
},
|
|
144
|
+
],
|
|
145
|
+
description: 'The headers to send',
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
displayName: 'Send Body',
|
|
149
|
+
name: 'sendBody',
|
|
150
|
+
type: 'boolean',
|
|
151
|
+
default: true,
|
|
152
|
+
description: 'Whether the request has a body or not',
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
displayName: 'Body Content Type',
|
|
156
|
+
name: 'contentType',
|
|
157
|
+
type: 'options',
|
|
158
|
+
displayOptions: {
|
|
159
|
+
show: {
|
|
160
|
+
sendBody: [true],
|
|
161
|
+
},
|
|
162
|
+
},
|
|
163
|
+
options: [
|
|
164
|
+
{
|
|
165
|
+
name: 'Form-Data Multipart',
|
|
166
|
+
value: 'multipart-form-data',
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
name: 'Form Urlencoded',
|
|
170
|
+
value: 'form-urlencoded',
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
name: 'JSON',
|
|
174
|
+
value: 'json',
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
name: 'RAW/Custom',
|
|
178
|
+
value: 'raw',
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
name: 'n8n Binary Data',
|
|
182
|
+
value: 'binaryData',
|
|
183
|
+
},
|
|
184
|
+
],
|
|
185
|
+
default: 'multipart-form-data',
|
|
186
|
+
description: 'Content-Type to use for body',
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
displayName: 'Body Parameters',
|
|
190
|
+
name: 'bodyParameters',
|
|
191
|
+
type: 'fixedCollection',
|
|
192
|
+
typeOptions: {
|
|
193
|
+
multipleValues: true,
|
|
194
|
+
},
|
|
195
|
+
placeholder: 'Add Parameter',
|
|
196
|
+
default: { parameters: [] },
|
|
197
|
+
displayOptions: {
|
|
198
|
+
show: {
|
|
199
|
+
sendBody: [true],
|
|
200
|
+
contentType: ['multipart-form-data', 'form-urlencoded'],
|
|
201
|
+
},
|
|
202
|
+
},
|
|
203
|
+
options: [
|
|
204
|
+
{
|
|
205
|
+
name: 'parameters',
|
|
206
|
+
displayName: 'Parameter',
|
|
207
|
+
values: [
|
|
208
|
+
{
|
|
209
|
+
displayName: 'Parameter Type',
|
|
210
|
+
name: 'parameterType',
|
|
211
|
+
type: 'options',
|
|
212
|
+
options: [
|
|
213
|
+
{
|
|
214
|
+
name: 'n8n Binary Data',
|
|
215
|
+
value: 'formBinaryData',
|
|
216
|
+
},
|
|
217
|
+
{
|
|
218
|
+
name: 'Form Data',
|
|
219
|
+
value: 'formData',
|
|
220
|
+
},
|
|
221
|
+
],
|
|
222
|
+
default: 'formData',
|
|
223
|
+
},
|
|
224
|
+
{
|
|
225
|
+
displayName: 'Name',
|
|
226
|
+
name: 'name',
|
|
227
|
+
type: 'string',
|
|
228
|
+
default: '',
|
|
229
|
+
description: 'Name of the parameter',
|
|
230
|
+
},
|
|
231
|
+
{
|
|
232
|
+
displayName: 'Input Data Field Name',
|
|
233
|
+
name: 'inputDataFieldName',
|
|
234
|
+
type: 'string',
|
|
235
|
+
displayOptions: {
|
|
236
|
+
show: {
|
|
237
|
+
parameterType: ['formBinaryData'],
|
|
238
|
+
},
|
|
239
|
+
},
|
|
240
|
+
default: '',
|
|
241
|
+
description: 'The name of the incoming field containing the binary file data',
|
|
242
|
+
},
|
|
243
|
+
{
|
|
244
|
+
displayName: 'Value',
|
|
245
|
+
name: 'value',
|
|
246
|
+
type: 'string',
|
|
247
|
+
displayOptions: {
|
|
248
|
+
show: {
|
|
249
|
+
parameterType: ['formData'],
|
|
250
|
+
},
|
|
251
|
+
},
|
|
252
|
+
default: '',
|
|
253
|
+
description: 'Value of the parameter',
|
|
254
|
+
},
|
|
255
|
+
],
|
|
256
|
+
},
|
|
257
|
+
],
|
|
258
|
+
description: 'Body parameters to send',
|
|
259
|
+
},
|
|
260
|
+
{
|
|
261
|
+
displayName: 'JSON/RAW Body',
|
|
262
|
+
name: 'jsonBody',
|
|
32
263
|
type: 'string',
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
264
|
+
displayOptions: {
|
|
265
|
+
show: {
|
|
266
|
+
sendBody: [true],
|
|
267
|
+
contentType: ['json', 'raw'],
|
|
268
|
+
},
|
|
269
|
+
},
|
|
270
|
+
default: '',
|
|
271
|
+
typeOptions: {
|
|
272
|
+
alwaysOpenEditWindow: true,
|
|
273
|
+
},
|
|
274
|
+
description: 'JSON or RAW body content',
|
|
37
275
|
},
|
|
38
276
|
{
|
|
39
|
-
displayName: '
|
|
40
|
-
name: '
|
|
277
|
+
displayName: 'Input Binary Field',
|
|
278
|
+
name: 'inputBinaryField',
|
|
41
279
|
type: 'string',
|
|
42
|
-
|
|
280
|
+
displayOptions: {
|
|
281
|
+
show: {
|
|
282
|
+
sendBody: [true],
|
|
283
|
+
contentType: ['binaryData'],
|
|
284
|
+
},
|
|
285
|
+
},
|
|
286
|
+
default: 'data',
|
|
43
287
|
required: true,
|
|
44
|
-
description: 'The
|
|
45
|
-
placeholder: 'http://gotenberg:3000/forms/chromium/convert/html',
|
|
288
|
+
description: 'The name of the incoming field containing the binary file data',
|
|
46
289
|
},
|
|
47
290
|
{
|
|
48
291
|
displayName: 'Options',
|
|
@@ -52,119 +295,121 @@ class MakePdf {
|
|
|
52
295
|
default: {},
|
|
53
296
|
options: [
|
|
54
297
|
{
|
|
55
|
-
displayName: '
|
|
56
|
-
name: '
|
|
57
|
-
|
|
298
|
+
displayName: 'Batching',
|
|
299
|
+
name: 'batching',
|
|
300
|
+
placeholder: 'Add Batching',
|
|
301
|
+
type: 'fixedCollection',
|
|
302
|
+
typeOptions: {
|
|
303
|
+
multipleValues: false,
|
|
304
|
+
},
|
|
305
|
+
default: {},
|
|
58
306
|
options: [
|
|
59
|
-
{
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
307
|
+
{
|
|
308
|
+
displayName: 'Batch',
|
|
309
|
+
name: 'batch',
|
|
310
|
+
values: [
|
|
311
|
+
{
|
|
312
|
+
displayName: 'Items per Batch',
|
|
313
|
+
name: 'batchSize',
|
|
314
|
+
type: 'number',
|
|
315
|
+
typeOptions: {
|
|
316
|
+
minValue: 1,
|
|
317
|
+
},
|
|
318
|
+
default: 50,
|
|
319
|
+
description: 'Input will be split into multiple batches to throttle requests. -1 for disabled.',
|
|
320
|
+
},
|
|
321
|
+
{
|
|
322
|
+
displayName: 'Batch Interval',
|
|
323
|
+
name: 'batchInterval',
|
|
324
|
+
type: 'number',
|
|
325
|
+
typeOptions: {
|
|
326
|
+
minValue: 0,
|
|
327
|
+
},
|
|
328
|
+
default: 1000,
|
|
329
|
+
description: 'Time (in milliseconds) between each batch of requests. 0 for disabled.',
|
|
330
|
+
},
|
|
331
|
+
],
|
|
332
|
+
},
|
|
66
333
|
],
|
|
67
|
-
default: 'A4',
|
|
68
|
-
description: 'The paper format for the PDF',
|
|
69
334
|
},
|
|
70
335
|
{
|
|
71
|
-
displayName: '
|
|
72
|
-
name: '
|
|
336
|
+
displayName: 'Ignore SSL Issues',
|
|
337
|
+
name: 'allowUnauthorizedCerts',
|
|
73
338
|
type: 'boolean',
|
|
74
339
|
default: false,
|
|
75
|
-
description: 'Whether to
|
|
340
|
+
description: 'Whether to download the response even if SSL certificate validation is not possible',
|
|
76
341
|
},
|
|
77
342
|
{
|
|
78
|
-
displayName: '
|
|
79
|
-
name: '
|
|
343
|
+
displayName: 'Follow Redirect',
|
|
344
|
+
name: 'followRedirect',
|
|
80
345
|
type: 'boolean',
|
|
81
346
|
default: true,
|
|
82
|
-
description: 'Whether to
|
|
347
|
+
description: 'Whether to follow redirects',
|
|
83
348
|
},
|
|
84
349
|
{
|
|
85
|
-
displayName: '
|
|
86
|
-
name: '
|
|
350
|
+
displayName: 'Redirect Count',
|
|
351
|
+
name: 'maxRedirects',
|
|
87
352
|
type: 'number',
|
|
88
|
-
default: 1,
|
|
89
353
|
typeOptions: {
|
|
90
|
-
minValue: 0
|
|
91
|
-
|
|
92
|
-
|
|
354
|
+
minValue: 0,
|
|
355
|
+
},
|
|
356
|
+
displayOptions: {
|
|
357
|
+
show: {
|
|
358
|
+
followRedirect: [true],
|
|
359
|
+
},
|
|
93
360
|
},
|
|
94
|
-
|
|
361
|
+
default: 21,
|
|
362
|
+
description: 'Maximum number of redirects to follow',
|
|
95
363
|
},
|
|
96
364
|
{
|
|
97
|
-
displayName: '
|
|
98
|
-
name: '
|
|
99
|
-
type: '
|
|
100
|
-
placeholder: 'Add Margin',
|
|
101
|
-
default: {},
|
|
365
|
+
displayName: 'Response Format',
|
|
366
|
+
name: 'responseFormat',
|
|
367
|
+
type: 'options',
|
|
102
368
|
options: [
|
|
103
369
|
{
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
default: '0',
|
|
119
|
-
description: 'Bottom margin',
|
|
120
|
-
},
|
|
121
|
-
{
|
|
122
|
-
displayName: 'Left',
|
|
123
|
-
name: 'left',
|
|
124
|
-
type: 'string',
|
|
125
|
-
default: '0',
|
|
126
|
-
description: 'Left margin',
|
|
127
|
-
},
|
|
128
|
-
{
|
|
129
|
-
displayName: 'Right',
|
|
130
|
-
name: 'right',
|
|
131
|
-
type: 'string',
|
|
132
|
-
default: '0',
|
|
133
|
-
description: 'Right margin',
|
|
134
|
-
},
|
|
135
|
-
],
|
|
370
|
+
name: 'Autodetect',
|
|
371
|
+
value: 'autodetect',
|
|
372
|
+
},
|
|
373
|
+
{
|
|
374
|
+
name: 'File',
|
|
375
|
+
value: 'file',
|
|
376
|
+
},
|
|
377
|
+
{
|
|
378
|
+
name: 'JSON',
|
|
379
|
+
value: 'json',
|
|
380
|
+
},
|
|
381
|
+
{
|
|
382
|
+
name: 'Text',
|
|
383
|
+
value: 'text',
|
|
136
384
|
},
|
|
137
385
|
],
|
|
386
|
+
default: 'file',
|
|
387
|
+
description: 'The format in which the data gets returned from the URL',
|
|
138
388
|
},
|
|
139
389
|
{
|
|
140
|
-
displayName: '
|
|
141
|
-
name: '
|
|
142
|
-
type: '
|
|
143
|
-
default:
|
|
144
|
-
|
|
145
|
-
minValue: 0,
|
|
146
|
-
maxValue: 30,
|
|
147
|
-
},
|
|
148
|
-
description: 'Wait delay in seconds before PDF generation (0-30)',
|
|
390
|
+
displayName: 'Output Binary Field Name',
|
|
391
|
+
name: 'outputBinaryField',
|
|
392
|
+
type: 'string',
|
|
393
|
+
default: 'data',
|
|
394
|
+
description: 'Name of the binary property to write the file to (only used when Response Format is File)',
|
|
149
395
|
},
|
|
150
396
|
{
|
|
151
397
|
displayName: 'Timeout',
|
|
152
398
|
name: 'timeout',
|
|
153
399
|
type: 'number',
|
|
154
|
-
default: 30,
|
|
155
400
|
typeOptions: {
|
|
156
401
|
minValue: 1,
|
|
157
|
-
maxValue: 300,
|
|
158
402
|
},
|
|
159
|
-
|
|
403
|
+
default: 10000,
|
|
404
|
+
description: 'Time in ms to wait for a response before giving up on the request',
|
|
160
405
|
},
|
|
161
406
|
{
|
|
162
|
-
displayName: '
|
|
163
|
-
name: '
|
|
407
|
+
displayName: 'Proxy',
|
|
408
|
+
name: 'proxy',
|
|
164
409
|
type: 'string',
|
|
165
410
|
default: '',
|
|
166
|
-
|
|
167
|
-
|
|
411
|
+
placeholder: 'http://myproxy:3128',
|
|
412
|
+
description: 'HTTP proxy to use',
|
|
168
413
|
},
|
|
169
414
|
],
|
|
170
415
|
},
|
|
@@ -172,111 +417,151 @@ class MakePdf {
|
|
|
172
417
|
};
|
|
173
418
|
}
|
|
174
419
|
async execute() {
|
|
175
|
-
var _a;
|
|
420
|
+
var _a, _b;
|
|
176
421
|
const items = this.getInputData();
|
|
177
422
|
const returnData = [];
|
|
178
423
|
for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
|
|
179
424
|
try {
|
|
180
|
-
const
|
|
181
|
-
const
|
|
182
|
-
const
|
|
425
|
+
const method = this.getNodeParameter('method', itemIndex, 'POST');
|
|
426
|
+
const url = this.getNodeParameter('url', itemIndex, '');
|
|
427
|
+
const sendQuery = this.getNodeParameter('sendQuery', itemIndex, false);
|
|
428
|
+
const sendHeaders = this.getNodeParameter('sendHeaders', itemIndex, false);
|
|
429
|
+
const sendBody = this.getNodeParameter('sendBody', itemIndex, false);
|
|
430
|
+
const contentType = this.getNodeParameter('contentType', itemIndex, '');
|
|
183
431
|
const options = this.getNodeParameter('options', itemIndex, {});
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
432
|
+
// Build request options
|
|
433
|
+
const requestOptions = {
|
|
434
|
+
method,
|
|
435
|
+
url,
|
|
436
|
+
headers: {},
|
|
437
|
+
returnFullResponse: false,
|
|
438
|
+
};
|
|
439
|
+
// Add query parameters
|
|
440
|
+
if (sendQuery) {
|
|
441
|
+
const queryParams = this.getNodeParameter('queryParameters.parameters', itemIndex, []);
|
|
442
|
+
if (queryParams && queryParams.length > 0) {
|
|
443
|
+
const qs = {};
|
|
444
|
+
for (const param of queryParams) {
|
|
445
|
+
qs[param.name] = param.value;
|
|
446
|
+
}
|
|
447
|
+
requestOptions.qs = qs;
|
|
448
|
+
}
|
|
187
449
|
}
|
|
188
|
-
|
|
189
|
-
|
|
450
|
+
// Add headers
|
|
451
|
+
if (sendHeaders) {
|
|
452
|
+
const headerParams = this.getNodeParameter('headerParameters.parameters', itemIndex, []);
|
|
453
|
+
if (headerParams && headerParams.length > 0) {
|
|
454
|
+
for (const param of headerParams) {
|
|
455
|
+
requestOptions.headers[param.name] = param.value;
|
|
456
|
+
}
|
|
457
|
+
}
|
|
190
458
|
}
|
|
191
|
-
//
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
459
|
+
// Add body
|
|
460
|
+
if (sendBody && contentType) {
|
|
461
|
+
if (contentType === 'json') {
|
|
462
|
+
const jsonBody = this.getNodeParameter('jsonBody', itemIndex, '');
|
|
463
|
+
requestOptions.body = jsonBody;
|
|
464
|
+
requestOptions.headers['Content-Type'] = 'application/json';
|
|
465
|
+
}
|
|
466
|
+
else if (contentType === 'raw') {
|
|
467
|
+
const rawBody = this.getNodeParameter('jsonBody', itemIndex, '');
|
|
468
|
+
requestOptions.body = rawBody;
|
|
469
|
+
}
|
|
470
|
+
else if (contentType === 'form-urlencoded') {
|
|
471
|
+
const bodyParams = this.getNodeParameter('bodyParameters.parameters', itemIndex, []);
|
|
472
|
+
const form = {};
|
|
473
|
+
for (const param of bodyParams) {
|
|
474
|
+
form[param.name] = param.value;
|
|
475
|
+
}
|
|
476
|
+
requestOptions.form = form;
|
|
477
|
+
}
|
|
478
|
+
else if (contentType === 'multipart-form-data') {
|
|
479
|
+
const FormData = require('form-data');
|
|
480
|
+
const formData = new FormData();
|
|
481
|
+
const bodyParams = this.getNodeParameter('bodyParameters.parameters', itemIndex, []);
|
|
482
|
+
for (const param of bodyParams) {
|
|
483
|
+
const paramName = param.name;
|
|
484
|
+
const paramType = param.parameterType;
|
|
485
|
+
if (paramType === 'formBinaryData') {
|
|
486
|
+
const inputDataFieldName = param.inputDataFieldName;
|
|
487
|
+
const binaryData = (_a = items[itemIndex].binary) === null || _a === void 0 ? void 0 : _a[inputDataFieldName];
|
|
488
|
+
if (binaryData && binaryData.data) {
|
|
489
|
+
const buffer = Buffer.from(binaryData.data, 'base64');
|
|
490
|
+
formData.append(paramName, buffer, {
|
|
491
|
+
filename: binaryData.fileName || 'file',
|
|
492
|
+
contentType: binaryData.mimeType || 'application/octet-stream',
|
|
493
|
+
});
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
else {
|
|
497
|
+
formData.append(paramName, param.value);
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
requestOptions.body = formData;
|
|
501
|
+
Object.assign(requestOptions.headers, formData.getHeaders());
|
|
502
|
+
}
|
|
503
|
+
else if (contentType === 'binaryData') {
|
|
504
|
+
const inputBinaryField = this.getNodeParameter('inputBinaryField', itemIndex, 'data');
|
|
505
|
+
const binaryData = (_b = items[itemIndex].binary) === null || _b === void 0 ? void 0 : _b[inputBinaryField];
|
|
506
|
+
if (!binaryData || !binaryData.data) {
|
|
507
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `No binary data found in property "${inputBinaryField}"`, { itemIndex });
|
|
508
|
+
}
|
|
509
|
+
requestOptions.body = Buffer.from(binaryData.data, 'base64');
|
|
510
|
+
if (binaryData.mimeType) {
|
|
511
|
+
requestOptions.headers['Content-Type'] = binaryData.mimeType;
|
|
512
|
+
}
|
|
216
513
|
}
|
|
217
514
|
}
|
|
218
|
-
|
|
219
|
-
|
|
515
|
+
// Add options
|
|
516
|
+
if (options.allowUnauthorizedCerts === true) {
|
|
517
|
+
requestOptions.skipSslCertificateValidation = true;
|
|
220
518
|
}
|
|
221
|
-
if (options.
|
|
222
|
-
|
|
519
|
+
if (options.followRedirect !== undefined) {
|
|
520
|
+
requestOptions.followRedirect = options.followRedirect;
|
|
521
|
+
if (options.followRedirect && options.maxRedirects) {
|
|
522
|
+
requestOptions.maxRedirects = options.maxRedirects;
|
|
523
|
+
}
|
|
223
524
|
}
|
|
224
|
-
if (options.
|
|
225
|
-
|
|
525
|
+
if (options.timeout !== undefined) {
|
|
526
|
+
requestOptions.timeout = options.timeout;
|
|
226
527
|
}
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
const margins = options.margins.marginValues;
|
|
230
|
-
if (margins) {
|
|
231
|
-
if (margins.top)
|
|
232
|
-
formData.append('marginTop', margins.top);
|
|
233
|
-
if (margins.bottom)
|
|
234
|
-
formData.append('marginBottom', margins.bottom);
|
|
235
|
-
if (margins.left)
|
|
236
|
-
formData.append('marginLeft', margins.left);
|
|
237
|
-
if (margins.right)
|
|
238
|
-
formData.append('marginRight', margins.right);
|
|
239
|
-
}
|
|
528
|
+
if (options.proxy) {
|
|
529
|
+
requestOptions.proxy = options.proxy;
|
|
240
530
|
}
|
|
241
|
-
|
|
242
|
-
|
|
531
|
+
const responseFormat = options.responseFormat || 'autodetect';
|
|
532
|
+
if (responseFormat === 'file') {
|
|
533
|
+
requestOptions.encoding = 'arraybuffer';
|
|
534
|
+
requestOptions.returnFullResponse = false;
|
|
243
535
|
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
const response = await this.helpers.httpRequest({
|
|
247
|
-
method: 'POST',
|
|
248
|
-
url: gotenbergUrl,
|
|
249
|
-
body: formData,
|
|
250
|
-
headers: formData.getHeaders(),
|
|
251
|
-
encoding: 'arraybuffer',
|
|
252
|
-
returnFullResponse: false,
|
|
253
|
-
timeout,
|
|
254
|
-
});
|
|
255
|
-
// Determine output filename
|
|
256
|
-
let outputFilename = options.outputFilename || '';
|
|
257
|
-
if (!outputFilename) {
|
|
258
|
-
outputFilename = binaryData.fileName
|
|
259
|
-
? binaryData.fileName.replace(/\.[^.]+$/, '.pdf')
|
|
260
|
-
: 'output.pdf';
|
|
536
|
+
else if (responseFormat === 'json') {
|
|
537
|
+
requestOptions.json = true;
|
|
261
538
|
}
|
|
262
|
-
|
|
263
|
-
|
|
539
|
+
// Make the request
|
|
540
|
+
const response = await this.helpers.httpRequest(requestOptions);
|
|
541
|
+
// Process response
|
|
542
|
+
let newItem;
|
|
543
|
+
if (responseFormat === 'file') {
|
|
544
|
+
const outputBinaryField = options.outputBinaryField || 'data';
|
|
545
|
+
const binaryData = {
|
|
546
|
+
data: Buffer.from(response).toString('base64'),
|
|
547
|
+
mimeType: 'application/pdf',
|
|
548
|
+
fileName: 'output.pdf',
|
|
549
|
+
};
|
|
550
|
+
newItem = {
|
|
551
|
+
json: items[itemIndex].json,
|
|
552
|
+
binary: {
|
|
553
|
+
...items[itemIndex].binary,
|
|
554
|
+
[outputBinaryField]: binaryData,
|
|
555
|
+
},
|
|
556
|
+
pairedItem: itemIndex,
|
|
557
|
+
};
|
|
558
|
+
}
|
|
559
|
+
else {
|
|
560
|
+
newItem = {
|
|
561
|
+
json: typeof response === 'object' ? response : { data: response },
|
|
562
|
+
pairedItem: itemIndex,
|
|
563
|
+
};
|
|
264
564
|
}
|
|
265
|
-
// Create new binary data for PDF
|
|
266
|
-
const newBinaryData = {
|
|
267
|
-
data: Buffer.from(response).toString('base64'),
|
|
268
|
-
mimeType: 'application/pdf',
|
|
269
|
-
fileName: outputFilename,
|
|
270
|
-
};
|
|
271
|
-
// Prepare output item
|
|
272
|
-
const newItem = {
|
|
273
|
-
json: items[itemIndex].json,
|
|
274
|
-
binary: {
|
|
275
|
-
...items[itemIndex].binary,
|
|
276
|
-
[outputBinaryPropertyName]: newBinaryData,
|
|
277
|
-
},
|
|
278
|
-
pairedItem: itemIndex,
|
|
279
|
-
};
|
|
280
565
|
returnData.push(newItem);
|
|
281
566
|
}
|
|
282
567
|
catch (error) {
|