@custom-js/n8n-nodes-pdf-toolkit 1.48.0 → 1.50.0
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/README.md +39 -0
- package/dist/nodes/CompressPDF/CompressPDF.node.js +63 -40
- package/dist/nodes/ExtractPages/ExtractPages.node.js +64 -41
- package/dist/nodes/GetFormFieldNames/GetFormFieldNames.node.js +50 -30
- package/dist/nodes/Html2Docx/Html2Docx.node.js +51 -28
- package/dist/nodes/Html2Pdf/Html2Pdf.node.js +51 -28
- package/dist/nodes/InvoiceGenerator/InvoiceGenerator.node.js +93 -70
- package/dist/nodes/Markdown2Html/Markdown2Html.node.js +42 -22
- package/dist/nodes/MergePdfs/MergePdfs.node.js +60 -37
- package/dist/nodes/PdfFormFill/PdfFormFill.node.js +60 -37
- package/dist/nodes/PdfToPng/PdfToPng.node.js +59 -36
- package/dist/nodes/PdfToText/PdfToText.node.js +50 -30
- package/dist/nodes/SSLChecker/SSLChecker.node.js +41 -21
- package/dist/nodes/Scraper/Scraper.node.js +75 -49
- package/dist/nodes/WebsiteScreenshot/WebsiteScreenshot.node.js +51 -28
- package/package.json +4 -4
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.InvoiceGenerator = void 0;
|
|
4
|
+
const n8n_workflow_1 = require("n8n-workflow");
|
|
4
5
|
class InvoiceGenerator {
|
|
5
6
|
constructor() {
|
|
6
7
|
this.description = {
|
|
@@ -187,56 +188,57 @@ class InvoiceGenerator {
|
|
|
187
188
|
const items = this.getInputData();
|
|
188
189
|
const returnData = [];
|
|
189
190
|
for (let i = 0; i < items.length; i++) {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
191
|
+
try { // Added try block
|
|
192
|
+
const credentials = await this.getCredentials('customJsApi');
|
|
193
|
+
const pdfTemplate = this.getNodeParameter('pdfTemplate', i);
|
|
194
|
+
const issuer = this.getNodeParameter('issuer.issuerValues', i);
|
|
195
|
+
const payment = this.getNodeParameter('payment.paymentValues', i);
|
|
196
|
+
const recipient = this.getNodeParameter('recipient.recipientValues', i);
|
|
197
|
+
const billing = this.getNodeParameter('billing.billingValues', i);
|
|
198
|
+
const itemsMode = this.getNodeParameter('itemsMode', i);
|
|
199
|
+
let invoiceItems;
|
|
200
|
+
if (itemsMode === 'json') {
|
|
201
|
+
const itemsJson = this.getNodeParameter('itemsJson', i);
|
|
202
|
+
if (typeof itemsJson === 'string') {
|
|
203
|
+
try {
|
|
204
|
+
invoiceItems = JSON.parse(itemsJson);
|
|
205
|
+
}
|
|
206
|
+
catch (error) {
|
|
207
|
+
if (error instanceof Error) {
|
|
208
|
+
throw new Error(`Invalid JSON in 'Items JSON' field: ${error.message}`);
|
|
209
|
+
}
|
|
210
|
+
throw new Error(`Invalid JSON in 'Items JSON' field: ${String(error)}`);
|
|
207
211
|
}
|
|
208
|
-
throw new Error(`Invalid JSON in 'Items JSON' field: ${String(error)}`);
|
|
209
212
|
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
+
else if (Array.isArray(itemsJson)) {
|
|
214
|
+
invoiceItems = itemsJson;
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
invoiceItems = [];
|
|
218
|
+
}
|
|
213
219
|
}
|
|
214
220
|
else {
|
|
215
|
-
|
|
221
|
+
const itemsData = this.getNodeParameter('items', i);
|
|
222
|
+
invoiceItems = itemsData.itemsValues;
|
|
216
223
|
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
224
|
+
invoiceItems = invoiceItems.map(item => {
|
|
225
|
+
return {
|
|
226
|
+
description: item.description,
|
|
227
|
+
quantity: Number(item.quantity),
|
|
228
|
+
unitPrice: Number(item.unitPrice),
|
|
229
|
+
};
|
|
230
|
+
});
|
|
231
|
+
const invoiceData = {
|
|
232
|
+
issuer,
|
|
233
|
+
payment,
|
|
234
|
+
recipient,
|
|
235
|
+
billing,
|
|
236
|
+
items: invoiceItems,
|
|
227
237
|
};
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
recipient,
|
|
233
|
-
billing,
|
|
234
|
-
items: invoiceItems,
|
|
235
|
-
};
|
|
236
|
-
const code = `
|
|
237
|
-
const { HTML2PDF } = requir` + `e('./utils');
|
|
238
|
-
const nunjucks = requir` + `e('nunjucks');
|
|
239
|
-
const fetch = requir` + `e('node-fetch');
|
|
238
|
+
const code = `
|
|
239
|
+
const { HTML2PDF } = require('./utils');
|
|
240
|
+
const nunjucks = require('nunjucks');
|
|
241
|
+
const fetch = require('node-fetch');
|
|
240
242
|
const tpl = 'https://www.customjs.space/pdf-templates/Invoice1.html';
|
|
241
243
|
const templateString = await fetch(tpl).then(r => r.text());
|
|
242
244
|
const renderedHtml = await nunjucks.renderString(
|
|
@@ -245,38 +247,59 @@ class InvoiceGenerator {
|
|
|
245
247
|
|
|
246
248
|
}
|
|
247
249
|
);
|
|
248
|
-
|
|
250
|
+
|
|
249
251
|
return HTML2PDF(renderedHtml);
|
|
250
252
|
`;
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
253
|
+
const options = {
|
|
254
|
+
url: `https://e.customjs.io/__js1-${credentials.apiKey}`,
|
|
255
|
+
method: 'POST',
|
|
256
|
+
headers: {
|
|
257
|
+
'customjs-origin': 'n8n/invoice-generator',
|
|
258
|
+
},
|
|
259
|
+
body: {
|
|
260
|
+
input: invoiceData,
|
|
261
|
+
code: code,
|
|
262
|
+
returnBinary: 'true',
|
|
263
|
+
},
|
|
264
|
+
encoding: null,
|
|
265
|
+
json: true,
|
|
266
|
+
};
|
|
267
|
+
const response = await this.helpers.requestWithAuthentication.call(this, 'customJsApi', options);
|
|
268
|
+
if (!response || (Buffer.isBuffer(response) && response.length === 0)) {
|
|
269
|
+
returnData.push({
|
|
270
|
+
json: items[i].json,
|
|
271
|
+
pairedItem: {
|
|
272
|
+
item: i,
|
|
273
|
+
},
|
|
274
|
+
});
|
|
275
|
+
continue;
|
|
276
|
+
}
|
|
277
|
+
const binaryData = await this.helpers.prepareBinaryData(response, "Invoice.pdf");
|
|
268
278
|
returnData.push({
|
|
269
279
|
json: items[i].json,
|
|
280
|
+
binary: {
|
|
281
|
+
data: binaryData,
|
|
282
|
+
},
|
|
283
|
+
pairedItem: {
|
|
284
|
+
item: i,
|
|
285
|
+
},
|
|
270
286
|
});
|
|
271
|
-
continue;
|
|
272
287
|
}
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
288
|
+
catch (error) { // Added catch block
|
|
289
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
290
|
+
if (this.continueOnFail()) {
|
|
291
|
+
returnData.push({
|
|
292
|
+
json: {
|
|
293
|
+
error: errorMessage,
|
|
294
|
+
},
|
|
295
|
+
pairedItem: {
|
|
296
|
+
item: i,
|
|
297
|
+
},
|
|
298
|
+
});
|
|
299
|
+
continue;
|
|
300
|
+
}
|
|
301
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), error, { itemIndex: i });
|
|
302
|
+
}
|
|
280
303
|
}
|
|
281
304
|
return [returnData];
|
|
282
305
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Markdown2Html = void 0;
|
|
4
|
+
const n8n_workflow_1 = require("n8n-workflow");
|
|
4
5
|
class Markdown2Html {
|
|
5
6
|
constructor() {
|
|
6
7
|
this.description = {
|
|
@@ -40,28 +41,47 @@ class Markdown2Html {
|
|
|
40
41
|
const items = this.getInputData();
|
|
41
42
|
const returnData = [];
|
|
42
43
|
for (let i = 0; i < items.length; i++) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
44
|
+
try {
|
|
45
|
+
const credentials = await this.getCredentials("customJsApi");
|
|
46
|
+
const markdownInput = this.getNodeParameter("markdownInput", i);
|
|
47
|
+
const options = {
|
|
48
|
+
url: `https://e.customjs.io/__js1-${credentials.apiKey}`,
|
|
49
|
+
method: 'POST',
|
|
50
|
+
headers: {
|
|
51
|
+
"customjs-origin": "n8n/markdown2html",
|
|
52
|
+
},
|
|
53
|
+
body: {
|
|
54
|
+
input: markdownInput,
|
|
55
|
+
code: "const { MD2HTML } = require('./utils'); return MD2HTML(input)",
|
|
56
|
+
returnBinary: "false",
|
|
57
|
+
},
|
|
58
|
+
json: true,
|
|
59
|
+
};
|
|
60
|
+
const response = await this.helpers.requestWithAuthentication.call(this, 'customJsApi', options);
|
|
61
|
+
returnData.push({
|
|
62
|
+
json: {
|
|
63
|
+
output: response.toString(),
|
|
64
|
+
},
|
|
65
|
+
pairedItem: {
|
|
66
|
+
item: i,
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
72
|
+
if (this.continueOnFail()) {
|
|
73
|
+
returnData.push({
|
|
74
|
+
json: {
|
|
75
|
+
error: errorMessage,
|
|
76
|
+
},
|
|
77
|
+
pairedItem: {
|
|
78
|
+
item: i,
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), error, { itemIndex: i });
|
|
84
|
+
}
|
|
65
85
|
}
|
|
66
86
|
return [returnData];
|
|
67
87
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MergePdfs = void 0;
|
|
4
|
+
const n8n_workflow_1 = require("n8n-workflow");
|
|
4
5
|
class MergePdfs {
|
|
5
6
|
constructor() {
|
|
6
7
|
this.description = {
|
|
@@ -52,49 +53,71 @@ class MergePdfs {
|
|
|
52
53
|
async execute() {
|
|
53
54
|
const items = this.getInputData();
|
|
54
55
|
const returnData = [];
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
const { PDF_MERGE } =
|
|
56
|
+
try {
|
|
57
|
+
const credentials = await this.getCredentials("customJsApi");
|
|
58
|
+
const isBinary = this.getNodeParameter("resource", 0) === "binary";
|
|
59
|
+
const field_name = this.getNodeParameter("field_name", 0);
|
|
60
|
+
const files = isBinary ? items.map((item, i) => {
|
|
61
|
+
var _a;
|
|
62
|
+
if ((_a = item.binary) === null || _a === void 0 ? void 0 : _a.data) {
|
|
63
|
+
return Buffer.from(item.binary.data.data, "base64");
|
|
64
|
+
}
|
|
65
|
+
}) : [];
|
|
66
|
+
const urls = !isBinary ? field_name : [];
|
|
67
|
+
const options = {
|
|
68
|
+
url: `https://e.customjs.io/__js1-${credentials.apiKey}`,
|
|
69
|
+
method: 'POST',
|
|
70
|
+
headers: {
|
|
71
|
+
"customjs-origin": "n8n/mergePDFs",
|
|
72
|
+
},
|
|
73
|
+
body: {
|
|
74
|
+
input: isBinary ? { files } : { urls },
|
|
75
|
+
code: `
|
|
76
|
+
const { PDF_MERGE } = require('./utils');
|
|
76
77
|
input = [...input.files || [],...input.urls || []].filter(i => i);
|
|
77
78
|
return PDF_MERGE(input);`,
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
79
|
+
returnBinary: "true",
|
|
80
|
+
},
|
|
81
|
+
encoding: null,
|
|
82
|
+
json: true,
|
|
83
|
+
};
|
|
84
|
+
const response = await this.helpers.requestWithAuthentication.call(this, 'customJsApi', options);
|
|
85
|
+
if (!response || (Buffer.isBuffer(response) && response.length === 0)) {
|
|
86
|
+
// No binary data returned; emit only JSON without a binary property
|
|
87
|
+
returnData.push({
|
|
88
|
+
json: {},
|
|
89
|
+
pairedItem: items.map((_, i) => ({
|
|
90
|
+
item: i,
|
|
91
|
+
})),
|
|
92
|
+
});
|
|
93
|
+
return [returnData];
|
|
94
|
+
}
|
|
95
|
+
const binaryData = await this.helpers.prepareBinaryData(response, "output.pdf");
|
|
86
96
|
returnData.push({
|
|
87
97
|
json: {},
|
|
98
|
+
binary: {
|
|
99
|
+
data: binaryData,
|
|
100
|
+
},
|
|
101
|
+
pairedItem: items.map((_, i) => ({
|
|
102
|
+
item: i,
|
|
103
|
+
})),
|
|
88
104
|
});
|
|
89
|
-
return [returnData];
|
|
90
105
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
106
|
+
catch (error) {
|
|
107
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
108
|
+
if (this.continueOnFail()) {
|
|
109
|
+
returnData.push({
|
|
110
|
+
json: {
|
|
111
|
+
error: errorMessage,
|
|
112
|
+
},
|
|
113
|
+
pairedItem: items.map((_, i) => ({
|
|
114
|
+
item: i,
|
|
115
|
+
})),
|
|
116
|
+
});
|
|
117
|
+
return [returnData];
|
|
118
|
+
}
|
|
119
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), error);
|
|
120
|
+
}
|
|
98
121
|
return [returnData];
|
|
99
122
|
}
|
|
100
123
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PdfFormFill = void 0;
|
|
4
|
+
const n8n_workflow_1 = require("n8n-workflow");
|
|
4
5
|
class PdfFormFill {
|
|
5
6
|
constructor() {
|
|
6
7
|
this.description = {
|
|
@@ -90,51 +91,73 @@ class PdfFormFill {
|
|
|
90
91
|
return Buffer.from(file.data, "base64");
|
|
91
92
|
};
|
|
92
93
|
for (let i = 0; i < items.length; i++) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
},
|
|
107
|
-
body: {
|
|
108
|
-
input: {
|
|
109
|
-
file: file,
|
|
110
|
-
// n8n fixedCollection with multipleValues returns an object like { field: [{ name, value }, ...] }
|
|
111
|
-
fields: ((_a = this.getNodeParameter("fields", i)) === null || _a === void 0 ? void 0 : _a.field) || []
|
|
94
|
+
try {
|
|
95
|
+
const credentials = await this.getCredentials("customJsApi");
|
|
96
|
+
const field_name = this.getNodeParameter("field_name", i);
|
|
97
|
+
const isBinary = this.getNodeParameter("resource", i) === "binary";
|
|
98
|
+
const file = isBinary ? getFile(field_name, i) : "";
|
|
99
|
+
if (!isBinary) {
|
|
100
|
+
throw new Error(`Invalid binary data`);
|
|
101
|
+
}
|
|
102
|
+
const options = {
|
|
103
|
+
url: `https://e.customjs.io/__js1-${credentials.apiKey}`,
|
|
104
|
+
method: 'POST',
|
|
105
|
+
headers: {
|
|
106
|
+
"customjs-origin": "n8n/pdfFormFill",
|
|
112
107
|
},
|
|
113
|
-
|
|
114
|
-
|
|
108
|
+
body: {
|
|
109
|
+
input: {
|
|
110
|
+
file: file,
|
|
111
|
+
// n8n fixedCollection with multipleValues returns an object like { field: [{ name, value }, ...] }
|
|
112
|
+
fields: ((_a = this.getNodeParameter("fields", i)) === null || _a === void 0 ? void 0 : _a.field) || []
|
|
113
|
+
},
|
|
114
|
+
code: `
|
|
115
|
+
const { PDF_FILL_FORM } = require('./utils');
|
|
115
116
|
const pdfInput = input.file;
|
|
116
117
|
const fieldValues = Object.fromEntries((input.fields || []).map(x => [x.name, x.value]));
|
|
117
118
|
return PDF_FILL_FORM(pdfInput, fieldValues);`,
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
119
|
+
returnBinary: "true",
|
|
120
|
+
},
|
|
121
|
+
encoding: null,
|
|
122
|
+
json: true,
|
|
123
|
+
};
|
|
124
|
+
const response = await this.helpers.requestWithAuthentication.call(this, 'customJsApi', options);
|
|
125
|
+
if (!response || (Buffer.isBuffer(response) && response.length === 0)) {
|
|
126
|
+
// No binary data returned; emit only JSON without a binary property
|
|
127
|
+
returnData.push({
|
|
128
|
+
json: items[i].json,
|
|
129
|
+
pairedItem: {
|
|
130
|
+
item: i,
|
|
131
|
+
},
|
|
132
|
+
});
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
const binaryData = await this.helpers.prepareBinaryData(response, "document.pdf");
|
|
126
136
|
returnData.push({
|
|
127
137
|
json: items[i].json,
|
|
138
|
+
binary: {
|
|
139
|
+
data: binaryData,
|
|
140
|
+
},
|
|
141
|
+
pairedItem: {
|
|
142
|
+
item: i,
|
|
143
|
+
},
|
|
128
144
|
});
|
|
129
|
-
continue;
|
|
130
145
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
146
|
+
catch (error) {
|
|
147
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
148
|
+
if (this.continueOnFail()) {
|
|
149
|
+
returnData.push({
|
|
150
|
+
json: {
|
|
151
|
+
error: errorMessage,
|
|
152
|
+
},
|
|
153
|
+
pairedItem: {
|
|
154
|
+
item: i,
|
|
155
|
+
},
|
|
156
|
+
});
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), error, { itemIndex: i });
|
|
160
|
+
}
|
|
138
161
|
}
|
|
139
162
|
return [returnData];
|
|
140
163
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PdfToPng = void 0;
|
|
4
|
+
const n8n_workflow_1 = require("n8n-workflow");
|
|
4
5
|
class PdfToPng {
|
|
5
6
|
constructor() {
|
|
6
7
|
this.description = {
|
|
@@ -61,48 +62,70 @@ class PdfToPng {
|
|
|
61
62
|
return Buffer.from(file.data, "base64");
|
|
62
63
|
};
|
|
63
64
|
for (let i = 0; i < items.length; i++) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
!
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
const { PDF2PNG } =
|
|
65
|
+
try {
|
|
66
|
+
const credentials = await this.getCredentials("customJsApi");
|
|
67
|
+
const field_name = this.getNodeParameter("field_name", i);
|
|
68
|
+
const isBinary = this.getNodeParameter("resource", i) === "binary";
|
|
69
|
+
const file = isBinary ? getFile(field_name, i) : "";
|
|
70
|
+
if (!isBinary &&
|
|
71
|
+
!field_name.startsWith("http://") &&
|
|
72
|
+
!field_name.startsWith("https://")) {
|
|
73
|
+
throw new Error(`Invalid URL: ${field_name}`);
|
|
74
|
+
}
|
|
75
|
+
const options = {
|
|
76
|
+
url: `https://e.customjs.io/__js1-${credentials.apiKey}`,
|
|
77
|
+
method: 'POST',
|
|
78
|
+
headers: {
|
|
79
|
+
"customjs-origin": "n8n/pdfToPng",
|
|
80
|
+
},
|
|
81
|
+
body: {
|
|
82
|
+
input: isBinary ? { file: file } : { urls: field_name },
|
|
83
|
+
code: `
|
|
84
|
+
const { PDF2PNG } = require('./utils');
|
|
84
85
|
input = input.file || input.urls;
|
|
85
86
|
return PDF2PNG(input);`,
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
87
|
+
returnBinary: "true",
|
|
88
|
+
},
|
|
89
|
+
encoding: null,
|
|
90
|
+
json: true,
|
|
91
|
+
};
|
|
92
|
+
const response = await this.helpers.requestWithAuthentication.call(this, 'customJsApi', options);
|
|
93
|
+
if (!response || (Buffer.isBuffer(response) && response.length === 0)) {
|
|
94
|
+
// No binary data returned; emit only JSON without a binary property
|
|
95
|
+
returnData.push({
|
|
96
|
+
json: items[i].json,
|
|
97
|
+
pairedItem: {
|
|
98
|
+
item: i,
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
const binaryData = await this.helpers.prepareBinaryData(response, "output.png");
|
|
94
104
|
returnData.push({
|
|
95
105
|
json: items[i].json,
|
|
106
|
+
binary: {
|
|
107
|
+
data: binaryData,
|
|
108
|
+
},
|
|
109
|
+
pairedItem: {
|
|
110
|
+
item: i,
|
|
111
|
+
},
|
|
96
112
|
});
|
|
97
|
-
continue;
|
|
98
113
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
114
|
+
catch (error) {
|
|
115
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
116
|
+
if (this.continueOnFail()) {
|
|
117
|
+
returnData.push({
|
|
118
|
+
json: {
|
|
119
|
+
error: errorMessage,
|
|
120
|
+
},
|
|
121
|
+
pairedItem: {
|
|
122
|
+
item: i,
|
|
123
|
+
},
|
|
124
|
+
});
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), error, { itemIndex: i });
|
|
128
|
+
}
|
|
106
129
|
}
|
|
107
130
|
return [returnData];
|
|
108
131
|
}
|