mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
feat(Respond to Webhook Node): Move from Binary Buffer to Binary streaming (#5613)
* replace binary buffer with binary streaming * Add binary assertion and remove duplicate code * handle streams correctly * fix binary response in `own` mode * fix stream response missing headers --------- Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <netroy@users.noreply.github.com> Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in> Co-authored-by: Marcus <marcus@n8n.io>
This commit is contained in:
@@ -15,10 +15,13 @@
|
||||
/* eslint-disable prefer-destructuring */
|
||||
import type express from 'express';
|
||||
import get from 'lodash.get';
|
||||
import stream from 'stream';
|
||||
import { promisify } from 'util';
|
||||
|
||||
import { BinaryDataManager, NodeExecuteFunctions, eventEmitter } from 'n8n-core';
|
||||
|
||||
import type {
|
||||
IBinaryData,
|
||||
IBinaryKeyData,
|
||||
IDataObject,
|
||||
IDeferredPromise,
|
||||
@@ -59,6 +62,8 @@ import type { WorkflowEntity } from '@db/entities/WorkflowEntity';
|
||||
import { getWorkflowOwner } from '@/UserManagement/UserManagementHelper';
|
||||
import { Container } from 'typedi';
|
||||
|
||||
const pipeline = promisify(stream.pipeline);
|
||||
|
||||
export const WEBHOOK_METHODS = ['DELETE', 'GET', 'HEAD', 'PATCH', 'POST', 'PUT'];
|
||||
|
||||
/**
|
||||
@@ -418,13 +423,17 @@ export async function executeWebhook(
|
||||
return;
|
||||
}
|
||||
|
||||
if (Buffer.isBuffer(response.body)) {
|
||||
const binaryData = (response.body as IDataObject)?.binaryData as IBinaryData;
|
||||
if (binaryData?.id) {
|
||||
res.header(response.headers);
|
||||
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);
|
||||
res.end(response.body);
|
||||
|
||||
responseCallback(null, {
|
||||
noWebhookResponse: true,
|
||||
});
|
||||
responseCallback(null, { noWebhookResponse: true });
|
||||
} else {
|
||||
// TODO: This probably needs some more changes depending on the options on the
|
||||
// Webhook Response node
|
||||
|
||||
Reference in New Issue
Block a user