🔀 Merge branch 'feature/added-rawBody-webhook' of https://github.com/RicardoE105/n8n into RicardoE105-feature/added-rawBody-webhook

This commit is contained in:
Jan Oberhauser 2019-12-21 18:37:58 -06:00
commit 968ddbd3df

View file

@ -119,7 +119,6 @@ export class Webhook implements INodeType {
default: 'GET', default: 'GET',
description: 'The HTTP method to liste to.', description: 'The HTTP method to liste to.',
}, },
{ {
displayName: 'Path', displayName: 'Path',
name: 'path', name: 'path',
@ -205,7 +204,6 @@ export class Webhook implements INodeType {
}, },
description: 'Name of the binary property to return', description: 'Name of the binary property to return',
}, },
{ {
displayName: 'Options', displayName: 'Options',
name: 'options', name: 'options',
@ -238,15 +236,45 @@ export class Webhook implements INodeType {
default: 'data', default: 'data',
description: 'Name of the property to return the data of instead of the whole JSON.', description: 'Name of the property to return the data of instead of the whole JSON.',
}, },
{
displayName: 'Raw Body',
name: 'rawBody',
type: 'boolean',
default: false,
description: 'Raw body (binary)',
},
],
},
{
displayName: 'Options',
name: 'options',
type: 'collection',
displayOptions: {
show: {
responseMode: [
'onReceived',
],
},
},
placeholder: 'Add Option',
default: {},
options: [
{
displayName: 'Raw Body',
name: 'rawBody',
type: 'boolean',
default: false,
description: 'Raw body (binary)',
},
], ],
}, },
], ],
}; };
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', 0) as string;
const options = this.getNodeParameter('options', 0) as string;
const req = this.getRequestObject(); const req = this.getRequestObject();
const resp = this.getResponseObject(); const resp = this.getResponseObject();
const headers = this.getHeaderData(); const headers = this.getHeaderData();
@ -288,20 +316,27 @@ export class Webhook implements INodeType {
return authorizationError(resp, realm, 403); return authorizationError(resp, realm, 403);
} }
} }
const response = {
const returnData: IDataObject[] = []; json: {
returnData.push(
{
body: this.getBodyData(), body: this.getBodyData(),
headers, headers,
query: this.getQueryData(), query: this.getQueryData(),
} },
); };
// @ts-ignore
if (options.rawBody) {
// @ts-ignore
response.binary = {
// @ts-ignore
data: req.rawBody.toString('base64'),
};
}
return { return {
workflowData: [ workflowData: [
this.helpers.returnJsonArray(returnData) [
response,
],
], ],
}; };
} }