From 2bae04b87f4557bbf4c6b7bdcc3e29aa22b85f6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=A4=95=E0=A4=BE=E0=A4=B0=E0=A4=A4=E0=A5=8B=E0=A4=AB?= =?UTF-8?q?=E0=A5=8D=E0=A4=AB=E0=A5=87=E0=A4=B2=E0=A4=B8=E0=A5=8D=E0=A4=95?= =?UTF-8?q?=E0=A5=8D=E0=A4=B0=E0=A4=BF=E0=A4=AA=E0=A5=8D=E0=A4=9F=E2=84=A2?= Date: Mon, 15 May 2023 17:28:54 +0200 Subject: [PATCH] fix binary response in `own` mode --- packages/cli/src/WebhookHelpers.ts | 20 +++++++++---------- .../RespondToWebhook/RespondToWebhook.node.ts | 5 ++--- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/packages/cli/src/WebhookHelpers.ts b/packages/cli/src/WebhookHelpers.ts index 48be4b9deef94..a85829afb2fe3 100644 --- a/packages/cli/src/WebhookHelpers.ts +++ b/packages/cli/src/WebhookHelpers.ts @@ -21,6 +21,7 @@ import { promisify } from 'util'; import { BinaryDataManager, NodeExecuteFunctions, eventEmitter } from 'n8n-core'; import type { + IBinaryData, IBinaryKeyData, IDataObject, IDeferredPromise, @@ -422,17 +423,16 @@ export async function executeWebhook( return; } - const isBuffer = Buffer.isBuffer(response.body); - const isStream = response.body instanceof stream.Readable; - if (isBuffer || isStream) { + const binaryData = (response.body as IDataObject)?.binaryData as IBinaryData; + if (binaryData?.id) { + const stream = NodeExecuteFunctions.getBinaryStream(binaryData.id); + void pipeline(stream, res).then(() => + responseCallback(null, { noWebhookResponse: true }), + ); + } else if (Buffer.isBuffer(response.body)) { res.header(response.headers); - if (isBuffer) { - res.end(response.body); - responseCallback(null, { noWebhookResponse: true }); - } else - void pipeline(response.body as stream.Readable, res).then(() => - responseCallback(null, { noWebhookResponse: true }), - ); + res.end(response.body); + responseCallback(null, { noWebhookResponse: true }); } else { // TODO: This probably needs some more changes depending on the options on the // Webhook Response node diff --git a/packages/nodes-base/nodes/RespondToWebhook/RespondToWebhook.node.ts b/packages/nodes-base/nodes/RespondToWebhook/RespondToWebhook.node.ts index ec0d6c8bcfbdc..699dd40a528e3 100644 --- a/packages/nodes-base/nodes/RespondToWebhook/RespondToWebhook.node.ts +++ b/packages/nodes-base/nodes/RespondToWebhook/RespondToWebhook.node.ts @@ -234,11 +234,10 @@ export class RespondToWebhook implements INodeType { } responseBinaryPropertyName = binaryKeys[0]; } + const binaryData = this.helpers.assertBinaryData(0, responseBinaryPropertyName); if (binaryData.id) { - responseBody = this.helpers.getBinaryStream(binaryData.id); - const metadata = await this.helpers.getBinaryMetadata(binaryData.id); - headers['content-length'] = metadata.fileSize; + responseBody = { binaryData }; } else { responseBody = Buffer.from(binaryData.data, BINARY_ENCODING); headers['content-length'] = (responseBody as Buffer).length;