mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
🔀 Merge branch 'RicardoE105-feature/webhook-binary-data'
This commit is contained in:
commit
d98b45d122
|
@ -219,6 +219,35 @@ export class Webhook implements INodeType {
|
||||||
placeholder: 'Add Option',
|
placeholder: 'Add Option',
|
||||||
default: {},
|
default: {},
|
||||||
options: [
|
options: [
|
||||||
|
{
|
||||||
|
displayName: 'Binary Data',
|
||||||
|
name: 'binaryData',
|
||||||
|
type: 'boolean',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
'/httpMethod': [
|
||||||
|
'POST',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
default: false,
|
||||||
|
description: 'Set to true if webhook will receive binary data.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Binary Property',
|
||||||
|
name: 'binaryPropertyName',
|
||||||
|
type: 'string',
|
||||||
|
default: 'data',
|
||||||
|
required: true,
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
binaryData: [
|
||||||
|
true,
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
description: 'Name of the binary property to which to<br />write the data of the received file.',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Response Content-Type',
|
displayName: 'Response Content-Type',
|
||||||
name: 'responseContentType',
|
name: 'responseContentType',
|
||||||
|
@ -258,6 +287,13 @@ export class Webhook implements INodeType {
|
||||||
displayName: 'Raw Body',
|
displayName: 'Raw Body',
|
||||||
name: 'rawBody',
|
name: 'rawBody',
|
||||||
type: 'boolean',
|
type: 'boolean',
|
||||||
|
displayOptions: {
|
||||||
|
hide: {
|
||||||
|
binaryData: [
|
||||||
|
true,
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
default: false,
|
default: false,
|
||||||
description: 'Raw body (binary)',
|
description: 'Raw body (binary)',
|
||||||
},
|
},
|
||||||
|
@ -266,10 +302,9 @@ export class Webhook implements INodeType {
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
async webhook(this: IWebhookFunctions): Promise<IWebhookResponseData> {
|
async webhook(this: IWebhookFunctions): Promise<IWebhookResponseData> {
|
||||||
const authentication = this.getNodeParameter('authentication', 0) as string;
|
const authentication = this.getNodeParameter('authentication') as string;
|
||||||
const options = this.getNodeParameter('options', 0) as IDataObject;
|
const options = this.getNodeParameter('options', {}) as IDataObject;
|
||||||
const req = this.getRequestObject();
|
const req = this.getRequestObject();
|
||||||
const resp = this.getResponseObject();
|
const resp = this.getResponseObject();
|
||||||
const headers = this.getHeaderData();
|
const headers = this.getHeaderData();
|
||||||
|
@ -347,6 +382,43 @@ export class Webhook implements INodeType {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (options.binaryData === true) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const binaryPropertyName = options.binaryPropertyName || 'data';
|
||||||
|
const data: Buffer[] = [];
|
||||||
|
|
||||||
|
req.on('data', (chunk) => {
|
||||||
|
data.push(chunk);
|
||||||
|
});
|
||||||
|
|
||||||
|
req.on('end', async () => {
|
||||||
|
const returnItem: INodeExecutionData = {
|
||||||
|
binary: {},
|
||||||
|
json: {},
|
||||||
|
};
|
||||||
|
|
||||||
|
const returnData: IDataObject[] = [{ json: {} }];
|
||||||
|
set(returnData[0], `binary[${binaryPropertyName}]`, {
|
||||||
|
data: Buffer.concat(data).toString(BINARY_ENCODING),
|
||||||
|
mimeType: req.headers['content-type'],
|
||||||
|
});
|
||||||
|
returnItem.binary![binaryPropertyName as string] = await this.helpers.prepareBinaryData(Buffer.concat(data));
|
||||||
|
|
||||||
|
return resolve({
|
||||||
|
workflowData: [
|
||||||
|
[
|
||||||
|
returnItem
|
||||||
|
]
|
||||||
|
],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
req.on('error', (err) => {
|
||||||
|
throw new Error(err.message);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const response: INodeExecutionData = {
|
const response: INodeExecutionData = {
|
||||||
json: {
|
json: {
|
||||||
body: this.getBodyData(),
|
body: this.getBodyData(),
|
||||||
|
@ -354,6 +426,7 @@ export class Webhook implements INodeType {
|
||||||
query: this.getQueryData(),
|
query: this.getQueryData(),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
if (options.rawBody) {
|
if (options.rawBody) {
|
||||||
response.binary = {
|
response.binary = {
|
||||||
data: {
|
data: {
|
||||||
|
|
Loading…
Reference in a new issue