mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 01:56:46 +00:00
refactor: Unify binary-data assertion across all nodes (no-changelog) (#5624)
This commit is contained in:
committed by
GitHub
parent
01a2160b3b
commit
5eb0d52459
@@ -1,6 +1,6 @@
|
||||
import type { IExecuteFunctions } from 'n8n-core';
|
||||
import type {
|
||||
IDataObject,
|
||||
IExecuteFunctions,
|
||||
INodeExecutionData,
|
||||
INodeType,
|
||||
INodeTypeBaseDescription,
|
||||
@@ -22,7 +22,7 @@ interface OptionData {
|
||||
displayName: string;
|
||||
}
|
||||
|
||||
interface OptionDataParamters {
|
||||
interface OptionDataParameters {
|
||||
[key: string]: OptionData;
|
||||
}
|
||||
|
||||
@@ -674,7 +674,7 @@ export class HttpRequestV2 implements INodeType {
|
||||
queryParametersUi: 'qs',
|
||||
};
|
||||
|
||||
const jsonParameters: OptionDataParamters = {
|
||||
const jsonParameters: OptionDataParameters = {
|
||||
bodyParametersJson: {
|
||||
name: 'body',
|
||||
displayName: 'Body Parameters',
|
||||
@@ -685,7 +685,7 @@ export class HttpRequestV2 implements INodeType {
|
||||
},
|
||||
queryParametersJson: {
|
||||
name: 'qs',
|
||||
displayName: 'Query Paramters',
|
||||
displayName: 'Query Parameters',
|
||||
},
|
||||
};
|
||||
let returnItems: INodeExecutionData[] = [];
|
||||
@@ -767,7 +767,7 @@ export class HttpRequestV2 implements INodeType {
|
||||
const contentTypesAllowed = ['raw', 'multipart-form-data'];
|
||||
|
||||
if (!contentTypesAllowed.includes(options.bodyContentType as string)) {
|
||||
// As n8n-workflow.NodeHelpers.getParamterResolveOrder can not be changed
|
||||
// As n8n-workflow.NodeHelpers.getParameterResolveOrder can not be changed
|
||||
// easily to handle parameters in dot.notation simply error for now.
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
@@ -776,24 +776,9 @@ export class HttpRequestV2 implements INodeType {
|
||||
);
|
||||
}
|
||||
|
||||
const item = items[itemIndex];
|
||||
|
||||
if (item.binary === undefined) {
|
||||
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!', {
|
||||
itemIndex,
|
||||
});
|
||||
}
|
||||
|
||||
if (options.bodyContentType === 'raw') {
|
||||
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', itemIndex);
|
||||
if (item.binary[binaryPropertyName] === undefined) {
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
`Item has no binary property called "${binaryPropertyName}"`,
|
||||
{ itemIndex },
|
||||
);
|
||||
}
|
||||
|
||||
this.helpers.assertBinaryData(itemIndex, binaryPropertyName);
|
||||
const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(
|
||||
itemIndex,
|
||||
binaryPropertyName,
|
||||
@@ -824,14 +809,7 @@ export class HttpRequestV2 implements INodeType {
|
||||
);
|
||||
}
|
||||
|
||||
if (item.binary[binaryPropertyName] === undefined) {
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
`Item has no binary property called "${binaryPropertyName}"`,
|
||||
);
|
||||
}
|
||||
|
||||
const binaryProperty = item.binary[binaryPropertyName];
|
||||
const binaryData = this.helpers.assertBinaryData(itemIndex, binaryPropertyName);
|
||||
const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(
|
||||
itemIndex,
|
||||
binaryPropertyName,
|
||||
@@ -840,8 +818,8 @@ export class HttpRequestV2 implements INodeType {
|
||||
requestOptions.body[propertyName] = {
|
||||
value: binaryDataBuffer,
|
||||
options: {
|
||||
filename: binaryProperty.fileName,
|
||||
contentType: binaryProperty.mimeType,
|
||||
filename: binaryData.fileName,
|
||||
contentType: binaryData.mimeType,
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -851,7 +829,7 @@ export class HttpRequestV2 implements INodeType {
|
||||
}
|
||||
|
||||
if (tempValue === '') {
|
||||
// Paramter is empty so skip it
|
||||
// Parameter is empty so skip it
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -879,7 +857,7 @@ export class HttpRequestV2 implements INodeType {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Paramters are defined in UI
|
||||
// Parameters are defined in UI
|
||||
let optionName: string;
|
||||
for (const parameterName of Object.keys(uiParameters)) {
|
||||
setUiParameter = this.getNodeParameter(parameterName, itemIndex, {}) as IDataObject;
|
||||
|
||||
Reference in New Issue
Block a user