refactor: Unify binary-data assertion across all nodes (no-changelog) (#5624)

This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™
2023-03-06 17:33:32 +01:00
committed by GitHub
parent 01a2160b3b
commit 5eb0d52459
69 changed files with 411 additions and 1573 deletions

View File

@@ -20,7 +20,7 @@ interface OptionData {
displayName: string;
}
interface OptionDataParamters {
interface OptionDataParameters {
[key: string]: OptionData;
}
@@ -637,7 +637,7 @@ export class HttpRequestV1 implements INodeType {
queryParametersUi: 'qs',
};
const jsonParameters: OptionDataParamters = {
const jsonParameters: OptionDataParameters = {
bodyParametersJson: {
name: 'body',
displayName: 'Body Parameters',
@@ -648,7 +648,7 @@ export class HttpRequestV1 implements INodeType {
},
queryParametersJson: {
name: 'qs',
displayName: 'Query Paramters',
displayName: 'Query Parameters',
},
};
let returnItems: INodeExecutionData[] = [];
@@ -730,7 +730,7 @@ export class HttpRequestV1 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(),
@@ -739,24 +739,9 @@ export class HttpRequestV1 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,
@@ -787,14 +772,7 @@ export class HttpRequestV1 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,
@@ -803,8 +781,8 @@ export class HttpRequestV1 implements INodeType {
requestOptions.body[propertyName] = {
value: binaryDataBuffer,
options: {
filename: binaryProperty.fileName,
contentType: binaryProperty.mimeType,
filename: binaryData.fileName,
contentType: binaryData.mimeType,
},
};
}
@@ -814,7 +792,7 @@ export class HttpRequestV1 implements INodeType {
}
if (tempValue === '') {
// Paramter is empty so skip it
// Parameter is empty so skip it
continue;
}
@@ -842,7 +820,7 @@ export class HttpRequestV1 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;

View File

@@ -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;

View File

@@ -1,8 +1,7 @@
import type { IExecuteFunctions } from 'n8n-core';
import type {
IBinaryKeyData,
IDataObject,
IExecuteFunctions,
INodeExecutionData,
INodeType,
INodeTypeBaseDescription,
@@ -1067,22 +1066,8 @@ export class HttpRequestV3 implements INodeType {
) => {
const accumulator = await acc;
if (cur.parameterType === 'formBinaryData') {
const binaryDataOnInput = items[itemIndex]?.binary;
if (!cur.inputDataFieldName) return accumulator;
if (!binaryDataOnInput?.[cur.inputDataFieldName]) {
throw new NodeOperationError(
this.getNode(),
`Input Data Field Name '${cur.inputDataFieldName}' could not be found in input`,
{
runIndex: itemIndex,
},
);
}
if (!cur.inputDataFieldName) return accumulator;
const binaryData = binaryDataOnInput[cur.inputDataFieldName];
const binaryData = this.helpers.assertBinaryData(itemIndex, cur.inputDataFieldName);
const buffer = await this.helpers.getBinaryDataBuffer(itemIndex, cur.inputDataFieldName);
accumulator[cur.name] = {
@@ -1143,6 +1128,7 @@ export class HttpRequestV3 implements INodeType {
'inputDataFieldName',
itemIndex,
) as string;
this.helpers.assertBinaryData(itemIndex, inputDataFieldName);
requestOptions.body = await this.helpers.getBinaryDataBuffer(
itemIndex,
inputDataFieldName,