@warleon/n8n-nodes-payload-cms 1.2.9 → 1.3.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.
@@ -262,6 +262,13 @@ class PayloadCms {
262
262
  default: "",
263
263
  description: "Locale for localized content",
264
264
  },
265
+ {
266
+ displayName: "Upload",
267
+ name: "upload",
268
+ type: "string",
269
+ default: "data",
270
+ description: "Name of the binary property that contains the file to upload",
271
+ },
265
272
  ],
266
273
  },
267
274
  ],
@@ -443,14 +450,40 @@ class PayloadCms {
443
450
  break;
444
451
  }
445
452
  }
446
- const requestConfig = {
447
- method: method,
448
- url,
449
- params,
450
- };
451
- if (data) {
452
- requestConfig.data =
453
- typeof data === "string" ? JSON.parse(data) : data;
453
+ let requestConfig = {};
454
+ // handle binary inputs
455
+ const binaryPropertyName = this.getNodeParameter("upload", 0, "");
456
+ if (binaryPropertyName !== "") {
457
+ const binaryData = this.helpers.assertBinaryData(0, binaryPropertyName);
458
+ const fileBuffer = await this.helpers.getBinaryDataBuffer(0, binaryPropertyName);
459
+ const fileName = binaryData.fileName;
460
+ const mimeType = binaryData.mimeType;
461
+ const formData = new FormData();
462
+ formData.append("file", fileBuffer, {
463
+ filename: fileName,
464
+ contentType: mimeType,
465
+ });
466
+ if (data) {
467
+ const sanitizeData = typeof data === "string" ? JSON.parse(data) : data;
468
+ formData.append("_payload", JSON.stringify(sanitizeData));
469
+ }
470
+ requestConfig = {
471
+ method: method,
472
+ url,
473
+ params,
474
+ data: formData,
475
+ };
476
+ }
477
+ else {
478
+ requestConfig = {
479
+ method: method,
480
+ url,
481
+ params,
482
+ };
483
+ if (data) {
484
+ requestConfig.data =
485
+ typeof data === "string" ? JSON.parse(data) : data;
486
+ }
454
487
  }
455
488
  const response = await PayloadCms.prototype.makeAuthenticatedRequest.call(this, requestConfig);
456
489
  returnData.push({
@@ -461,6 +494,7 @@ class PayloadCms {
461
494
  });
462
495
  }
463
496
  catch (error) {
497
+ console.error("PayloadCMS Error:", error);
464
498
  if (this.continueOnFail()) {
465
499
  returnData.push({
466
500
  json: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@warleon/n8n-nodes-payload-cms",
3
- "version": "1.2.9",
3
+ "version": "1.3.1",
4
4
  "description": "Dynamic n8n node for Payload CMS that auto-discovers collections and operations forked and extended from https://github.com/leadership-institute/n8n-payload-dynamic",
5
5
  "main": "dist/index.js",
6
6
  "author": "warleon",