Skip to content

Commit

Permalink
fix binary response in own mode
Browse files Browse the repository at this point in the history
  • Loading branch information
netroy committed May 15, 2023
1 parent 9ff8633 commit 2bae04b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
20 changes: 10 additions & 10 deletions packages/cli/src/WebhookHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { promisify } from 'util';
import { BinaryDataManager, NodeExecuteFunctions, eventEmitter } from 'n8n-core';

import type {
IBinaryData,
IBinaryKeyData,
IDataObject,
IDeferredPromise,
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 2bae04b

Please sign in to comment.