mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
⚡ Fix rawBody
This commit is contained in:
parent
968ddbd3df
commit
9acb03435a
|
@ -4,6 +4,7 @@ import {
|
||||||
|
|
||||||
import {
|
import {
|
||||||
IDataObject,
|
IDataObject,
|
||||||
|
INodeExecutionData,
|
||||||
INodeTypeDescription,
|
INodeTypeDescription,
|
||||||
INodeType,
|
INodeType,
|
||||||
IWebhookResponseData,
|
IWebhookResponseData,
|
||||||
|
@ -208,16 +209,6 @@ export class Webhook implements INodeType {
|
||||||
displayName: 'Options',
|
displayName: 'Options',
|
||||||
name: 'options',
|
name: 'options',
|
||||||
type: 'collection',
|
type: 'collection',
|
||||||
displayOptions: {
|
|
||||||
show: {
|
|
||||||
responseData: [
|
|
||||||
'firstEntryJson',
|
|
||||||
],
|
|
||||||
responseMode: [
|
|
||||||
'lastNode',
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
placeholder: 'Add Option',
|
placeholder: 'Add Option',
|
||||||
default: {},
|
default: {},
|
||||||
options: [
|
options: [
|
||||||
|
@ -225,6 +216,16 @@ export class Webhook implements INodeType {
|
||||||
displayName: 'Response Content-Type',
|
displayName: 'Response Content-Type',
|
||||||
name: 'responseContentType',
|
name: 'responseContentType',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
'/responseData': [
|
||||||
|
'firstEntryJson',
|
||||||
|
],
|
||||||
|
'/responseMode': [
|
||||||
|
'lastNode',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
default: '',
|
default: '',
|
||||||
placeholder: 'application/xml',
|
placeholder: 'application/xml',
|
||||||
description: 'Set a custom content-type to return if another one as the "application/json" should be returned.',
|
description: 'Set a custom content-type to return if another one as the "application/json" should be returned.',
|
||||||
|
@ -233,6 +234,16 @@ export class Webhook implements INodeType {
|
||||||
displayName: 'Property Name',
|
displayName: 'Property Name',
|
||||||
name: 'responsePropertyName',
|
name: 'responsePropertyName',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
'/responseData': [
|
||||||
|
'firstEntryJson',
|
||||||
|
],
|
||||||
|
'/responseMode': [
|
||||||
|
'lastNode',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
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.',
|
||||||
},
|
},
|
||||||
|
@ -245,36 +256,13 @@ export class Webhook implements INodeType {
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
|
||||||
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 options = this.getNodeParameter('options', 0) 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();
|
||||||
|
@ -316,19 +304,24 @@ export class Webhook implements INodeType {
|
||||||
return authorizationError(resp, realm, 403);
|
return authorizationError(resp, realm, 403);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const response = {
|
|
||||||
|
// @ts-ignore
|
||||||
|
const mimeType = headers['content-type'] || 'application/json';
|
||||||
|
|
||||||
|
const response: INodeExecutionData = {
|
||||||
json: {
|
json: {
|
||||||
body: this.getBodyData(),
|
body: this.getBodyData(),
|
||||||
headers,
|
headers,
|
||||||
query: this.getQueryData(),
|
query: this.getQueryData(),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
// @ts-ignore
|
|
||||||
if (options.rawBody) {
|
if (options.rawBody) {
|
||||||
// @ts-ignore
|
|
||||||
response.binary = {
|
response.binary = {
|
||||||
// @ts-ignore
|
data: {
|
||||||
data: req.rawBody.toString('base64'),
|
// @ts-ignore
|
||||||
|
data: req.rawBody.toString('base64'),
|
||||||
|
mimeType,
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue