mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-09 22:24:05 -08:00
fix(Webhook Node): Do not create binary data when there is no data in the request (#8000)
https://linear.app/n8n/issue/NODE-980/do-not-create-binary-data-for-webhooks-when-there-is-no-data-in-the related: https://github.com/n8n-io/n8n/pull/7804/files#r1422641833 --------- Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
This commit is contained in:
parent
61129863f1
commit
70f0755278
|
@ -1,6 +1,7 @@
|
|||
/* eslint-disable n8n-nodes-base/node-execute-block-wrong-error-thrown */
|
||||
import { pipeline } from 'stream/promises';
|
||||
import { createWriteStream } from 'fs';
|
||||
import { stat } from 'fs/promises';
|
||||
import type {
|
||||
IWebhookFunctions,
|
||||
ICredentialDataDecryptedObject,
|
||||
|
@ -216,7 +217,6 @@ export class Webhook extends Node {
|
|||
const { data, files } = req.body;
|
||||
|
||||
const returnItem: INodeExecutionData = {
|
||||
binary: {},
|
||||
json: {
|
||||
headers: req.headers,
|
||||
params: req.params,
|
||||
|
@ -225,6 +225,10 @@ export class Webhook extends Node {
|
|||
},
|
||||
};
|
||||
|
||||
if (files?.length) {
|
||||
returnItem.binary = {};
|
||||
}
|
||||
|
||||
let count = 0;
|
||||
|
||||
for (const key of Object.keys(files)) {
|
||||
|
@ -274,7 +278,6 @@ export class Webhook extends Node {
|
|||
await pipeline(req, createWriteStream(binaryFile.path));
|
||||
|
||||
const returnItem: INodeExecutionData = {
|
||||
binary: {},
|
||||
json: {
|
||||
headers: req.headers,
|
||||
params: req.params,
|
||||
|
@ -283,20 +286,18 @@ export class Webhook extends Node {
|
|||
},
|
||||
};
|
||||
|
||||
const binaryPropertyName = (options.binaryPropertyName || 'data') as string;
|
||||
const fileName = req.contentDisposition?.filename ?? uuid();
|
||||
const binaryData = await context.nodeHelpers.copyBinaryFile(
|
||||
binaryFile.path,
|
||||
fileName,
|
||||
req.contentType ?? 'application/octet-stream',
|
||||
);
|
||||
|
||||
if (!binaryData.data) {
|
||||
return { workflowData: [[returnItem]] };
|
||||
const stats = await stat(binaryFile.path);
|
||||
if (stats.size) {
|
||||
const binaryPropertyName = (options.binaryPropertyName ?? 'data') as string;
|
||||
const fileName = req.contentDisposition?.filename ?? uuid();
|
||||
const binaryData = await context.nodeHelpers.copyBinaryFile(
|
||||
binaryFile.path,
|
||||
fileName,
|
||||
req.contentType ?? 'application/octet-stream',
|
||||
);
|
||||
returnItem.binary = { [binaryPropertyName]: binaryData };
|
||||
}
|
||||
|
||||
returnItem.binary![binaryPropertyName] = binaryData;
|
||||
|
||||
return { workflowData: [[returnItem]] };
|
||||
} catch (error) {
|
||||
throw new NodeOperationError(context.getNode(), error as Error);
|
||||
|
|
Loading…
Reference in a new issue