@custom-js/n8n-nodes-pdf-toolkit 1.49.0 → 1.51.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.
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.WebsiteScreenshot = void 0;
4
+ const n8n_workflow_1 = require("n8n-workflow");
4
5
  class WebsiteScreenshot {
5
6
  constructor() {
6
7
  this.description = {
@@ -30,6 +31,14 @@ class WebsiteScreenshot {
30
31
  description: "The url for taking screenshot",
31
32
  required: true,
32
33
  },
34
+ {
35
+ displayName: "Output Filename",
36
+ name: "outputFilename",
37
+ type: "string",
38
+ default: "output.png",
39
+ description: "Name for the generated PNG file (include .png extension)",
40
+ required: false,
41
+ },
33
42
  ],
34
43
  };
35
44
  }
@@ -37,38 +46,61 @@ class WebsiteScreenshot {
37
46
  const items = this.getInputData();
38
47
  const returnData = [];
39
48
  for (let i = 0; i < items.length; i++) {
40
- const credentials = await this.getCredentials("customJsApi");
41
- const urlInput = this.getNodeParameter("urlInput", i);
42
- const options = {
43
- url: `https://e.customjs.io/__js1-${credentials.apiKey}`,
44
- method: 'POST',
45
- headers: {
46
- "customjs-origin": "n8n/screenshot",
47
- "x-api-key": credentials.apiKey,
48
- },
49
- body: {
50
- input: urlInput,
51
- code: "const { SCREENSHOT } = require('./utils'); return SCREENSHOT(input);",
52
- returnBinary: "true",
53
- },
54
- encoding: 'arraybuffer',
55
- json: true,
56
- };
57
- const response = await this.helpers.httpRequest(options);
58
- if (!response || (Buffer.isBuffer(response) && response.length === 0)) {
59
- // No binary data returned; emit only JSON without a binary property
49
+ try {
50
+ const credentials = await this.getCredentials("customJsApi");
51
+ const urlInput = this.getNodeParameter("urlInput", i);
52
+ const options = {
53
+ url: `https://e.customjs.io/__js1-${credentials.apiKey}`,
54
+ method: 'POST',
55
+ headers: {
56
+ "customjs-origin": "n8n/screenshot",
57
+ },
58
+ body: {
59
+ input: urlInput,
60
+ code: "const { SCREENSHOT } = require('./utils'); return SCREENSHOT(input);",
61
+ returnBinary: "true",
62
+ },
63
+ encoding: null,
64
+ json: true,
65
+ };
66
+ const response = await this.helpers.requestWithAuthentication.call(this, 'customJsApi', options);
67
+ if (!response || (Buffer.isBuffer(response) && response.length === 0)) {
68
+ // No binary data returned; emit only JSON without a binary property
69
+ returnData.push({
70
+ json: items[i].json,
71
+ pairedItem: {
72
+ item: i,
73
+ },
74
+ });
75
+ continue;
76
+ }
77
+ const outputFilename = this.getNodeParameter("outputFilename", i, "output.png");
78
+ const binaryData = await this.helpers.prepareBinaryData(response, outputFilename);
60
79
  returnData.push({
61
80
  json: items[i].json,
81
+ binary: {
82
+ data: binaryData,
83
+ },
84
+ pairedItem: {
85
+ item: i,
86
+ },
62
87
  });
63
- continue;
64
88
  }
65
- const binaryData = await this.helpers.prepareBinaryData(response, "output.png");
66
- returnData.push({
67
- json: items[i].json,
68
- binary: {
69
- data: binaryData,
70
- },
71
- });
89
+ catch (error) {
90
+ const errorMessage = error instanceof Error ? error.message : String(error);
91
+ if (this.continueOnFail()) {
92
+ returnData.push({
93
+ json: {
94
+ error: errorMessage,
95
+ },
96
+ pairedItem: {
97
+ item: i,
98
+ },
99
+ });
100
+ continue;
101
+ }
102
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), error, { itemIndex: i });
103
+ }
72
104
  }
73
105
  return [returnData];
74
106
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@custom-js/n8n-nodes-pdf-toolkit",
3
- "version": "1.49.0",
3
+ "version": "1.51.0",
4
4
  "description": "This is official node for interacting with APIs from customjs.space",
5
5
  "keywords": [
6
6
  "customjs",