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

@@ -844,6 +844,30 @@ export function getBinaryStream(binaryDataId: string, chunkSize?: number): Reada
return BinaryDataManager.getInstance().getBinaryStream(binaryDataId, chunkSize); return BinaryDataManager.getInstance().getBinaryStream(binaryDataId, chunkSize);
} }
export function assertBinaryData(
inputData: ITaskDataConnections,
node: INode,
itemIndex: number,
propertyName: string,
inputIndex: number,
): IBinaryData {
const binaryKeyData = inputData.main[inputIndex]![itemIndex]!.binary;
if (binaryKeyData === undefined) {
throw new NodeOperationError(node, 'No binary data exists on item!', {
itemIndex,
});
}
const binaryPropertyData = binaryKeyData[propertyName];
if (binaryPropertyData === undefined) {
throw new NodeOperationError(node, `Item has no binary property called "${propertyName}"`, {
itemIndex,
});
}
return binaryPropertyData;
}
/** /**
* Returns binary data buffer for given item index and property name. * Returns binary data buffer for given item index and property name.
*/ */
@@ -2327,8 +2351,11 @@ export function getExecuteFunctions(
...getRequestHelperFunctions(workflow, node, additionalData), ...getRequestHelperFunctions(workflow, node, additionalData),
...getFileSystemHelperFunctions(node), ...getFileSystemHelperFunctions(node),
...getBinaryHelperFunctions(additionalData), ...getBinaryHelperFunctions(additionalData),
getBinaryDataBuffer: async (itemIndex, propertyName, inputIndex = 0) => assertBinaryData: (itemIndex, propertyName) =>
getBinaryDataBuffer(inputData, itemIndex, propertyName, inputIndex), assertBinaryData(inputData, node, itemIndex, propertyName, 0),
getBinaryDataBuffer: async (itemIndex, propertyName) =>
getBinaryDataBuffer(inputData, itemIndex, propertyName, 0),
returnJsonArray, returnJsonArray,
normalizeItems, normalizeItems,
constructExecutionMetaData, constructExecutionMetaData,
@@ -2465,6 +2492,8 @@ export function getExecuteSingleFunctions(
...getRequestHelperFunctions(workflow, node, additionalData), ...getRequestHelperFunctions(workflow, node, additionalData),
...getBinaryHelperFunctions(additionalData), ...getBinaryHelperFunctions(additionalData),
assertBinaryData: (propertyName, inputIndex = 0) =>
assertBinaryData(inputData, node, itemIndex, propertyName, inputIndex),
getBinaryDataBuffer: async (propertyName, inputIndex = 0) => getBinaryDataBuffer: async (propertyName, inputIndex = 0) =>
getBinaryDataBuffer(inputData, itemIndex, propertyName, inputIndex), getBinaryDataBuffer(inputData, itemIndex, propertyName, inputIndex),
}, },

View File

@@ -1,13 +1,10 @@
import type { IExecuteFunctions } from 'n8n-core';
import type { import type {
IBinaryKeyData,
IDataObject, IDataObject,
IExecuteFunctions,
INodeExecutionData, INodeExecutionData,
INodeType, INodeType,
INodeTypeDescription, INodeTypeDescription,
} from 'n8n-workflow'; } from 'n8n-workflow';
import { NodeOperationError } from 'n8n-workflow';
import { awsApiRequestREST, keysTPascalCase } from './GenericFunctions'; import { awsApiRequestREST, keysTPascalCase } from './GenericFunctions';
@@ -104,7 +101,7 @@ export class AwsRekognition implements INodeType {
resource: ['image'], resource: ['image'],
}, },
}, },
description: 'Whether the image to analize should be taken from binary field', description: 'Whether the image to analyze should be taken from binary field',
}, },
{ {
displayName: 'Binary Property', displayName: 'Binary Property',
@@ -364,9 +361,9 @@ export class AwsRekognition implements INodeType {
action = 'RekognitionService.DetectFaces'; action = 'RekognitionService.DetectFaces';
// TODO: Add a later point make it possible to activate via option. // TODO: Add a later point make it possible to activate via option.
// If activated add an index to each of the found faces/tages/... // If activated add an index to each of the found faces/tags/...
// to not loose the reference to the image it got found on if // to not loose the reference to the image it got found on if
// multilpe ones got supplied. // multiple ones got supplied.
// property = 'FaceDetails'; // property = 'FaceDetails';
if (additionalFields.attributes) { if (additionalFields.attributes) {
@@ -412,27 +409,10 @@ export class AwsRekognition implements INodeType {
body.Filters.WordFilter = keysTPascalCase(wordFilter); body.Filters.WordFilter = keysTPascalCase(wordFilter);
} }
const binaryData = this.getNodeParameter('binaryData', 0); const isBinaryData = this.getNodeParameter('binaryData', i);
if (isBinaryData) {
if (binaryData) { const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i);
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', 0); const binaryPropertyData = this.helpers.assertBinaryData(i, binaryPropertyName);
if (items[i].binary === undefined) {
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!', {
itemIndex: i,
});
}
if ((items[i].binary as IBinaryKeyData)[binaryPropertyName] === undefined) {
throw new NodeOperationError(
this.getNode(),
`Item has no binary property called "${binaryPropertyName}"`,
{ itemIndex: i },
);
}
const binaryPropertyData = (items[i].binary as IBinaryKeyData)[binaryPropertyName];
Object.assign(body, { Object.assign(body, {
Image: { Image: {
Bytes: binaryPropertyData.data, Bytes: binaryPropertyData.data,
@@ -440,7 +420,6 @@ export class AwsRekognition implements INodeType {
}); });
} else { } else {
const bucket = this.getNodeParameter('bucket', i) as string; const bucket = this.getNodeParameter('bucket', i) as string;
const name = this.getNodeParameter('name', i) as string; const name = this.getNodeParameter('name', i) as string;
Object.assign(body, { Object.assign(body, {

View File

@@ -4,11 +4,9 @@ import { createHash } from 'crypto';
import { Builder } from 'xml2js'; import { Builder } from 'xml2js';
import type { IExecuteFunctions } from 'n8n-core';
import type { import type {
IBinaryKeyData,
IDataObject, IDataObject,
IExecuteFunctions,
INodeExecutionData, INodeExecutionData,
INodeType, INodeType,
INodeTypeDescription, INodeTypeDescription,
@@ -221,8 +219,8 @@ export class AwsS3 implements INodeType {
qs['encoding-type'] = additionalFields.encodingType as string; qs['encoding-type'] = additionalFields.encodingType as string;
} }
if (additionalFields.delmiter) { if (additionalFields.delimiter) {
qs.delimiter = additionalFields.delmiter as string; qs.delimiter = additionalFields.delimiter as string;
} }
if (additionalFields.fetchOwner) { if (additionalFields.fetchOwner) {
@@ -593,7 +591,7 @@ export class AwsS3 implements INodeType {
if (fileKey.substring(fileKey.length - 1) === '/') { if (fileKey.substring(fileKey.length - 1) === '/') {
throw new NodeOperationError( throw new NodeOperationError(
this.getNode(), this.getNode(),
'Downloding a whole directory is not yet supported, please provide a file key', 'Downloading a whole directory is not yet supported, please provide a file key',
); );
} }
@@ -836,23 +834,8 @@ export class AwsS3 implements INodeType {
const region = responseData.LocationConstraint._; const region = responseData.LocationConstraint._;
if (isBinaryData) { if (isBinaryData) {
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', 0); const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i);
const binaryPropertyData = this.helpers.assertBinaryData(i, binaryPropertyName);
if (items[i].binary === undefined) {
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!', {
itemIndex: i,
});
}
if ((items[i].binary as IBinaryKeyData)[binaryPropertyName] === undefined) {
throw new NodeOperationError(
this.getNode(),
`Item has no binary property called "${binaryPropertyName}"`,
{ itemIndex: i },
);
}
const binaryData = (items[i].binary as IBinaryKeyData)[binaryPropertyName];
const binaryDataBuffer = await this.helpers.getBinaryDataBuffer( const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(
i, i,
binaryPropertyName, binaryPropertyName,
@@ -860,7 +843,7 @@ export class AwsS3 implements INodeType {
body = binaryDataBuffer; body = binaryDataBuffer;
headers['Content-Type'] = binaryData.mimeType; headers['Content-Type'] = binaryPropertyData.mimeType;
headers['Content-MD5'] = createHash('md5').update(body).digest('base64'); headers['Content-MD5'] = createHash('md5').update(body).digest('base64');
@@ -868,7 +851,7 @@ export class AwsS3 implements INodeType {
this, this,
`${bucketName}.s3`, `${bucketName}.s3`,
'PUT', 'PUT',
`${path}${fileName || binaryData.fileName}`, `${path}${fileName || binaryPropertyData.fileName}`,
body, body,
qs, qs,
headers, headers,

View File

@@ -1,7 +1,6 @@
import type { IExecuteFunctions } from 'n8n-core';
import type { import type {
IDataObject, IDataObject,
IExecuteFunctions,
ILoadOptionsFunctions, ILoadOptionsFunctions,
INodeExecutionData, INodeExecutionData,
INodeParameters, INodeParameters,
@@ -10,7 +9,7 @@ import type {
INodeTypeDescription, INodeTypeDescription,
JsonObject, JsonObject,
} from 'n8n-workflow'; } from 'n8n-workflow';
import { NodeApiError, NodeOperationError } from 'n8n-workflow'; import { NodeApiError } from 'n8n-workflow';
import { URL } from 'url'; import { URL } from 'url';
@@ -341,29 +340,12 @@ export class AwsSqs implements INodeType {
this.getNodeParameter('options.messageAttributes.binary', i, []) as INodeParameters[] this.getNodeParameter('options.messageAttributes.binary', i, []) as INodeParameters[]
).forEach((attribute) => { ).forEach((attribute) => {
attributeCount++; attributeCount++;
const dataPropertyName = attribute.dataPropertyName as string; const dataPropertyName = attribute.dataPropertyName as string;
const item = items[i]; const binaryData = this.helpers.assertBinaryData(i, dataPropertyName);
if (item.binary === undefined) {
throw new NodeOperationError(
this.getNode(),
'No binary data set. So message attribute cannot be added!',
{ itemIndex: i },
);
}
if (item.binary[dataPropertyName] === undefined) {
throw new NodeOperationError(
this.getNode(),
`The binary property "${dataPropertyName}" does not exist. So message attribute cannot be added!`,
{ itemIndex: i },
);
}
const binaryData = item.binary[dataPropertyName].data;
params.push(`MessageAttribute.${attributeCount}.Name=${attribute.name}`); params.push(`MessageAttribute.${attributeCount}.Name=${attribute.name}`);
params.push(`MessageAttribute.${attributeCount}.Value.BinaryValue=${binaryData}`); params.push(`MessageAttribute.${attributeCount}.Value.BinaryValue=${binaryData.data}`);
params.push(`MessageAttribute.${attributeCount}.Value.DataType=Binary`); params.push(`MessageAttribute.${attributeCount}.Value.DataType=Binary`);
}); });

View File

@@ -1,17 +1,14 @@
import type { IExecuteFunctions } from 'n8n-core';
import type { import type {
IBinaryKeyData,
ICredentialDataDecryptedObject, ICredentialDataDecryptedObject,
ICredentialsDecrypted, ICredentialsDecrypted,
ICredentialTestFunctions, ICredentialTestFunctions,
IDataObject, IDataObject,
IExecuteFunctions,
INodeCredentialTestResult, INodeCredentialTestResult,
INodeExecutionData, INodeExecutionData,
INodeType, INodeType,
INodeTypeDescription, INodeTypeDescription,
} from 'n8n-workflow'; } from 'n8n-workflow';
import { NodeOperationError } from 'n8n-workflow';
import type { IExpenseDocument } from './GenericFunctions'; import type { IExpenseDocument } from './GenericFunctions';
import { awsApiRequestREST, simplify, validateCredentials } from './GenericFunctions'; import { awsApiRequestREST, simplify, validateCredentials } from './GenericFunctions';
@@ -116,28 +113,13 @@ export class AwsTextract implements INodeType {
try { try {
//https://docs.aws.amazon.com/textract/latest/dg/API_AnalyzeExpense.html //https://docs.aws.amazon.com/textract/latest/dg/API_AnalyzeExpense.html
if (operation === 'analyzeExpense') { if (operation === 'analyzeExpense') {
const binaryProperty = this.getNodeParameter('binaryPropertyName', i);
const simple = this.getNodeParameter('simple', i) as boolean; const simple = this.getNodeParameter('simple', i) as boolean;
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i);
if (items[i].binary === undefined) { const binaryData = this.helpers.assertBinaryData(i, binaryPropertyName);
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!', {
itemIndex: i,
});
}
if ((items[i].binary as IBinaryKeyData)[binaryProperty] === undefined) {
throw new NodeOperationError(
this.getNode(),
`Item has no binary property called "${binaryProperty}"`,
{ itemIndex: i },
);
}
const binaryPropertyData = (items[i].binary as IBinaryKeyData)[binaryProperty];
const body: IDataObject = { const body: IDataObject = {
Document: { Document: {
Bytes: binaryPropertyData.data, Bytes: binaryData.data,
}, },
}; };

View File

@@ -1,7 +1,4 @@
import type { IExecuteFunctions } from 'n8n-core'; import type { IDataObject, IExecuteFunctions } from 'n8n-workflow';
import type { IBinaryKeyData, IDataObject } from 'n8n-workflow';
import { NodeOperationError } from 'n8n-workflow';
import { apiRequest } from '../../../transport'; import { apiRequest } from '../../../transport';
@@ -9,34 +6,12 @@ export async function upload(this: IExecuteFunctions, index: number) {
let body: IDataObject = {}; let body: IDataObject = {};
const requestMethod = 'POST'; const requestMethod = 'POST';
const items = this.getInputData(); const id: string = this.getNodeParameter('employeeId', index) as string;
const category = this.getNodeParameter('categoryId', index) as string; const category = this.getNodeParameter('categoryId', index) as string;
const options = this.getNodeParameter('options', index); const options = this.getNodeParameter('options', index);
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', index);
if (items[index].binary === undefined) { const { fileName, mimeType } = this.helpers.assertBinaryData(index, binaryPropertyName);
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!', { const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(index, binaryPropertyName);
itemIndex: index,
});
}
const propertyNameUpload = this.getNodeParameter('binaryPropertyName', index);
if (items[index]!.binary![propertyNameUpload] === undefined) {
throw new NodeOperationError(
this.getNode(),
`Item has no binary property called "${propertyNameUpload}"`,
{ itemIndex: index },
);
}
const item = items[index].binary as IBinaryKeyData;
const binaryData = item[propertyNameUpload];
const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(index, propertyNameUpload);
const id: string = this.getNodeParameter('employeeId', index) as string;
body = { body = {
json: false, json: false,
@@ -44,11 +19,11 @@ export async function upload(this: IExecuteFunctions, index: number) {
file: { file: {
value: binaryDataBuffer, value: binaryDataBuffer,
options: { options: {
filename: binaryData.fileName, filename: fileName,
contentType: binaryData.mimeType, contentType: mimeType,
}, },
}, },
fileName: binaryData.fileName, fileName,
category, category,
}, },
resolveWithFullResponse: true, resolveWithFullResponse: true,

View File

@@ -1,7 +1,4 @@
import type { IExecuteFunctions } from 'n8n-core'; import type { IDataObject, IExecuteFunctions } from 'n8n-workflow';
import type { IBinaryKeyData, IDataObject } from 'n8n-workflow';
import { NodeOperationError } from 'n8n-workflow';
import { apiRequest } from '../../../transport'; import { apiRequest } from '../../../transport';
@@ -9,32 +6,12 @@ export async function upload(this: IExecuteFunctions, index: number) {
let body: IDataObject = {}; let body: IDataObject = {};
const requestMethod = 'POST'; const requestMethod = 'POST';
const items = this.getInputData();
const category = this.getNodeParameter('categoryId', index) as string; const category = this.getNodeParameter('categoryId', index) as string;
const share = this.getNodeParameter('options.share', index, true) as boolean; const share = this.getNodeParameter('options.share', index, true) as boolean;
if (items[index].binary === undefined) { const binaryPropertyName = this.getNodeParameter('binaryPropertyName', index);
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!', { const { fileName, mimeType } = this.helpers.assertBinaryData(index, binaryPropertyName);
itemIndex: index, const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(index, binaryPropertyName);
});
}
const propertyNameUpload = this.getNodeParameter('binaryPropertyName', index);
if (items[index]!.binary![propertyNameUpload] === undefined) {
throw new NodeOperationError(
this.getNode(),
`Item has no binary property called "${propertyNameUpload}"`,
{ itemIndex: index },
);
}
const item = items[index].binary as IBinaryKeyData;
const binaryData = item[propertyNameUpload];
const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(index, propertyNameUpload);
body = { body = {
json: false, json: false,
@@ -42,11 +19,11 @@ export async function upload(this: IExecuteFunctions, index: number) {
file: { file: {
value: binaryDataBuffer, value: binaryDataBuffer,
options: { options: {
filename: binaryData.fileName, filename: fileName,
contentType: binaryData.mimeType, contentType: mimeType,
}, },
}, },
fileName: binaryData.fileName, fileName,
category, category,
}, },
resolveWithFullResponse: true, resolveWithFullResponse: true,

View File

@@ -1,8 +1,6 @@
import type { IExecuteFunctions } from 'n8n-core';
import type { import type {
IBinaryKeyData,
IDataObject, IDataObject,
IExecuteFunctions,
INodeExecutionData, INodeExecutionData,
INodeType, INodeType,
INodeTypeDescription, INodeTypeDescription,
@@ -277,23 +275,8 @@ export class Box implements INodeType {
} }
if (isBinaryData) { if (isBinaryData) {
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', 0); const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i);
const binaryData = this.helpers.assertBinaryData(i, binaryPropertyName);
if (items[i].binary === undefined) {
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!', {
itemIndex: i,
});
}
//@ts-ignore
if (items[i].binary[binaryPropertyName] === undefined) {
throw new NodeOperationError(
this.getNode(),
`Item has no binary property called "${binaryPropertyName}"`,
{ itemIndex: i },
);
}
const binaryData = (items[i].binary as IBinaryKeyData)[binaryPropertyName];
const binaryDataBuffer = await this.helpers.getBinaryDataBuffer( const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(
i, i,
binaryPropertyName, binaryPropertyName,

View File

@@ -1,16 +1,14 @@
import type { IExecuteFunctions } from 'n8n-core';
import type { import type {
IDataObject, IDataObject,
IExecuteFunctions,
ILoadOptionsFunctions, ILoadOptionsFunctions,
INodeExecutionData, INodeExecutionData,
INodePropertyOptions, INodePropertyOptions,
INodeType, INodeType,
INodeTypeDescription, INodeTypeDescription,
} from 'n8n-workflow'; } from 'n8n-workflow';
import { NodeOperationError } from 'n8n-workflow';
import { getAttachemnts, webexApiRequest, webexApiRequestAllItems } from './GenericFunctions'; import { getAttachments, webexApiRequest, webexApiRequestAllItems } from './GenericFunctions';
import { import {
meetingFields, meetingFields,
@@ -156,7 +154,7 @@ export class CiscoWebex implements INodeType {
body.text = this.getNodeParameter('text', i); body.text = this.getNodeParameter('text', i);
body.attachments = getAttachemnts( body.attachments = getAttachments(
this.getNodeParameter( this.getNodeParameter(
'additionalFields.attachmentsUi.attachmentValues', 'additionalFields.attachmentsUi.attachmentValues',
i, i,
@@ -168,15 +166,8 @@ export class CiscoWebex implements INodeType {
const isBinaryData = file.fileLocation === 'binaryData' ? true : false; const isBinaryData = file.fileLocation === 'binaryData' ? true : false;
if (isBinaryData) { if (isBinaryData) {
if (!items[i].binary) {
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!', {
itemIndex: i,
});
}
const binaryPropertyName = file.binaryPropertyName as string; const binaryPropertyName = file.binaryPropertyName as string;
const binaryData = this.helpers.assertBinaryData(i, binaryPropertyName);
const binaryData = items[i].binary![binaryPropertyName];
const binaryDataBuffer = await this.helpers.getBinaryDataBuffer( const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(
i, i,
binaryPropertyName, binaryPropertyName,

View File

@@ -135,9 +135,9 @@ function removeEmptyProperties(rest: { [key: string]: any }) {
.reduce((a, k) => ({ ...a, [k]: rest[k] }), {}); .reduce((a, k) => ({ ...a, [k]: rest[k] }), {});
} }
export function getAttachemnts(attachements: IDataObject[]) { export function getAttachments(attachments: IDataObject[]) {
const _attachments: IDataObject[] = []; const _attachments: IDataObject[] = [];
for (const attachment of attachements) { for (const attachment of attachments) {
const body: IDataObject[] = []; const body: IDataObject[] = [];
const actions: IDataObject[] = []; const actions: IDataObject[] = [];
for (const element of ((attachment?.elementsUi as IDataObject) for (const element of ((attachment?.elementsUi as IDataObject)

View File

@@ -1,13 +1,11 @@
import type { IExecuteFunctions } from 'n8n-core';
import type { import type {
IDataObject, IDataObject,
IExecuteFunctions,
INodeExecutionData, INodeExecutionData,
INodeType, INodeType,
INodeTypeDescription, INodeTypeDescription,
JsonObject, JsonObject,
} from 'n8n-workflow'; } from 'n8n-workflow';
import { NodeOperationError } from 'n8n-workflow';
import { citrixADCApiRequest } from './GenericFunctions'; import { citrixADCApiRequest } from './GenericFunctions';
@@ -74,24 +72,12 @@ export class CitrixAdc implements INodeType {
const options = this.getNodeParameter('options', i); const options = this.getNodeParameter('options', i);
const endpoint = '/config/systemfile'; const endpoint = '/config/systemfile';
const item = items[i]; const binaryData = this.helpers.assertBinaryData(i, binaryProperty);
if (item.binary === undefined) {
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!');
}
if (item.binary[binaryProperty] === undefined) {
throw new NodeOperationError(
this.getNode(),
`The binary data property "${binaryProperty}" does not exists on item!`,
);
}
const buffer = await this.helpers.getBinaryDataBuffer(i, binaryProperty); const buffer = await this.helpers.getBinaryDataBuffer(i, binaryProperty);
const body = { const body = {
systemfile: { systemfile: {
filename: item.binary[binaryProperty].fileName, filename: binaryData.fileName,
filecontent: Buffer.from(buffer).toString('base64'), filecontent: Buffer.from(buffer).toString('base64'),
filelocation: fileLocation, filelocation: fileLocation,
fileencoding: 'BASE64', fileencoding: 'BASE64',

View File

@@ -1,12 +1,10 @@
import type { IExecuteFunctions } from 'n8n-core';
import type { import type {
IBinaryKeyData, IBinaryKeyData,
IExecuteFunctions,
INodeExecutionData, INodeExecutionData,
INodeType, INodeType,
INodeTypeDescription, INodeTypeDescription,
} from 'n8n-workflow'; } from 'n8n-workflow';
import { NodeOperationError } from 'n8n-workflow';
import * as fflate from 'fflate'; import * as fflate from 'fflate';
@@ -158,7 +156,7 @@ export class Compression implements INodeType {
outputFormat: ['gzip'], outputFormat: ['gzip'],
}, },
}, },
description: 'Prefix use for all gzip compresed files', description: 'Prefix use for all gzip compressed files',
}, },
{ {
displayName: 'Output Prefix', displayName: 'Output Prefix',
@@ -196,28 +194,14 @@ export class Compression implements INodeType {
let zipIndex = 0; let zipIndex = 0;
for (const [index, binaryPropertyName] of binaryPropertyNames.entries()) { for (const [index, binaryPropertyName] of binaryPropertyNames.entries()) {
if (items[i].binary === undefined) { const binaryData = this.helpers.assertBinaryData(i, binaryPropertyName);
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!', {
itemIndex: i,
});
}
//@ts-ignore
if (items[i].binary[binaryPropertyName] === undefined) {
throw new NodeOperationError(
this.getNode(),
`Item has no binary property called "${binaryPropertyName}"`,
{ itemIndex: i },
);
}
const binaryData = (items[i].binary as IBinaryKeyData)[binaryPropertyName];
const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName); const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName);
if (binaryData.fileExtension === 'zip') { if (binaryData.fileExtension === 'zip') {
const files = await unzip(binaryDataBuffer); const files = await unzip(binaryDataBuffer);
for (const key of Object.keys(files)) { for (const key of Object.keys(files)) {
// when files are compresed using MACOSX for some reason they are duplicated under __MACOSX // when files are compressed using MACOSX for some reason they are duplicated under __MACOSX
if (key.includes('__MACOSX')) { if (key.includes('__MACOSX')) {
continue; continue;
} }
@@ -267,21 +251,7 @@ export class Compression implements INodeType {
const binaryObject: IBinaryKeyData = {}; const binaryObject: IBinaryKeyData = {};
for (const [index, binaryPropertyName] of binaryPropertyNames.entries()) { for (const [index, binaryPropertyName] of binaryPropertyNames.entries()) {
if (items[i].binary === undefined) { const binaryData = this.helpers.assertBinaryData(i, binaryPropertyName);
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!', {
itemIndex: i,
});
}
//@ts-ignore
if (items[i].binary[binaryPropertyName] === undefined) {
throw new NodeOperationError(
this.getNode(),
`Item has no binary property called "${binaryPropertyName}"`,
{ itemIndex: i },
);
}
const binaryData = (items[i].binary as IBinaryKeyData)[binaryPropertyName];
const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName); const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName);
if (outputFormat === 'zip') { if (outputFormat === 'zip') {

View File

@@ -1,18 +1,16 @@
import type { IExecuteFunctions } from 'n8n-core';
import { cortexApiRequest, getEntityLabel, prepareParameters, splitTags } from './GenericFunctions'; import { cortexApiRequest, getEntityLabel, prepareParameters, splitTags } from './GenericFunctions';
import { analyzerFields, analyzersOperations } from './AnalyzerDescriptions'; import { analyzerFields, analyzersOperations } from './AnalyzerDescriptions';
import type { import type {
IDataObject, IDataObject,
IExecuteFunctions,
ILoadOptionsFunctions, ILoadOptionsFunctions,
INodeExecutionData, INodeExecutionData,
INodePropertyOptions, INodePropertyOptions,
INodeType, INodeType,
INodeTypeDescription, INodeTypeDescription,
} from 'n8n-workflow'; } from 'n8n-workflow';
import { NodeOperationError } from 'n8n-workflow';
import { responderFields, respondersOperations } from './ResponderDescription'; import { responderFields, respondersOperations } from './ResponderDescription';
@@ -193,24 +191,8 @@ export class Cortex implements INodeType {
} }
if (observableType === 'file') { if (observableType === 'file') {
const item = items[i];
if (item.binary === undefined) {
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!', {
itemIndex: i,
});
}
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i); const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i);
const binaryData = this.helpers.assertBinaryData(i, binaryPropertyName);
if (item.binary[binaryPropertyName] === undefined) {
throw new NodeOperationError(
this.getNode(),
`Item has no binary property called "${binaryPropertyName}"`,
{ itemIndex: i },
);
}
const fileBufferData = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName); const fileBufferData = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName);
const options = { const options = {
@@ -218,8 +200,8 @@ export class Cortex implements INodeType {
data: { data: {
value: fileBufferData, value: fileBufferData,
options: { options: {
contentType: item.binary[binaryPropertyName].mimeType, contentType: binaryData.mimeType,
filename: item.binary[binaryPropertyName].fileName, filename: binaryData.fileName,
}, },
}, },
_json: JSON.stringify({ _json: JSON.stringify({
@@ -337,27 +319,8 @@ export class Cortex implements INodeType {
element.data = artifactvalue.data as string; element.data = artifactvalue.data as string;
if (artifactvalue.dataType === 'file') { if (artifactvalue.dataType === 'file') {
const item = items[i];
if (item.binary === undefined) {
throw new NodeOperationError(
this.getNode(),
'No binary data exists on item!',
{ itemIndex: i },
);
}
const binaryPropertyName = artifactvalue.binaryProperty as string; const binaryPropertyName = artifactvalue.binaryProperty as string;
const binaryData = this.helpers.assertBinaryData(i, binaryPropertyName);
if (item.binary[binaryPropertyName] === undefined) {
throw new NodeOperationError(
this.getNode(),
`Item has no binary property called "${binaryPropertyName}"`,
{ itemIndex: i },
);
}
const binaryData = item.binary[binaryPropertyName];
element.data = `${binaryData.fileName};${binaryData.mimeType};${binaryData.data}`; element.data = `${binaryData.fileName};${binaryData.mimeType};${binaryData.data}`;
} }
@@ -373,24 +336,9 @@ export class Cortex implements INodeType {
// deal with file observable // deal with file observable
if ((body.data as IDataObject).dataType === 'file') { if ((body.data as IDataObject).dataType === 'file') {
const item = items[i];
if (item.binary === undefined) {
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!', {
itemIndex: i,
});
}
const binaryPropertyName = (body.data as IDataObject) const binaryPropertyName = (body.data as IDataObject)
.binaryPropertyName as string; .binaryPropertyName as string;
if (item.binary[binaryPropertyName] === undefined) { const binaryData = this.helpers.assertBinaryData(i, binaryPropertyName);
throw new NodeOperationError(
this.getNode(),
`Item has no binary property called "${binaryPropertyName}"`,
{ itemIndex: i },
);
}
const fileBufferData = await this.helpers.getBinaryDataBuffer( const fileBufferData = await this.helpers.getBinaryDataBuffer(
i, i,
binaryPropertyName, binaryPropertyName,
@@ -398,14 +346,14 @@ export class Cortex implements INodeType {
const sha256 = createHash('sha256').update(fileBufferData).digest('hex'); const sha256 = createHash('sha256').update(fileBufferData).digest('hex');
(body.data as IDataObject).attachment = { (body.data as IDataObject).attachment = {
name: item.binary[binaryPropertyName].fileName, name: binaryData.fileName,
hashes: [ hashes: [
sha256, sha256,
createHash('sha1').update(fileBufferData).digest('hex'), createHash('sha1').update(fileBufferData).digest('hex'),
createHash('md5').update(fileBufferData).digest('hex'), createHash('md5').update(fileBufferData).digest('hex'),
], ],
size: fileBufferData.byteLength, size: fileBufferData.byteLength,
contentType: item.binary[binaryPropertyName].mimeType, contentType: binaryData.mimeType,
id: sha256, id: sha256,
}; };

View File

@@ -1,7 +1,6 @@
import type { IExecuteFunctions } from 'n8n-core';
import type { import type {
IDataObject, IDataObject,
IExecuteFunctions,
INodeExecutionData, INodeExecutionData,
INodeType, INodeType,
INodeTypeDescription, INodeTypeDescription,
@@ -760,26 +759,9 @@ export class Dropbox implements INodeType {
options = { json: false }; options = { json: false };
if (this.getNodeParameter('binaryData', i)) { if (this.getNodeParameter('binaryData', i)) {
// Is binary file to upload const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i);
const item = items[i]; this.helpers.assertBinaryData(i, binaryPropertyName);
body = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName);
if (item.binary === undefined) {
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!', {
itemIndex: i,
});
}
const propertyNameUpload = this.getNodeParameter('binaryPropertyName', i);
if (item.binary[propertyNameUpload] === undefined) {
throw new NodeOperationError(
this.getNode(),
`Item has no binary property called "${propertyNameUpload}"`,
{ itemIndex: i },
);
}
body = await this.helpers.getBinaryDataBuffer(i, propertyNameUpload);
} else { } else {
// Is text file // Is text file
body = Buffer.from(this.getNodeParameter('fileContent', i) as string, 'utf8'); body = Buffer.from(this.getNodeParameter('fileContent', i) as string, 'utf8');

View File

@@ -1,6 +1,6 @@
import type { IExecuteFunctions } from 'n8n-core';
import type { import type {
IDataObject, IDataObject,
IExecuteFunctions,
ILoadOptionsFunctions, ILoadOptionsFunctions,
INodeExecutionData, INodeExecutionData,
INodeProperties, INodeProperties,
@@ -8,7 +8,7 @@ import type {
INodeType, INodeType,
INodeTypeDescription, INodeTypeDescription,
} from 'n8n-workflow'; } from 'n8n-workflow';
import { deepCopy, NodeOperationError } from 'n8n-workflow'; import { deepCopy } from 'n8n-workflow';
import gm from 'gm'; import gm from 'gm';
import { file } from 'tmp-promise'; import { file } from 'tmp-promise';
import { parse as pathParse } from 'path'; import { parse as pathParse } from 'path';
@@ -1058,20 +1058,7 @@ export class EditImage implements INodeType {
if (operations[0].operation !== 'create') { if (operations[0].operation !== 'create') {
// "create" generates a new image so does not require any incoming data. // "create" generates a new image so does not require any incoming data.
if (item.binary === undefined) { this.helpers.assertBinaryData(itemIndex, dataPropertyName);
throw new NodeOperationError(this.getNode(), 'Item does not contain any binary data.', {
itemIndex,
});
}
if (item.binary[dataPropertyName] === undefined) {
throw new NodeOperationError(
this.getNode(),
`Item does not contain any binary data with the name "${dataPropertyName}".`,
{ itemIndex },
);
}
const binaryDataBuffer = await this.helpers.getBinaryDataBuffer( const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(
itemIndex, itemIndex,
dataPropertyName, dataPropertyName,
@@ -1123,20 +1110,15 @@ export class EditImage implements INodeType {
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands // eslint-disable-next-line @typescript-eslint/restrict-plus-operands
(positionX >= 0 ? '+' : '') + positionX + (positionY >= 0 ? '+' : '') + positionY; (positionX >= 0 ? '+' : '') + positionX + (positionY >= 0 ? '+' : '') + positionY;
if (item.binary![operationData.dataPropertyNameComposite as string] === undefined) { const binaryPropertyName = operationData.dataPropertyNameComposite as string;
throw new NodeOperationError( this.helpers.assertBinaryData(itemIndex, binaryPropertyName);
this.getNode(), const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(
`Item does not contain any binary data with the name "${operationData.dataPropertyNameComposite}".`, itemIndex,
{ itemIndex }, binaryPropertyName,
); );
}
const { fd, path, cleanup } = await file(); const { fd, path, cleanup } = await file();
cleanupFunctions.push(cleanup); cleanupFunctions.push(cleanup);
const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(
itemIndex,
operationData.dataPropertyNameComposite as string,
);
await fsWriteFileAsync(fd, binaryDataBuffer); await fsWriteFileAsync(fd, binaryDataBuffer);
if (operations[0].operation === 'create') { if (operations[0].operation === 'create') {

View File

@@ -1,8 +1,7 @@
/* eslint-disable n8n-nodes-base/node-filename-against-convention */ /* eslint-disable n8n-nodes-base/node-filename-against-convention */
import type { IExecuteFunctions } from 'n8n-core';
import type { import type {
IDataObject, IDataObject,
IExecuteFunctions,
INodeExecutionData, INodeExecutionData,
INodeType, INodeType,
INodeTypeBaseDescription, INodeTypeBaseDescription,
@@ -211,11 +210,9 @@ export class EmailSendV1 implements INodeType {
}); });
for (const propertyName of attachmentProperties) { for (const propertyName of attachmentProperties) {
if (!item.binary.hasOwnProperty(propertyName)) { const binaryData = this.helpers.assertBinaryData(itemIndex, propertyName);
continue;
}
attachments.push({ attachments.push({
filename: item.binary[propertyName].fileName || 'unknown', filename: binaryData.fileName || 'unknown',
content: await this.helpers.getBinaryDataBuffer(itemIndex, propertyName), content: await this.helpers.getBinaryDataBuffer(itemIndex, propertyName),
}); });
} }

View File

@@ -223,11 +223,9 @@ export async function execute(this: IExecuteFunctions): Promise<INodeExecutionDa
}); });
for (const propertyName of attachmentProperties) { for (const propertyName of attachmentProperties) {
if (!item.binary.hasOwnProperty(propertyName)) { const binaryData = this.helpers.assertBinaryData(itemIndex, propertyName);
continue;
}
attachments.push({ attachments.push({
filename: item.binary[propertyName].fileName || 'unknown', filename: binaryData.fileName || 'unknown',
content: await this.helpers.getBinaryDataBuffer(itemIndex, propertyName), content: await this.helpers.getBinaryDataBuffer(itemIndex, propertyName),
}); });
} }

View File

@@ -1,6 +1,6 @@
import type { IExecuteFunctions } from 'n8n-core';
import type { import type {
IDataObject, IDataObject,
IExecuteFunctions,
INodeExecutionData, INodeExecutionData,
INodeType, INodeType,
INodeTypeDescription, INodeTypeDescription,
@@ -367,13 +367,6 @@ export class FacebookGraphApi implements INodeType {
const sendBinaryData = this.getNodeParameter('sendBinaryData', itemIndex, false) as boolean; const sendBinaryData = this.getNodeParameter('sendBinaryData', itemIndex, false) as boolean;
if (sendBinaryData) { if (sendBinaryData) {
const item = items[itemIndex];
if (item.binary === undefined) {
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!', {
itemIndex,
});
}
const binaryPropertyNameFull = this.getNodeParameter('binaryPropertyName', itemIndex); const binaryPropertyNameFull = this.getNodeParameter('binaryPropertyName', itemIndex);
let propertyName = 'file'; let propertyName = 'file';
@@ -384,16 +377,7 @@ export class FacebookGraphApi implements INodeType {
binaryPropertyName = binaryPropertyNameParts[1]; binaryPropertyName = binaryPropertyNameParts[1];
} }
if (item.binary[binaryPropertyName] === undefined) { const binaryData = this.helpers.assertBinaryData(itemIndex, binaryPropertyName);
throw new NodeOperationError(
this.getNode(),
`Item has no binary property called "${binaryPropertyName}"`,
{ itemIndex },
);
}
const binaryProperty = item.binary[binaryPropertyName];
const binaryDataBuffer = await this.helpers.getBinaryDataBuffer( const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(
itemIndex, itemIndex,
binaryPropertyName, binaryPropertyName,
@@ -402,8 +386,8 @@ export class FacebookGraphApi implements INodeType {
[propertyName]: { [propertyName]: {
value: binaryDataBuffer, value: binaryDataBuffer,
options: { options: {
filename: binaryProperty.fileName, filename: binaryData.fileName,
contentType: binaryProperty.mimeType, contentType: binaryData.mimeType,
}, },
}, },
}; };

View File

@@ -1,17 +1,17 @@
import type { IExecuteFunctions } from 'n8n-core';
import { BINARY_ENCODING } from 'n8n-core'; import { BINARY_ENCODING } from 'n8n-core';
import type { import type {
ICredentialDataDecryptedObject, ICredentialDataDecryptedObject,
ICredentialsDecrypted, ICredentialsDecrypted,
ICredentialTestFunctions, ICredentialTestFunctions,
IDataObject, IDataObject,
IExecuteFunctions,
INodeCredentialTestResult, INodeCredentialTestResult,
INodeExecutionData, INodeExecutionData,
INodeType, INodeType,
INodeTypeDescription, INodeTypeDescription,
JsonObject, JsonObject,
} from 'n8n-workflow'; } from 'n8n-workflow';
import { NodeApiError, NodeOperationError } from 'n8n-workflow'; import { NodeApiError } from 'n8n-workflow';
import { createWriteStream } from 'fs'; import { createWriteStream } from 'fs';
import { basename, dirname } from 'path'; import { basename, dirname } from 'path';
import type { Readable } from 'stream'; import type { Readable } from 'stream';
@@ -624,30 +624,14 @@ export class Ftp implements INodeType {
await recursivelyCreateSftpDirs(sftp!, remotePath); await recursivelyCreateSftpDirs(sftp!, remotePath);
if (this.getNodeParameter('binaryData', i)) { if (this.getNodeParameter('binaryData', i)) {
// Is binary file to upload const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i);
const item = items[i]; const binaryData = this.helpers.assertBinaryData(i, binaryPropertyName);
if (item.binary === undefined) {
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!', {
itemIndex: i,
});
}
const propertyNameUpload = this.getNodeParameter('binaryPropertyName', i);
const itemBinaryData = item.binary[propertyNameUpload];
if (itemBinaryData === undefined) {
throw new NodeOperationError(
this.getNode(),
`Item has no binary property called "${propertyNameUpload}"`,
{ itemIndex: i },
);
}
let uploadData: Buffer | Readable; let uploadData: Buffer | Readable;
if (itemBinaryData.id) { if (binaryData.id) {
uploadData = this.helpers.getBinaryStream(itemBinaryData.id); uploadData = this.helpers.getBinaryStream(binaryData.id);
} else { } else {
uploadData = Buffer.from(itemBinaryData.data, BINARY_ENCODING); uploadData = Buffer.from(binaryData.data, BINARY_ENCODING);
} }
await sftp!.put(uploadData, remotePath); await sftp!.put(uploadData, remotePath);
} else { } else {
@@ -750,30 +734,14 @@ export class Ftp implements INodeType {
const dirPath = remotePath.replace(fileName, ''); const dirPath = remotePath.replace(fileName, '');
if (this.getNodeParameter('binaryData', i)) { if (this.getNodeParameter('binaryData', i)) {
// Is binary file to upload const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i);
const item = items[i]; const binaryData = this.helpers.assertBinaryData(i, binaryPropertyName);
if (item.binary === undefined) {
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!', {
itemIndex: i,
});
}
const propertyNameUpload = this.getNodeParameter('binaryPropertyName', i);
const itemBinaryData = item.binary[propertyNameUpload];
if (itemBinaryData === undefined) {
throw new NodeOperationError(
this.getNode(),
`Item has no binary property called "${propertyNameUpload}"`,
{ itemIndex: i },
);
}
let uploadData: Buffer | Readable; let uploadData: Buffer | Readable;
if (itemBinaryData.id) { if (binaryData.id) {
uploadData = this.helpers.getBinaryStream(itemBinaryData.id); uploadData = this.helpers.getBinaryStream(binaryData.id);
} else { } else {
uploadData = Buffer.from(itemBinaryData.data, BINARY_ENCODING); uploadData = Buffer.from(binaryData.data, BINARY_ENCODING);
} }
try { try {

View File

@@ -1,7 +1,6 @@
import type { IExecuteFunctions } from 'n8n-core';
import type { import type {
IDataObject, IDataObject,
IExecuteFunctions,
INodeExecutionData, INodeExecutionData,
INodeType, INodeType,
INodeTypeDescription, INodeTypeDescription,
@@ -1821,28 +1820,12 @@ export class Github implements INodeType {
body.message = this.getNodeParameter('commitMessage', i) as string; body.message = this.getNodeParameter('commitMessage', i) as string;
if (this.getNodeParameter('binaryData', i)) { if (this.getNodeParameter('binaryData', i)) {
// Is binary file to upload
const item = items[i];
if (item.binary === undefined) {
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!', {
itemIndex: i,
});
}
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i);
if (item.binary[binaryPropertyName] === undefined) {
throw new NodeOperationError(
this.getNode(),
`Item has no binary property called "${binaryPropertyName}"`,
{ itemIndex: i },
);
}
// Currently internally n8n uses base64 and also Github expects it base64 encoded. // Currently internally n8n uses base64 and also Github expects it base64 encoded.
// If that ever changes the data has to get converted here. // If that ever changes the data has to get converted here.
body.content = item.binary[binaryPropertyName].data; const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i);
const binaryData = this.helpers.assertBinaryData(i, binaryPropertyName);
// TODO: Does this work with filesystem mode
body.content = binaryData.data;
} else { } else {
// Is text file // Is text file
// body.content = Buffer.from(this.getNodeParameter('fileContent', i) as string, 'base64'); // body.content = Buffer.from(this.getNodeParameter('fileContent', i) as string, 'base64');

View File

@@ -1,7 +1,6 @@
import type { IExecuteFunctions } from 'n8n-core';
import type { import type {
IDataObject, IDataObject,
IExecuteFunctions,
INodeExecutionData, INodeExecutionData,
INodeType, INodeType,
INodeTypeDescription, INodeTypeDescription,
@@ -1572,28 +1571,12 @@ export class Gitlab implements INodeType {
} }
if (this.getNodeParameter('binaryData', i)) { if (this.getNodeParameter('binaryData', i)) {
// Is binary file to upload
const item = items[i];
if (item.binary === undefined) {
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!', {
itemIndex: i,
});
}
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i);
if (item.binary[binaryPropertyName] === undefined) {
throw new NodeOperationError(
this.getNode(),
`Item has no binary property called "${binaryPropertyName}"`,
{ itemIndex: i },
);
}
// Currently internally n8n uses base64 and also GitLab expects it base64 encoded. // Currently internally n8n uses base64 and also GitLab expects it base64 encoded.
// If that ever changes the data has to get converted here. // If that ever changes the data has to get converted here.
body.content = item.binary[binaryPropertyName].data; const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i);
const binaryData = this.helpers.assertBinaryData(i, binaryPropertyName);
// TODO: Does this work with filesystem mode
body.content = binaryData.data;
body.encoding = 'base64'; body.encoding = 'base64';
} else { } else {
// Is text file // Is text file

View File

@@ -1,6 +1,5 @@
import FormData from 'form-data'; import FormData from 'form-data';
import type { IDataObject, INodeExecutionData, INodeProperties } from 'n8n-workflow'; import type { IDataObject, INodeExecutionData, INodeProperties } from 'n8n-workflow';
import { NodeOperationError } from 'n8n-workflow';
// Define these because we'll be using them in two separate places // Define these because we'll be using them in two separate places
const metagenerationFilters: INodeProperties[] = [ const metagenerationFilters: INodeProperties[] = [
@@ -140,7 +139,6 @@ export const objectOperations: INodeProperties[] = [
// Populate request body // Populate request body
const body = new FormData(); const body = new FormData();
const item = this.getInputData();
body.append('metadata', JSON.stringify(metadata), { body.append('metadata', JSON.stringify(metadata), {
contentType: 'application/json', contentType: 'application/json',
}); });
@@ -152,20 +150,8 @@ export const objectOperations: INodeProperties[] = [
const binaryPropertyName = this.getNodeParameter( const binaryPropertyName = this.getNodeParameter(
'createBinaryPropertyName', 'createBinaryPropertyName',
) as string; ) as string;
if (!item.binary) {
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!', {
itemIndex: this.getItemIndex(),
});
}
if (item.binary[binaryPropertyName] === undefined) {
throw new NodeOperationError(
this.getNode(),
`Item has no binary property called "${binaryPropertyName}"`,
{ itemIndex: this.getItemIndex() },
);
}
const binaryData = item.binary[binaryPropertyName]; const binaryData = this.helpers.assertBinaryData(binaryPropertyName);
// Decode from base64 for upload // Decode from base64 for upload
content = Buffer.from(binaryData.data, 'base64'); content = Buffer.from(binaryData.data, 'base64');

View File

@@ -1,13 +1,12 @@
import type { IExecuteFunctions } from 'n8n-core';
import { BINARY_ENCODING } from 'n8n-core'; import { BINARY_ENCODING } from 'n8n-core';
import type { import type {
IDataObject, IDataObject,
IExecuteFunctions,
INodeExecutionData, INodeExecutionData,
INodeType, INodeType,
INodeTypeDescription, INodeTypeDescription,
} from 'n8n-workflow'; } from 'n8n-workflow';
import { NodeOperationError } from 'n8n-workflow';
import { googleApiRequest, googleApiRequestAllItems } from './GenericFunctions'; import { googleApiRequest, googleApiRequestAllItems } from './GenericFunctions';
@@ -2433,38 +2432,20 @@ export class GoogleDrive implements INodeType {
let mimeType = 'text/plain'; let mimeType = 'text/plain';
if (this.getNodeParameter('binaryData', i)) { if (this.getNodeParameter('binaryData', i)) {
// Is binary file to upload const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i);
const item = items[i]; const binaryData = this.helpers.assertBinaryData(i, binaryPropertyName);
if (binaryData.id) {
if (item.binary === undefined) {
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!', {
itemIndex: i,
});
}
const propertyNameUpload = this.getNodeParameter('binaryPropertyName', i);
const binary = item.binary[propertyNameUpload];
if (binary === undefined) {
throw new NodeOperationError(
this.getNode(),
`Item has no binary property called "${propertyNameUpload}"`,
{ itemIndex: i },
);
}
if (binary.id) {
// Stream data in 256KB chunks, and upload the via the resumable upload api // Stream data in 256KB chunks, and upload the via the resumable upload api
fileContent = this.helpers.getBinaryStream(binary.id, UPLOAD_CHUNK_SIZE); fileContent = this.helpers.getBinaryStream(binaryData.id, UPLOAD_CHUNK_SIZE);
const metadata = await this.helpers.getBinaryMetadata(binary.id); const metadata = await this.helpers.getBinaryMetadata(binaryData.id);
contentLength = metadata.fileSize; contentLength = metadata.fileSize;
originalFilename = metadata.fileName; originalFilename = metadata.fileName;
if (metadata.mimeType) mimeType = binary.mimeType; if (metadata.mimeType) mimeType = binaryData.mimeType;
} else { } else {
fileContent = Buffer.from(binary.data, BINARY_ENCODING); fileContent = Buffer.from(binaryData.data, BINARY_ENCODING);
contentLength = fileContent.length; contentLength = fileContent.length;
originalFilename = binary.fileName; originalFilename = binaryData.fileName;
mimeType = binary.mimeType; mimeType = binaryData.mimeType;
} }
} else { } else {
// Is text file // Is text file

View File

@@ -508,18 +508,10 @@ export async function prepareEmailAttachments(
if (attachments && !isEmpty(attachments)) { if (attachments && !isEmpty(attachments)) {
for (const { property } of attachments) { for (const { property } of attachments) {
for (const name of (property as string).split(',')) { for (const name of (property as string).split(',')) {
if (!items[itemIndex].binary || items[itemIndex].binary![name] === undefined) { const binaryData = this.helpers.assertBinaryData(itemIndex, name);
const description = `This node has no input field called '${name}' `;
throw new NodeOperationError(this.getNode(), 'Attachment not found', {
description,
itemIndex,
});
}
const binaryData = items[itemIndex].binary![name];
const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(itemIndex, name); const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(itemIndex, name);
if (!items[itemIndex].binary![name] || !Buffer.isBuffer(binaryDataBuffer)) { if (!Buffer.isBuffer(binaryDataBuffer)) {
const description = `The input field '${name}' doesn't contain an attachment. Please make sure you specify a field containing binary data`; const description = `The input field '${name}' doesn't contain an attachment. Please make sure you specify a field containing binary data`;
throw new NodeOperationError(this.getNode(), 'Attachment not found', { throw new NodeOperationError(this.getNode(), 'Attachment not found', {
description, description,

View File

@@ -1,9 +1,8 @@
/* eslint-disable n8n-nodes-base/node-filename-against-convention */ /* eslint-disable n8n-nodes-base/node-filename-against-convention */
import type { IExecuteFunctions } from 'n8n-core';
import type { import type {
IBinaryKeyData, IBinaryKeyData,
IDataObject, IDataObject,
IExecuteFunctions,
ILoadOptionsFunctions, ILoadOptionsFunctions,
INodeExecutionData, INodeExecutionData,
INodePropertyOptions, INodePropertyOptions,
@@ -314,11 +313,9 @@ export class GmailV1 implements INodeType {
!isEmpty(attachmentsUi.attachmentsBinary) && !isEmpty(attachmentsUi.attachmentsBinary) &&
items[i].binary items[i].binary
) { ) {
// @ts-ignore
for (const { property } of attachmentsUi.attachmentsBinary as IDataObject[]) { for (const { property } of attachmentsUi.attachmentsBinary as IDataObject[]) {
for (const binaryProperty of (property as string).split(',')) { for (const binaryProperty of (property as string).split(',')) {
if (items[i].binary![binaryProperty] !== undefined) { const binaryData = this.helpers.assertBinaryData(i, binaryProperty);
const binaryData = items[i].binary![binaryProperty];
const binaryDataBuffer = await this.helpers.getBinaryDataBuffer( const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(
i, i,
binaryProperty, binaryProperty,
@@ -331,7 +328,6 @@ export class GmailV1 implements INodeType {
} }
} }
} }
}
qs = { qs = {
userId: 'me', userId: 'me',
@@ -404,11 +400,9 @@ export class GmailV1 implements INodeType {
!isEmpty(attachmentsUi.attachmentsBinary) && !isEmpty(attachmentsUi.attachmentsBinary) &&
items[i].binary items[i].binary
) { ) {
// @ts-ignore
for (const { property } of attachmentsUi.attachmentsBinary as IDataObject[]) { for (const { property } of attachmentsUi.attachmentsBinary as IDataObject[]) {
for (const binaryProperty of (property as string).split(',')) { for (const binaryProperty of (property as string).split(',')) {
if (items[i].binary![binaryProperty] !== undefined) { const binaryData = this.helpers.assertBinaryData(i, binaryProperty);
const binaryData = items[i].binary![binaryProperty];
const binaryDataBuffer = await this.helpers.getBinaryDataBuffer( const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(
i, i,
binaryProperty, binaryProperty,
@@ -421,7 +415,6 @@ export class GmailV1 implements INodeType {
} }
} }
} }
}
qs = { qs = {
userId: 'me', userId: 'me',
@@ -651,8 +644,7 @@ export class GmailV1 implements INodeType {
) { ) {
for (const { property } of attachmentsUi.attachmentsBinary as IDataObject[]) { for (const { property } of attachmentsUi.attachmentsBinary as IDataObject[]) {
for (const binaryProperty of (property as string).split(',')) { for (const binaryProperty of (property as string).split(',')) {
if (items[i].binary![binaryProperty] !== undefined) { const binaryData = this.helpers.assertBinaryData(i, binaryProperty);
const binaryData = items[i].binary![binaryProperty];
const binaryDataBuffer = await this.helpers.getBinaryDataBuffer( const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(
i, i,
binaryProperty, binaryProperty,
@@ -666,7 +658,6 @@ export class GmailV1 implements INodeType {
} }
} }
} }
}
qs = { qs = {
userId: 'me', userId: 'me',

View File

@@ -1,7 +1,7 @@
import type { IExecuteFunctions } from 'n8n-core';
import { BINARY_ENCODING } from 'n8n-core'; import { BINARY_ENCODING } from 'n8n-core';
import type { import type {
IDataObject, IDataObject,
IExecuteFunctions,
ILoadOptionsFunctions, ILoadOptionsFunctions,
INodeExecutionData, INodeExecutionData,
INodePropertyOptions, INodePropertyOptions,
@@ -387,35 +387,12 @@ export class YouTube implements INodeType {
if (operation === 'uploadBanner') { if (operation === 'uploadBanner') {
const channelId = this.getNodeParameter('channelId', i) as string; const channelId = this.getNodeParameter('channelId', i) as string;
const binaryProperty = this.getNodeParameter('binaryProperty', i); const binaryProperty = this.getNodeParameter('binaryProperty', i);
const binaryData = this.helpers.assertBinaryData(i, binaryProperty);
let mimeType;
// Is binary file to upload
const item = items[i];
if (item.binary === undefined) {
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!', {
itemIndex: i,
});
}
if (item.binary[binaryProperty] === undefined) {
throw new NodeOperationError(
this.getNode(),
`Item has no binary property called "${binaryProperty}"`,
{ itemIndex: i },
);
}
if (item.binary[binaryProperty].mimeType) {
mimeType = item.binary[binaryProperty].mimeType;
}
const body = await this.helpers.getBinaryDataBuffer(i, binaryProperty); const body = await this.helpers.getBinaryDataBuffer(i, binaryProperty);
const requestOptions = { const requestOptions = {
headers: { headers: {
'Content-Type': mimeType, ...(binaryData.mimeType ? { 'Content-Type': binaryData.mimeType } : {}),
}, },
json: false, json: false,
}; };
@@ -854,38 +831,18 @@ export class YouTube implements INodeType {
const options = this.getNodeParameter('options', i); const options = this.getNodeParameter('options', i);
const binaryProperty = this.getNodeParameter('binaryProperty', i); const binaryProperty = this.getNodeParameter('binaryProperty', i);
// Is binary file to upload const binaryData = this.helpers.assertBinaryData(i, binaryProperty);
const item = items[i];
if (item.binary === undefined) {
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!', {
itemIndex: i,
});
}
const binaryData = item.binary[binaryProperty];
if (binaryData === undefined) {
throw new NodeOperationError(
this.getNode(),
`Item has no binary property called "${binaryProperty}"`,
{ itemIndex: i },
);
}
let mimeType: string; let mimeType: string;
let contentLength: number; let contentLength: number;
let fileContent: Buffer | Readable; let fileContent: Buffer | Readable;
if (binaryData.mimeType) {
mimeType = binaryData.mimeType;
}
if (binaryData.id) { if (binaryData.id) {
// Stream data in 256KB chunks, and upload the via the resumable upload api // Stream data in 256KB chunks, and upload the via the resumable upload api
fileContent = this.helpers.getBinaryStream(binaryData.id, UPLOAD_CHUNK_SIZE); fileContent = this.helpers.getBinaryStream(binaryData.id, UPLOAD_CHUNK_SIZE);
const metadata = await this.helpers.getBinaryMetadata(binaryData.id); const metadata = await this.helpers.getBinaryMetadata(binaryData.id);
contentLength = metadata.fileSize; contentLength = metadata.fileSize;
mimeType = binaryData.mimeType; mimeType = metadata.mimeType ?? binaryData.mimeType;
} else { } else {
fileContent = Buffer.from(binaryData.data, BINARY_ENCODING); fileContent = Buffer.from(binaryData.data, BINARY_ENCODING);
contentLength = fileContent.length; contentLength = fileContent.length;

View File

@@ -296,23 +296,7 @@ export class Html implements INodeType {
} }
htmlArray = item.json[dataPropertyName] as string; htmlArray = item.json[dataPropertyName] as string;
} else { } else {
if (item.binary === undefined) { this.helpers.assertBinaryData(itemIndex, dataPropertyName);
throw new NodeOperationError(
this.getNode(),
'No item does not contain binary data!',
{
itemIndex,
},
);
}
if (item.binary[dataPropertyName] === undefined) {
throw new NodeOperationError(
this.getNode(),
`No property named "${dataPropertyName}" exists!`,
{ itemIndex },
);
}
const binaryDataBuffer = await this.helpers.getBinaryDataBuffer( const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(
itemIndex, itemIndex,
dataPropertyName, dataPropertyName,

View File

@@ -1,7 +1,7 @@
import cheerio from 'cheerio'; import cheerio from 'cheerio';
import type { IExecuteFunctions } from 'n8n-core';
import type { import type {
IDataObject, IDataObject,
IExecuteFunctions,
INodeExecutionData, INodeExecutionData,
INodeType, INodeType,
INodeTypeDescription, INodeTypeDescription,
@@ -236,19 +236,7 @@ export class HtmlExtract implements INodeType {
} }
htmlArray = item.json[dataPropertyName] as string; htmlArray = item.json[dataPropertyName] as string;
} else { } else {
if (item.binary === undefined) { this.helpers.assertBinaryData(itemIndex, dataPropertyName);
throw new NodeOperationError(this.getNode(), 'No item does not contain binary data!', {
itemIndex,
});
}
if (item.binary[dataPropertyName] === undefined) {
throw new NodeOperationError(
this.getNode(),
`No property named "${dataPropertyName}" exists!`,
{ itemIndex },
);
}
const binaryDataBuffer = await this.helpers.getBinaryDataBuffer( const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(
itemIndex, itemIndex,
dataPropertyName, dataPropertyName,

View File

@@ -20,7 +20,7 @@ interface OptionData {
displayName: string; displayName: string;
} }
interface OptionDataParamters { interface OptionDataParameters {
[key: string]: OptionData; [key: string]: OptionData;
} }
@@ -637,7 +637,7 @@ export class HttpRequestV1 implements INodeType {
queryParametersUi: 'qs', queryParametersUi: 'qs',
}; };
const jsonParameters: OptionDataParamters = { const jsonParameters: OptionDataParameters = {
bodyParametersJson: { bodyParametersJson: {
name: 'body', name: 'body',
displayName: 'Body Parameters', displayName: 'Body Parameters',
@@ -648,7 +648,7 @@ export class HttpRequestV1 implements INodeType {
}, },
queryParametersJson: { queryParametersJson: {
name: 'qs', name: 'qs',
displayName: 'Query Paramters', displayName: 'Query Parameters',
}, },
}; };
let returnItems: INodeExecutionData[] = []; let returnItems: INodeExecutionData[] = [];
@@ -730,7 +730,7 @@ export class HttpRequestV1 implements INodeType {
const contentTypesAllowed = ['raw', 'multipart-form-data']; const contentTypesAllowed = ['raw', 'multipart-form-data'];
if (!contentTypesAllowed.includes(options.bodyContentType as string)) { 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. // easily to handle parameters in dot.notation simply error for now.
throw new NodeOperationError( throw new NodeOperationError(
this.getNode(), 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') { if (options.bodyContentType === 'raw') {
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', itemIndex); const binaryPropertyName = this.getNodeParameter('binaryPropertyName', itemIndex);
if (item.binary[binaryPropertyName] === undefined) { this.helpers.assertBinaryData(itemIndex, binaryPropertyName);
throw new NodeOperationError(
this.getNode(),
`Item has no binary property called "${binaryPropertyName}"`,
{ itemIndex },
);
}
const binaryDataBuffer = await this.helpers.getBinaryDataBuffer( const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(
itemIndex, itemIndex,
binaryPropertyName, binaryPropertyName,
@@ -787,14 +772,7 @@ export class HttpRequestV1 implements INodeType {
); );
} }
if (item.binary[binaryPropertyName] === undefined) { const binaryData = this.helpers.assertBinaryData(itemIndex, binaryPropertyName);
throw new NodeOperationError(
this.getNode(),
`Item has no binary property called "${binaryPropertyName}"`,
);
}
const binaryProperty = item.binary[binaryPropertyName];
const binaryDataBuffer = await this.helpers.getBinaryDataBuffer( const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(
itemIndex, itemIndex,
binaryPropertyName, binaryPropertyName,
@@ -803,8 +781,8 @@ export class HttpRequestV1 implements INodeType {
requestOptions.body[propertyName] = { requestOptions.body[propertyName] = {
value: binaryDataBuffer, value: binaryDataBuffer,
options: { options: {
filename: binaryProperty.fileName, filename: binaryData.fileName,
contentType: binaryProperty.mimeType, contentType: binaryData.mimeType,
}, },
}; };
} }
@@ -814,7 +792,7 @@ export class HttpRequestV1 implements INodeType {
} }
if (tempValue === '') { if (tempValue === '') {
// Paramter is empty so skip it // Parameter is empty so skip it
continue; continue;
} }
@@ -842,7 +820,7 @@ export class HttpRequestV1 implements INodeType {
} }
} }
} else { } else {
// Paramters are defined in UI // Parameters are defined in UI
let optionName: string; let optionName: string;
for (const parameterName of Object.keys(uiParameters)) { for (const parameterName of Object.keys(uiParameters)) {
setUiParameter = this.getNodeParameter(parameterName, itemIndex, {}) as IDataObject; setUiParameter = this.getNodeParameter(parameterName, itemIndex, {}) as IDataObject;

View File

@@ -1,6 +1,6 @@
import type { IExecuteFunctions } from 'n8n-core';
import type { import type {
IDataObject, IDataObject,
IExecuteFunctions,
INodeExecutionData, INodeExecutionData,
INodeType, INodeType,
INodeTypeBaseDescription, INodeTypeBaseDescription,
@@ -22,7 +22,7 @@ interface OptionData {
displayName: string; displayName: string;
} }
interface OptionDataParamters { interface OptionDataParameters {
[key: string]: OptionData; [key: string]: OptionData;
} }
@@ -674,7 +674,7 @@ export class HttpRequestV2 implements INodeType {
queryParametersUi: 'qs', queryParametersUi: 'qs',
}; };
const jsonParameters: OptionDataParamters = { const jsonParameters: OptionDataParameters = {
bodyParametersJson: { bodyParametersJson: {
name: 'body', name: 'body',
displayName: 'Body Parameters', displayName: 'Body Parameters',
@@ -685,7 +685,7 @@ export class HttpRequestV2 implements INodeType {
}, },
queryParametersJson: { queryParametersJson: {
name: 'qs', name: 'qs',
displayName: 'Query Paramters', displayName: 'Query Parameters',
}, },
}; };
let returnItems: INodeExecutionData[] = []; let returnItems: INodeExecutionData[] = [];
@@ -767,7 +767,7 @@ export class HttpRequestV2 implements INodeType {
const contentTypesAllowed = ['raw', 'multipart-form-data']; const contentTypesAllowed = ['raw', 'multipart-form-data'];
if (!contentTypesAllowed.includes(options.bodyContentType as string)) { 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. // easily to handle parameters in dot.notation simply error for now.
throw new NodeOperationError( throw new NodeOperationError(
this.getNode(), 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') { if (options.bodyContentType === 'raw') {
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', itemIndex); const binaryPropertyName = this.getNodeParameter('binaryPropertyName', itemIndex);
if (item.binary[binaryPropertyName] === undefined) { this.helpers.assertBinaryData(itemIndex, binaryPropertyName);
throw new NodeOperationError(
this.getNode(),
`Item has no binary property called "${binaryPropertyName}"`,
{ itemIndex },
);
}
const binaryDataBuffer = await this.helpers.getBinaryDataBuffer( const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(
itemIndex, itemIndex,
binaryPropertyName, binaryPropertyName,
@@ -824,14 +809,7 @@ export class HttpRequestV2 implements INodeType {
); );
} }
if (item.binary[binaryPropertyName] === undefined) { const binaryData = this.helpers.assertBinaryData(itemIndex, binaryPropertyName);
throw new NodeOperationError(
this.getNode(),
`Item has no binary property called "${binaryPropertyName}"`,
);
}
const binaryProperty = item.binary[binaryPropertyName];
const binaryDataBuffer = await this.helpers.getBinaryDataBuffer( const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(
itemIndex, itemIndex,
binaryPropertyName, binaryPropertyName,
@@ -840,8 +818,8 @@ export class HttpRequestV2 implements INodeType {
requestOptions.body[propertyName] = { requestOptions.body[propertyName] = {
value: binaryDataBuffer, value: binaryDataBuffer,
options: { options: {
filename: binaryProperty.fileName, filename: binaryData.fileName,
contentType: binaryProperty.mimeType, contentType: binaryData.mimeType,
}, },
}; };
} }
@@ -851,7 +829,7 @@ export class HttpRequestV2 implements INodeType {
} }
if (tempValue === '') { if (tempValue === '') {
// Paramter is empty so skip it // Parameter is empty so skip it
continue; continue;
} }
@@ -879,7 +857,7 @@ export class HttpRequestV2 implements INodeType {
} }
} }
} else { } else {
// Paramters are defined in UI // Parameters are defined in UI
let optionName: string; let optionName: string;
for (const parameterName of Object.keys(uiParameters)) { for (const parameterName of Object.keys(uiParameters)) {
setUiParameter = this.getNodeParameter(parameterName, itemIndex, {}) as IDataObject; setUiParameter = this.getNodeParameter(parameterName, itemIndex, {}) as IDataObject;

View File

@@ -1,8 +1,7 @@
import type { IExecuteFunctions } from 'n8n-core';
import type { import type {
IBinaryKeyData, IBinaryKeyData,
IDataObject, IDataObject,
IExecuteFunctions,
INodeExecutionData, INodeExecutionData,
INodeType, INodeType,
INodeTypeBaseDescription, INodeTypeBaseDescription,
@@ -1067,22 +1066,8 @@ export class HttpRequestV3 implements INodeType {
) => { ) => {
const accumulator = await acc; const accumulator = await acc;
if (cur.parameterType === 'formBinaryData') { if (cur.parameterType === 'formBinaryData') {
const binaryDataOnInput = items[itemIndex]?.binary;
if (!cur.inputDataFieldName) return accumulator; if (!cur.inputDataFieldName) return accumulator;
const binaryData = this.helpers.assertBinaryData(itemIndex, cur.inputDataFieldName);
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 buffer = await this.helpers.getBinaryDataBuffer(itemIndex, cur.inputDataFieldName); const buffer = await this.helpers.getBinaryDataBuffer(itemIndex, cur.inputDataFieldName);
accumulator[cur.name] = { accumulator[cur.name] = {
@@ -1143,6 +1128,7 @@ export class HttpRequestV3 implements INodeType {
'inputDataFieldName', 'inputDataFieldName',
itemIndex, itemIndex,
) as string; ) as string;
this.helpers.assertBinaryData(itemIndex, inputDataFieldName);
requestOptions.body = await this.helpers.getBinaryDataBuffer( requestOptions.body = await this.helpers.getBinaryDataBuffer(
itemIndex, itemIndex,
inputDataFieldName, inputDataFieldName,

View File

@@ -1,13 +1,10 @@
import type { IExecuteFunctions } from 'n8n-core';
import type { import type {
IBinaryKeyData,
IDataObject, IDataObject,
IExecuteFunctions,
INodeExecutionData, INodeExecutionData,
INodeType, INodeType,
INodeTypeDescription, INodeTypeDescription,
} from 'n8n-workflow'; } from 'n8n-workflow';
import { NodeOperationError } from 'n8n-workflow';
import { humanticAiApiRequest } from './GenericFunctions'; import { humanticAiApiRequest } from './GenericFunctions';
@@ -71,26 +68,9 @@ export class HumanticAi implements INodeType {
if (sendResume) { if (sendResume) {
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i); const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i);
const binaryData = this.helpers.assertBinaryData(i, binaryPropertyName);
if (items[i].binary === undefined) {
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!', {
itemIndex: i,
});
}
const item = items[i].binary as IBinaryKeyData;
const binaryData = item[binaryPropertyName];
const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName); const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName);
if (binaryData === undefined) {
throw new NodeOperationError(
this.getNode(),
`Item has no binary property called "${binaryPropertyName}"`,
{ itemIndex: i },
);
}
responseData = await humanticAiApiRequest.call( responseData = await humanticAiApiRequest.call(
this, this,
'POST', 'POST',
@@ -144,26 +124,9 @@ export class HumanticAi implements INodeType {
if (sendResume) { if (sendResume) {
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i); const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i);
const binaryData = this.helpers.assertBinaryData(i, binaryPropertyName);
if (items[i].binary === undefined) {
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!', {
itemIndex: i,
});
}
const item = items[i].binary as IBinaryKeyData;
const binaryData = item[binaryPropertyName];
const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName); const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName);
if (binaryData === undefined) {
throw new NodeOperationError(
this.getNode(),
`Item has no binary property called "${binaryPropertyName}"`,
{ itemIndex: i },
);
}
responseData = await humanticAiApiRequest.call( responseData = await humanticAiApiRequest.call(
this, this,
'POST', 'POST',

View File

@@ -1057,23 +1057,9 @@ export class Jira implements INodeType {
for (let i = 0; i < length; i++) { for (let i = 0; i < length; i++) {
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i); const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i);
const issueKey = this.getNodeParameter('issueKey', i) as string; const issueKey = this.getNodeParameter('issueKey', i) as string;
const binaryData = this.helpers.assertBinaryData(i, binaryPropertyName);
if (items[i].binary === undefined) {
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!', {
itemIndex: i,
});
}
let uploadData: Buffer | Readable; let uploadData: Buffer | Readable;
const item = items[i].binary as IBinaryKeyData;
const binaryData = item[binaryPropertyName];
if (binaryData === undefined) {
throw new NodeOperationError(
this.getNode(),
`Item has no binary property called "${binaryPropertyName}"`,
{ itemIndex: i },
);
}
if (binaryData.id) { if (binaryData.id) {
uploadData = this.helpers.getBinaryStream(binaryData.id); uploadData = this.helpers.getBinaryStream(binaryData.id);
} else { } else {

View File

@@ -1,15 +1,12 @@
import type { IExecuteFunctions } from 'n8n-core';
import type { import type {
IBinaryKeyData,
IDataObject, IDataObject,
IExecuteFunctions,
ILoadOptionsFunctions, ILoadOptionsFunctions,
INodeExecutionData, INodeExecutionData,
INodePropertyOptions, INodePropertyOptions,
INodeType, INodeType,
INodeTypeDescription, INodeTypeDescription,
} from 'n8n-workflow'; } from 'n8n-workflow';
import { NodeOperationError } from 'n8n-workflow';
import { keapApiRequest, keapApiRequestAllItems, keysToSnakeCase } from './GenericFunctions'; import { keapApiRequest, keapApiRequestAllItems, keysToSnakeCase } from './GenericFunctions';
@@ -742,30 +739,15 @@ export class Keap implements INodeType {
keysToSnakeCase(attachmentsUi.attachmentsValues as IDataObject); keysToSnakeCase(attachmentsUi.attachmentsValues as IDataObject);
attachments = attachmentsUi.attachmentsValues as IAttachment[]; attachments = attachmentsUi.attachmentsValues as IAttachment[];
} }
if ( const attachmentsBinary = attachmentsUi.attachmentsBinary as Array<{
attachmentsUi.attachmentsBinary && property: string;
(attachmentsUi.attachmentsBinary as IDataObject).length }>;
) { if (attachmentsBinary?.length) {
if (items[i].binary === undefined) { for (const { property } of attachmentsBinary) {
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!', { const binaryData = this.helpers.assertBinaryData(i, property);
itemIndex: i,
});
}
for (const { property } of attachmentsUi.attachmentsBinary as IDataObject[]) {
const item = items[i].binary as IBinaryKeyData;
if (item[property as string] === undefined) {
throw new NodeOperationError(
this.getNode(),
`Item has no binary property called "${property}"`,
{ itemIndex: i },
);
}
attachments.push({ attachments.push({
file_data: item[property as string].data, file_data: binaryData.data,
file_name: item[property as string].fileName, file_name: binaryData.fileName,
}); });
} }
} }
@@ -815,7 +797,6 @@ export class Keap implements INodeType {
} }
//https://developer.infusionsoft.com/docs/rest/#!/File/createFileUsingPOST //https://developer.infusionsoft.com/docs/rest/#!/File/createFileUsingPOST
if (operation === 'upload') { if (operation === 'upload') {
const binaryData = this.getNodeParameter('binaryData', i);
const fileAssociation = this.getNodeParameter('fileAssociation', i) as string; const fileAssociation = this.getNodeParameter('fileAssociation', i) as string;
const isPublic = this.getNodeParameter('isPublic', i) as boolean; const isPublic = this.getNodeParameter('isPublic', i) as boolean;
const body: IFile = { const body: IFile = {
@@ -826,27 +807,11 @@ export class Keap implements INodeType {
const contactId = parseInt(this.getNodeParameter('contactId', i) as string, 10); const contactId = parseInt(this.getNodeParameter('contactId', i) as string, 10);
body.contact_id = contactId; body.contact_id = contactId;
} }
if (binaryData) { if (this.getNodeParameter('binaryData', i)) {
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i); const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i);
const binaryData = this.helpers.assertBinaryData(i, binaryPropertyName);
if (items[i].binary === undefined) { body.file_data = binaryData.data;
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!', { body.file_name = binaryData.fileName;
itemIndex: i,
});
}
const item = items[i].binary as IBinaryKeyData;
if (item[binaryPropertyName] === undefined) {
throw new NodeOperationError(
this.getNode(),
`Item has no binary property called "${binaryPropertyName}"`,
{ itemIndex: i },
);
}
body.file_data = item[binaryPropertyName].data;
body.file_name = item[binaryPropertyName].fileName;
} else { } else {
const fileName = this.getNodeParameter('fileName', i) as string; const fileName = this.getNodeParameter('fileName', i) as string;
const fileData = this.getNodeParameter('fileData', i) as string; const fileData = this.getNodeParameter('fileData', i) as string;

View File

@@ -1,13 +1,10 @@
import type { IExecuteFunctions } from 'n8n-core';
import type { import type {
IBinaryKeyData,
IDataObject, IDataObject,
IExecuteFunctions,
INodeExecutionData, INodeExecutionData,
INodeType, INodeType,
INodeTypeDescription, INodeTypeDescription,
} from 'n8n-workflow'; } from 'n8n-workflow';
import { NodeOperationError } from 'n8n-workflow';
import { lineApiRequest } from './GenericFunctions'; import { lineApiRequest } from './GenericFunctions';
@@ -97,27 +94,9 @@ export class Line implements INodeType {
const image = (body.imageUi as IDataObject).imageValue as IDataObject; const image = (body.imageUi as IDataObject).imageValue as IDataObject;
if (image && image.binaryData === true) { if (image && image.binaryData === true) {
if (items[i].binary === undefined) { const binaryProperty = image.binaryProperty as string;
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!', { const binaryData = this.helpers.assertBinaryData(i, binaryProperty);
itemIndex: i, const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryProperty);
});
}
//@ts-ignore
if (items[i].binary[image.binaryProperty] === undefined) {
throw new NodeOperationError(
this.getNode(),
`Item has no binary property called "${image.binaryProperty}"`,
{ itemIndex: i },
);
}
const binaryData = (items[i].binary as IBinaryKeyData)[
image.binaryProperty as string
];
const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(
i,
image.binaryProperty as string,
);
body.imageFile = { body.imageFile = {
value: binaryDataBuffer, value: binaryDataBuffer,

View File

@@ -1,13 +1,12 @@
import type { IExecuteFunctions } from 'n8n-core';
import type { import type {
IDataObject, IDataObject,
IExecuteFunctions,
ILoadOptionsFunctions, ILoadOptionsFunctions,
INodeExecutionData, INodeExecutionData,
INodePropertyOptions, INodePropertyOptions,
INodeType, INodeType,
INodeTypeDescription, INodeTypeDescription,
} from 'n8n-workflow'; } from 'n8n-workflow';
import { NodeOperationError } from 'n8n-workflow';
import { linkedInApiRequest } from './GenericFunctions'; import { linkedInApiRequest } from './GenericFunctions';
import { postFields, postOperations } from './PostDescription'; import { postFields, postOperations } from './PostDescription';
@@ -137,27 +136,11 @@ export class LinkedIn implements INodeType {
].uploadUrl as string; ].uploadUrl as string;
const asset = registerObject.value.asset as string; const asset = registerObject.value.asset as string;
// Prepare binary file upload const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i);
const item = items[i]; this.helpers.assertBinaryData(i, binaryPropertyName);
if (item.binary === undefined) {
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!', {
itemIndex: i,
});
}
const propertyNameUpload = this.getNodeParameter('binaryPropertyName', i);
if (item.binary[propertyNameUpload] === undefined) {
throw new NodeOperationError(
this.getNode(),
`Item has no binary property called "${propertyNameUpload}"`,
{ itemIndex: i },
);
}
// Buffer binary data // Buffer binary data
const buffer = await this.helpers.getBinaryDataBuffer(i, propertyNameUpload); const buffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName);
// Upload image // Upload image
await linkedInApiRequest.call(this, 'POST', uploadUrl, buffer, true); await linkedInApiRequest.call(this, 'POST', uploadUrl, buffer, true);

View File

@@ -148,9 +148,7 @@ export class Mailgun implements INodeType {
}); });
for (const propertyName of attachmentProperties) { for (const propertyName of attachmentProperties) {
if (!item.binary.hasOwnProperty(propertyName)) { const binaryData = this.helpers.assertBinaryData(itemIndex, propertyName);
continue;
}
const binaryDataBuffer = await this.helpers.getBinaryDataBuffer( const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(
itemIndex, itemIndex,
propertyName, propertyName,
@@ -158,7 +156,7 @@ export class Mailgun implements INodeType {
attachments.push({ attachments.push({
value: binaryDataBuffer, value: binaryDataBuffer,
options: { options: {
filename: item.binary[propertyName].fileName || 'unknown', filename: binaryData.fileName || 'unknown',
}, },
}); });
} }

View File

@@ -1,10 +1,14 @@
import type { OptionsWithUri } from 'request'; import type { OptionsWithUri } from 'request';
import type { IDataObject, JsonObject } from 'n8n-workflow'; import type {
IDataObject,
IExecuteFunctions,
IExecuteSingleFunctions,
ILoadOptionsFunctions,
JsonObject,
} from 'n8n-workflow';
import { NodeApiError, NodeOperationError } from 'n8n-workflow'; import { NodeApiError, NodeOperationError } from 'n8n-workflow';
import type { IExecuteFunctions, IExecuteSingleFunctions, ILoadOptionsFunctions } from 'n8n-core';
import { v4 as uuid } from 'uuid'; import { v4 as uuid } from 'uuid';
export async function matrixApiRequest( export async function matrixApiRequest(
@@ -190,25 +194,11 @@ export async function handleMatrixCall(
const qs: IDataObject = {}; const qs: IDataObject = {};
const headers: IDataObject = {}; const headers: IDataObject = {};
if ( const { fileName, mimeType } = this.helpers.assertBinaryData(index, binaryPropertyName);
item.binary === undefined ||
//@ts-ignore
item.binary[binaryPropertyName] === undefined
) {
throw new NodeOperationError(
this.getNode(),
`Item has no binary property called "${binaryPropertyName}"`,
);
}
// @ts-ignore
qs.filename = item.binary[binaryPropertyName].fileName;
//@ts-ignore
const filename = item.binary[binaryPropertyName].fileName;
body = await this.helpers.getBinaryDataBuffer(index, binaryPropertyName); body = await this.helpers.getBinaryDataBuffer(index, binaryPropertyName);
//@ts-ignore
headers['Content-Type'] = item.binary[binaryPropertyName].mimeType; qs.filename = fileName;
headers['Content-Type'] = mimeType;
headers.accept = 'application/json,text/*;q=0.99'; headers.accept = 'application/json,text/*;q=0.99';
const uploadRequestResult = await matrixApiRequest.call( const uploadRequestResult = await matrixApiRequest.call(
@@ -226,7 +216,7 @@ export async function handleMatrixCall(
body = { body = {
msgtype: `m.${mediaType}`, msgtype: `m.${mediaType}`,
body: filename, body: fileName,
url: uploadRequestResult.content_uri, url: uploadRequestResult.content_uri,
}; };
const messageId = uuid(); const messageId = uuid();

View File

@@ -1,8 +1,6 @@
import type { IExecuteFunctions } from 'n8n-core';
import type { import type {
IBinaryKeyData,
IDataObject, IDataObject,
IExecuteFunctions,
INodeExecutionData, INodeExecutionData,
INodeType, INodeType,
INodeTypeDescription, INodeTypeDescription,
@@ -197,22 +195,7 @@ export class MicrosoftOneDrive implements INodeType {
if (isBinaryData) { if (isBinaryData) {
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', 0); const binaryPropertyName = this.getNodeParameter('binaryPropertyName', 0);
const binaryData = this.helpers.assertBinaryData(i, binaryPropertyName);
if (items[i].binary === undefined) {
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!', {
itemIndex: i,
});
}
//@ts-ignore
if (items[i].binary[binaryPropertyName] === undefined) {
throw new NodeOperationError(
this.getNode(),
`Item has no binary property called "${binaryPropertyName}"`,
{ itemIndex: i },
);
}
const binaryData = (items[i].binary as IBinaryKeyData)[binaryPropertyName];
const body = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName); const body = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName);
let encodedFilename; let encodedFilename;

View File

@@ -4,7 +4,7 @@ import type { IExecuteFunctions, IExecuteSingleFunctions, ILoadOptionsFunctions
import { BINARY_ENCODING } from 'n8n-core'; import { BINARY_ENCODING } from 'n8n-core';
import type { IDataObject, INodeExecutionData, JsonObject } from 'n8n-workflow'; import type { IDataObject, INodeExecutionData, JsonObject } from 'n8n-workflow';
import { NodeApiError, NodeOperationError } from 'n8n-workflow'; import { NodeApiError } from 'n8n-workflow';
export async function microsoftApiRequest( export async function microsoftApiRequest(
this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions,
@@ -228,24 +228,8 @@ export async function binaryToAttachments(
) { ) {
return Promise.all( return Promise.all(
attachments.map(async (attachment) => { attachments.map(async (attachment) => {
const { binary } = items[i];
if (binary === undefined) {
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!', {
itemIndex: i,
});
}
const binaryPropertyName = attachment.binaryPropertyName as string; const binaryPropertyName = attachment.binaryPropertyName as string;
if (binary[binaryPropertyName] === undefined) { const binaryData = this.helpers.assertBinaryData(i, binaryPropertyName);
throw new NodeOperationError(
this.getNode(),
`Item has no binary property called "${binaryPropertyName}"`,
{ itemIndex: i },
);
}
const binaryData = binary[binaryPropertyName];
const dataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName); const dataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName);
return { return {
'@odata.type': '#microsoft.graph.fileAttachment', '@odata.type': '#microsoft.graph.fileAttachment',

View File

@@ -1,8 +1,6 @@
import type { IExecuteFunctions } from 'n8n-core';
import type { import type {
IBinaryKeyData,
IDataObject, IDataObject,
IExecuteFunctions,
ILoadOptionsFunctions, ILoadOptionsFunctions,
INodeExecutionData, INodeExecutionData,
INodePropertyOptions, INodePropertyOptions,
@@ -643,19 +641,7 @@ export class MicrosoftOutlook implements INodeType {
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', 0); const binaryPropertyName = this.getNodeParameter('binaryPropertyName', 0);
const additionalFields = this.getNodeParameter('additionalFields', i); const additionalFields = this.getNodeParameter('additionalFields', i);
if (items[i].binary === undefined) { const binaryData = this.helpers.assertBinaryData(i, binaryPropertyName);
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!');
}
//@ts-ignore
if (items[i].binary[binaryPropertyName] === undefined) {
throw new NodeOperationError(
this.getNode(),
`Item has no binary property called "${binaryPropertyName}"`,
{ itemIndex: i },
);
}
const binaryData = (items[i].binary as IBinaryKeyData)[binaryPropertyName];
const dataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName); const dataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName);
const fileName = const fileName =

View File

@@ -1,8 +1,6 @@
import type { IExecuteFunctions } from 'n8n-core';
import type { import type {
IBinaryKeyData,
IDataObject, IDataObject,
IExecuteFunctions,
INodeExecutionData, INodeExecutionData,
INodeType, INodeType,
INodeTypeDescription, INodeTypeDescription,
@@ -160,27 +158,12 @@ export class Mindee implements INodeType {
try { try {
if (resource === 'receipt') { if (resource === 'receipt') {
if (operation === 'predict') { if (operation === 'predict') {
const rawData = this.getNodeParameter('rawData', i);
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i); const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i);
const rawData = this.getNodeParameter('rawData', i); const binaryData = this.helpers.assertBinaryData(i, binaryPropertyName);
if (items[i].binary === undefined) {
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!', {
itemIndex: i,
});
}
const item = items[i].binary as IBinaryKeyData;
const binaryData = item[binaryPropertyName];
const dataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName); const dataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName);
if (binaryData === undefined) {
throw new NodeOperationError(
this.getNode(),
`Item has no binary property called "${binaryPropertyName}"`,
);
}
if (version === 1) { if (version === 1) {
responseData = await mindeeApiRequest.call( responseData = await mindeeApiRequest.call(
this, this,
@@ -233,27 +216,12 @@ export class Mindee implements INodeType {
if (resource === 'invoice') { if (resource === 'invoice') {
if (operation === 'predict') { if (operation === 'predict') {
const rawData = this.getNodeParameter('rawData', i);
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i); const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i);
const rawData = this.getNodeParameter('rawData', i); const binaryData = this.helpers.assertBinaryData(i, binaryPropertyName);
if (items[i].binary === undefined) {
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!', {
itemIndex: i,
});
}
const item = items[i].binary as IBinaryKeyData;
const binaryData = item[binaryPropertyName];
const dataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName); const dataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName);
if (binaryData === undefined) {
throw new NodeOperationError(
this.getNode(),
`Item has no binary property called "${binaryPropertyName}"`,
);
}
if (version === 1) { if (version === 1) {
endpoint = '/invoices/v1/predict'; endpoint = '/invoices/v1/predict';
responseData = await mindeeApiRequest.call( responseData = await mindeeApiRequest.call(

View File

@@ -1,8 +1,7 @@
import type { IExecuteFunctions } from 'n8n-core';
import type { import type {
IBinaryKeyData, IBinaryKeyData,
IDataObject, IDataObject,
IExecuteFunctions,
INodeExecutionData, INodeExecutionData,
INodeType, INodeType,
INodeTypeDescription, INodeTypeDescription,
@@ -902,26 +901,9 @@ export class NextCloud implements INodeType {
endpoint = this.getNodeParameter('path', i) as string; endpoint = this.getNodeParameter('path', i) as string;
if (this.getNodeParameter('binaryDataUpload', i) === true) { if (this.getNodeParameter('binaryDataUpload', i) === true) {
// Is binary file to upload const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i);
const item = items[i]; this.helpers.assertBinaryData(i, binaryPropertyName);
body = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName);
if (item.binary === undefined) {
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!', {
itemIndex: i,
});
}
const propertyNameUpload = this.getNodeParameter('binaryPropertyName', i);
if (item.binary[propertyNameUpload] === undefined) {
throw new NodeOperationError(
this.getNode(),
`Item has no binary property called "${propertyNameUpload}"`,
{ itemIndex: i },
);
}
body = await this.helpers.getBinaryDataBuffer(i, propertyNameUpload);
} else { } else {
// Is text file // Is text file
body = this.getNodeParameter('fileContent', i) as string; body = this.getNodeParameter('fileContent', i) as string;

View File

@@ -1,8 +1,7 @@
/* eslint-disable n8n-nodes-base/node-filename-against-convention */ /* eslint-disable n8n-nodes-base/node-filename-against-convention */
import type { IExecuteFunctions } from 'n8n-core';
import type { import type {
IDataObject, IDataObject,
IExecuteFunctions,
ILoadOptionsFunctions, ILoadOptionsFunctions,
INodeExecutionData, INodeExecutionData,
INodeType, INodeType,
@@ -265,20 +264,8 @@ export class NocoDB implements INodeType {
if (!field.binaryData) { if (!field.binaryData) {
newItem[field.fieldName] = field.fieldValue; newItem[field.fieldName] = field.fieldValue;
} else if (field.binaryProperty) { } else if (field.binaryProperty) {
if (!items[i].binary) {
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!', {
itemIndex: i,
});
}
const binaryPropertyName = field.binaryProperty; const binaryPropertyName = field.binaryProperty;
if (binaryPropertyName && !items[i].binary![binaryPropertyName]) { const binaryData = this.helpers.assertBinaryData(i, binaryPropertyName);
throw new NodeOperationError(
this.getNode(),
`Item has no binary property called "${binaryPropertyName}"`,
{ itemIndex: i },
);
}
const binaryData = items[i].binary![binaryPropertyName];
const dataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName); const dataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName);
const formData = { const formData = {
@@ -581,20 +568,8 @@ export class NocoDB implements INodeType {
if (!field.binaryData) { if (!field.binaryData) {
newItem[field.fieldName] = field.fieldValue; newItem[field.fieldName] = field.fieldValue;
} else if (field.binaryProperty) { } else if (field.binaryProperty) {
if (!items[i].binary) {
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!', {
itemIndex: i,
});
}
const binaryPropertyName = field.binaryProperty; const binaryPropertyName = field.binaryProperty;
if (binaryPropertyName && !items[i].binary![binaryPropertyName]) { const binaryData = this.helpers.assertBinaryData(i, binaryPropertyName);
throw new NodeOperationError(
this.getNode(),
`Item has no binary property called "${binaryPropertyName}"`,
{ itemIndex: i },
);
}
const binaryData = items[i].binary![binaryPropertyName];
const dataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName); const dataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName);
const formData = { const formData = {

View File

@@ -1,6 +1,7 @@
import type { IExecuteFunctions, ILoadOptionsFunctions } from 'n8n-core';
import type { import type {
IDataObject, IDataObject,
IExecuteFunctions,
ILoadOptionsFunctions,
INodeExecutionData, INodeExecutionData,
INodePropertyOptions, INodePropertyOptions,
INodeType, INodeType,
@@ -4337,31 +4338,15 @@ export class Pipedrive implements INodeType {
requestMethod = 'POST'; requestMethod = 'POST';
endpoint = '/files'; endpoint = '/files';
const item = items[i];
if (item.binary === undefined) {
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!', {
itemIndex: i,
});
}
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i); const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i);
const binaryData = this.helpers.assertBinaryData(i, binaryPropertyName);
if (item.binary[binaryPropertyName] === undefined) {
throw new NodeOperationError(
this.getNode(),
`Item has no binary property called "${binaryPropertyName}"`,
{ itemIndex: i },
);
}
const fileBufferData = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName); const fileBufferData = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName);
formData.file = { formData.file = {
value: fileBufferData, value: fileBufferData,
options: { options: {
contentType: item.binary[binaryPropertyName].mimeType, contentType: binaryData.mimeType,
filename: item.binary[binaryPropertyName].fileName, filename: binaryData.fileName,
}, },
}; };

View File

@@ -1,15 +1,12 @@
import type { IExecuteFunctions } from 'n8n-core';
import type { import type {
IBinaryKeyData,
IDataObject, IDataObject,
IExecuteFunctions,
ILoadOptionsFunctions, ILoadOptionsFunctions,
INodeExecutionData, INodeExecutionData,
INodePropertyOptions, INodePropertyOptions,
INodeType, INodeType,
INodeTypeDescription, INodeTypeDescription,
} from 'n8n-workflow'; } from 'n8n-workflow';
import { NodeOperationError } from 'n8n-workflow';
import { pushbulletApiRequest, pushbulletApiRequestAllItems } from './GenericFunctions'; import { pushbulletApiRequest, pushbulletApiRequestAllItems } from './GenericFunctions';
@@ -408,20 +405,7 @@ export class Pushbullet implements INodeType {
if (type === 'file') { if (type === 'file') {
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', 0); const binaryPropertyName = this.getNodeParameter('binaryPropertyName', 0);
const binaryData = this.helpers.assertBinaryData(i, binaryPropertyName);
if (items[i].binary === undefined) {
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!');
}
//@ts-ignore
if (items[i].binary[binaryPropertyName] === undefined) {
throw new NodeOperationError(
this.getNode(),
`Item has no binary property called "${binaryPropertyName}"`,
{ itemIndex: i },
);
}
const binaryData = (items[i].binary as IBinaryKeyData)[binaryPropertyName];
const dataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName); const dataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName);
//create upload url //create upload url

View File

@@ -1,15 +1,12 @@
import type { IExecuteFunctions } from 'n8n-core';
import type { import type {
IBinaryKeyData,
IDataObject, IDataObject,
IExecuteFunctions,
ILoadOptionsFunctions, ILoadOptionsFunctions,
INodeExecutionData, INodeExecutionData,
INodePropertyOptions, INodePropertyOptions,
INodeType, INodeType,
INodeTypeDescription, INodeTypeDescription,
} from 'n8n-workflow'; } from 'n8n-workflow';
import { NodeOperationError } from 'n8n-workflow';
import { pushoverApiRequest } from './GenericFunctions'; import { pushoverApiRequest } from './GenericFunctions';
@@ -339,25 +336,7 @@ export class Pushover implements INodeType {
if (attachment) { if (attachment) {
const binaryPropertyName = attachment.binaryPropertyName as string; const binaryPropertyName = attachment.binaryPropertyName as string;
const binaryData = this.helpers.assertBinaryData(i, binaryPropertyName);
if (items[i].binary === undefined) {
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!', {
itemIndex: i,
});
}
const item = items[i].binary as IBinaryKeyData;
const binaryData = item[binaryPropertyName];
if (binaryData === undefined) {
throw new NodeOperationError(
this.getNode(),
`Item has no binary property called "${binaryPropertyName}"`,
{ itemIndex: i },
);
}
const dataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName); const dataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName);
body.attachment = { body.attachment = {

View File

@@ -315,23 +315,8 @@ export class Raindrop implements INodeType {
// cover-specific endpoint // cover-specific endpoint
if (updateFields.cover) { if (updateFields.cover) {
if (!items[i].binary) {
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!', {
itemIndex: i,
});
}
if (!updateFields.cover) {
throw new NodeOperationError(
this.getNode(),
'Please enter a binary property to upload a cover image.',
{ itemIndex: i },
);
}
const binaryPropertyName = updateFields.cover as string; const binaryPropertyName = updateFields.cover as string;
const binaryData = this.helpers.assertBinaryData(i, binaryPropertyName);
const binaryData = items[i].binary![binaryPropertyName];
const dataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName); const dataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName);
const formData = { const formData = {

View File

@@ -52,11 +52,14 @@ export class ReadPDF implements INodeType {
item.binary = {}; item.binary = {};
} }
const binaryData = await this.helpers.getBinaryDataBuffer(itemIndex, binaryPropertyName); const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(
itemIndex,
binaryPropertyName,
);
returnData.push({ returnData.push({
binary: item.binary, binary: item.binary,
json: (await pdf(binaryData)) as unknown as IDataObject, json: (await pdf(binaryDataBuffer)) as unknown as IDataObject,
}); });
} catch (error) { } catch (error) {
if (this.continueOnFail()) { if (this.continueOnFail()) {

View File

@@ -1,7 +1,6 @@
import type { IExecuteFunctions } from 'n8n-core';
import type { import type {
IDataObject, IDataObject,
IExecuteFunctions,
IN8nHttpFullResponse, IN8nHttpFullResponse,
IN8nHttpResponse, IN8nHttpResponse,
INodeExecutionData, INodeExecutionData,
@@ -215,7 +214,7 @@ export class RespondToWebhook implements INodeType {
} else if (respondWith === 'text') { } else if (respondWith === 'text') {
responseBody = this.getNodeParameter('responseBody', 0) as string; responseBody = this.getNodeParameter('responseBody', 0) as string;
} else if (respondWith === 'binary') { } else if (respondWith === 'binary') {
const item = this.getInputData()[0]; const item = items[0];
if (item.binary === undefined) { if (item.binary === undefined) {
throw new NodeOperationError(this.getNode(), 'No binary data exists on the first item!'); throw new NodeOperationError(this.getNode(), 'No binary data exists on the first item!');
@@ -235,19 +234,12 @@ export class RespondToWebhook implements INodeType {
responseBinaryPropertyName = binaryKeys[0]; responseBinaryPropertyName = binaryKeys[0];
} }
const binaryData = item.binary[responseBinaryPropertyName]; const binaryData = this.helpers.assertBinaryData(0, responseBinaryPropertyName);
const binaryDataBuffer = await this.helpers.getBinaryDataBuffer( const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(
0, 0,
responseBinaryPropertyName, responseBinaryPropertyName,
); );
if (binaryData === undefined) {
throw new NodeOperationError(
this.getNode(),
`Item has no binary property called "${responseBinaryPropertyName}"`,
);
}
if (!headers['content-type']) { if (!headers['content-type']) {
headers['content-type'] = binaryData.mimeType; headers['content-type'] = binaryData.mimeType;
} }

View File

@@ -4,11 +4,9 @@ import { createHash } from 'crypto';
import { Builder } from 'xml2js'; import { Builder } from 'xml2js';
import type { IExecuteFunctions } from 'n8n-core';
import type { import type {
IBinaryKeyData,
IDataObject, IDataObject,
IExecuteFunctions,
INodeExecutionData, INodeExecutionData,
INodeType, INodeType,
INodeTypeDescription, INodeTypeDescription,
@@ -837,22 +835,7 @@ export class S3 implements INodeType {
if (isBinaryData) { if (isBinaryData) {
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', 0); const binaryPropertyName = this.getNodeParameter('binaryPropertyName', 0);
const binaryData = this.helpers.assertBinaryData(i, binaryPropertyName);
if (items[i].binary === undefined) {
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!', {
itemIndex: i,
});
}
if ((items[i].binary as IBinaryKeyData)[binaryPropertyName] === undefined) {
throw new NodeOperationError(
this.getNode(),
`Item has no binary property called "${binaryPropertyName}"`,
{ itemIndex: i },
);
}
const binaryData = (items[i].binary as IBinaryKeyData)[binaryPropertyName];
body = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName); body = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName);
headers['Content-Type'] = binaryData.mimeType; headers['Content-Type'] = binaryData.mimeType;

View File

@@ -1834,7 +1834,6 @@ export class Salesforce implements INodeType {
const title = this.getNodeParameter('title', i) as string; const title = this.getNodeParameter('title', i) as string;
const additionalFields = this.getNodeParameter('additionalFields', i); const additionalFields = this.getNodeParameter('additionalFields', i);
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i); const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i);
let data;
const body: { entity_content: { [key: string]: string } } = { const body: { entity_content: { [key: string]: string } } = {
entity_content: { entity_content: {
Title: title, Title: title,
@@ -1848,14 +1847,13 @@ export class Salesforce implements INodeType {
body.entity_content.FirstPublishLocationId = body.entity_content.FirstPublishLocationId =
additionalFields.linkToObjectId as string; additionalFields.linkToObjectId as string;
} }
if (items[i].binary && items[i].binary![binaryPropertyName]) { const binaryData = this.helpers.assertBinaryData(i, binaryPropertyName);
const binaryData = items[i].binary![binaryPropertyName];
const dataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName); const dataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName);
body.entity_content.PathOnClient = `${title}.${ body.entity_content.PathOnClient = `${title}.${
additionalFields.fileExtension || binaryData.fileExtension additionalFields.fileExtension || binaryData.fileExtension
}`; }`;
data = { const data = {
entity_content: { entity_content: {
value: JSON.stringify(body.entity_content), value: JSON.stringify(body.entity_content),
options: { options: {
@@ -1869,13 +1867,6 @@ export class Salesforce implements INodeType {
}, },
}, },
}; };
} else {
throw new NodeOperationError(
this.getNode(),
`The property ${binaryPropertyName} does not exist`,
{ itemIndex: i },
);
}
responseData = await salesforceApiRequest.call( responseData = await salesforceApiRequest.call(
this, this,
'POST', 'POST',

View File

@@ -1,14 +1,12 @@
import type { IExecuteFunctions } from 'n8n-core';
import type { import type {
IDataObject, IDataObject,
IExecuteFunctions,
ILoadOptionsFunctions, ILoadOptionsFunctions,
INodeExecutionData, INodeExecutionData,
INodePropertyOptions, INodePropertyOptions,
INodeType, INodeType,
INodeTypeDescription, INodeTypeDescription,
} from 'n8n-workflow'; } from 'n8n-workflow';
import { NodeOperationError } from 'n8n-workflow';
import { listFields, listOperations } from './ListDescription'; import { listFields, listOperations } from './ListDescription';
@@ -588,22 +586,13 @@ export class SendGrid implements INodeType {
const binaryProperties = attachments.split(',').map((p) => p.trim()); const binaryProperties = attachments.split(',').map((p) => p.trim());
for (const property of binaryProperties) { for (const property of binaryProperties) {
if (!items[i].binary?.hasOwnProperty(property)) { const binaryData = this.helpers.assertBinaryData(i, property);
throw new NodeOperationError(
this.getNode(),
`The binary property ${property} does not exist`,
{ itemIndex: i },
);
}
const binaryProperty = items[i].binary![property];
const dataBuffer = await this.helpers.getBinaryDataBuffer(i, property); const dataBuffer = await this.helpers.getBinaryDataBuffer(i, property);
attachmentsToSend.push({ attachmentsToSend.push({
content: dataBuffer.toString('base64'), content: dataBuffer.toString('base64'),
filename: binaryProperty.fileName || 'unknown', filename: binaryData.fileName || 'unknown',
type: binaryProperty.mimeType, type: binaryData.mimeType,
}); });
} }

View File

@@ -84,20 +84,8 @@ export namespace SendInBlueNode {
const { binaryPropertyName } = dataPropertyList; const { binaryPropertyName } = dataPropertyList;
const dataMappingList = (binaryPropertyName as string).split(','); const dataMappingList = (binaryPropertyName as string).split(',');
for (const attachmentDataName of dataMappingList) { for (const attachmentDataName of dataMappingList) {
const binaryPropertyAttachmentName = attachmentDataName; const binaryData = this.helpers.assertBinaryData(attachmentDataName);
const bufferFromIncomingData = await this.helpers.getBinaryDataBuffer(attachmentDataName);
const item = this.getInputData();
if (item.binary![binaryPropertyAttachmentName] === undefined) {
throw new NodeOperationError(
this.getNode(),
`Item has no binary property called "${binaryPropertyName}"`,
);
}
const bufferFromIncomingData = await this.helpers.getBinaryDataBuffer(
binaryPropertyAttachmentName,
);
const { const {
data: content, data: content,
@@ -111,7 +99,7 @@ export namespace SendInBlueNode {
itemIndex, itemIndex,
mimeType, mimeType,
fileExtension!, fileExtension!,
fileName || item.binary!.data.fileName!, fileName ?? binaryData.fileName!,
); );
attachment.push({ content, name }); attachment.push({ content, name });

View File

@@ -1,8 +1,7 @@
import type { IExecuteFunctions, ILoadOptionsFunctions } from 'n8n-core';
import type { import type {
IBinaryData,
IDataObject, IDataObject,
IExecuteFunctions,
ILoadOptionsFunctions,
INodeExecutionData, INodeExecutionData,
INodePropertyOptions, INodePropertyOptions,
INodeType, INodeType,
@@ -605,17 +604,7 @@ export class ServiceNow implements INodeType {
const inputDataFieldName = this.getNodeParameter('inputDataFieldName', i) as string; const inputDataFieldName = this.getNodeParameter('inputDataFieldName', i) as string;
const options = this.getNodeParameter('options', i); const options = this.getNodeParameter('options', i);
let binaryData: IBinaryData; const binaryData = this.helpers.assertBinaryData(i, inputDataFieldName);
if (items[i].binary && items[i].binary![inputDataFieldName]) {
binaryData = items[i].binary![inputDataFieldName];
} else {
throw new NodeOperationError(
this.getNode(),
`Item has no binary property called "${inputDataFieldName}"`,
{ itemIndex: i },
);
}
const headers: IDataObject = { const headers: IDataObject = {
'Content-Type': binaryData.mimeType, 'Content-Type': binaryData.mimeType,

View File

@@ -1,8 +1,6 @@
import type { IExecuteFunctions } from 'n8n-core';
import type { import type {
IBinaryKeyData,
IDataObject, IDataObject,
IExecuteFunctions,
INodeExecutionData, INodeExecutionData,
INodeType, INodeType,
INodeTypeDescription, INodeTypeDescription,
@@ -279,17 +277,16 @@ export class Signl4 implements INodeType {
// Attachments // Attachments
const attachments = additionalFields.attachmentsUi as IDataObject; const attachments = additionalFields.attachmentsUi as IDataObject;
if (attachments) { if (attachments?.attachmentsBinary) {
if (attachments.attachmentsBinary && items[i].binary) {
const propertyName = (attachments.attachmentsBinary as IDataObject) const propertyName = (attachments.attachmentsBinary as IDataObject)
.property as string; .property as string;
const binaryProperty = (items[i].binary as IBinaryKeyData)[propertyName]; const binaryData = this.helpers.assertBinaryData(i, propertyName);
if (binaryProperty) { if (binaryData) {
const supportedFileExtension = ['png', 'jpg', 'jpeg', 'bmp', 'gif', 'mp3', 'wav']; const supportedFileExtension = ['png', 'jpg', 'jpeg', 'bmp', 'gif', 'mp3', 'wav'];
if (!supportedFileExtension.includes(binaryProperty.fileExtension as string)) { if (!supportedFileExtension.includes(binaryData.fileExtension as string)) {
throw new NodeOperationError( throw new NodeOperationError(
this.getNode(), this.getNode(),
`Invalid extension, just ${supportedFileExtension.join(',')} are supported}`, `Invalid extension, just ${supportedFileExtension.join(',')} are supported}`,
@@ -301,17 +298,10 @@ export class Signl4 implements INodeType {
data.attachment = { data.attachment = {
value: binaryDataBuffer, value: binaryDataBuffer,
options: { options: {
filename: binaryProperty.fileName, filename: binaryData.fileName,
contentType: binaryProperty.mimeType, contentType: binaryData.mimeType,
}, },
}; };
} else {
throw new NodeOperationError(
this.getNode(),
`Binary property ${propertyName} does not exist on input`,
{ itemIndex: i },
);
}
} }
} }

View File

@@ -1,7 +1,6 @@
import type { IExecuteFunctions } from 'n8n-core';
import type { import type {
IDataObject, IDataObject,
IExecuteFunctions,
ILoadOptionsFunctions, ILoadOptionsFunctions,
INodeExecutionData, INodeExecutionData,
INodePropertyOptions, INodePropertyOptions,
@@ -1076,7 +1075,6 @@ export class SlackV1 implements INodeType {
//https://api.slack.com/methods/files.upload //https://api.slack.com/methods/files.upload
if (operation === 'upload') { if (operation === 'upload') {
const options = this.getNodeParameter('options', i); const options = this.getNodeParameter('options', i);
const binaryData = this.getNodeParameter('binaryData', i);
const body: IDataObject = {}; const body: IDataObject = {};
if (options.channelIds) { if (options.channelIds) {
body.channels = (options.channelIds as string[]).join(','); body.channels = (options.channelIds as string[]).join(',');
@@ -1093,31 +1091,18 @@ export class SlackV1 implements INodeType {
if (options.title) { if (options.title) {
body.title = options.title as string; body.title = options.title as string;
} }
if (binaryData) { if (this.getNodeParameter('binaryData', i)) {
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i); const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i);
if ( const binaryData = this.helpers.assertBinaryData(i, binaryPropertyName);
items[i].binary === undefined ||
//@ts-ignore
items[i].binary[binaryPropertyName] === undefined
) {
throw new NodeOperationError(
this.getNode(),
`Item has no binary property called "${binaryPropertyName}"`,
{ itemIndex: i },
);
}
const binaryDataBuffer = await this.helpers.getBinaryDataBuffer( const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(
i, i,
binaryPropertyName, binaryPropertyName,
); );
body.file = { body.file = {
//@ts-ignore
value: binaryDataBuffer, value: binaryDataBuffer,
options: { options: {
//@ts-ignore filename: binaryData.fileName,
filename: items[i].binary[binaryPropertyName].fileName, contentType: binaryData.mimeType,
//@ts-ignore
contentType: items[i].binary[binaryPropertyName].mimeType,
}, },
}; };
responseData = await slackApiRequest.call( responseData = await slackApiRequest.call(

View File

@@ -1,9 +1,9 @@
import type { IExecuteFunctions } from 'n8n-core';
import { BINARY_ENCODING } from 'n8n-core'; import { BINARY_ENCODING } from 'n8n-core';
import type { Readable } from 'stream'; import type { Readable } from 'stream';
import type { import type {
IDataObject, IDataObject,
IExecuteFunctions,
ILoadOptionsFunctions, ILoadOptionsFunctions,
INodeExecutionData, INodeExecutionData,
INodeListSearchItems, INodeListSearchItems,
@@ -1043,7 +1043,6 @@ export class SlackV2 implements INodeType {
//https://api.slack.com/methods/files.upload //https://api.slack.com/methods/files.upload
if (operation === 'upload') { if (operation === 'upload') {
const options = this.getNodeParameter('options', i); const options = this.getNodeParameter('options', i);
const binaryData = this.getNodeParameter('binaryData', i);
const body: IDataObject = {}; const body: IDataObject = {};
if (options.channelIds) { if (options.channelIds) {
body.channels = (options.channelIds as string[]).join(','); body.channels = (options.channelIds as string[]).join(',');
@@ -1060,34 +1059,21 @@ export class SlackV2 implements INodeType {
if (options.title) { if (options.title) {
body.title = options.title as string; body.title = options.title as string;
} }
if (binaryData) { if (this.getNodeParameter('binaryData', i)) {
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i); const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i);
if ( const binaryData = this.helpers.assertBinaryData(i, binaryPropertyName);
items[i].binary === undefined ||
//@ts-ignore
items[i].binary[binaryPropertyName] === undefined
) {
throw new NodeOperationError(
this.getNode(),
`Item has no binary property called "${binaryPropertyName}"`,
{ itemIndex: i },
);
}
let uploadData: Buffer | Readable; let uploadData: Buffer | Readable;
const itemBinaryData = items[i].binary![binaryPropertyName]; if (binaryData.id) {
if (itemBinaryData.id) { uploadData = this.helpers.getBinaryStream(binaryData.id);
uploadData = this.helpers.getBinaryStream(itemBinaryData.id);
} else { } else {
uploadData = Buffer.from(itemBinaryData.data, BINARY_ENCODING); uploadData = Buffer.from(binaryData.data, BINARY_ENCODING);
} }
body.file = { body.file = {
//@ts-ignore
value: uploadData, value: uploadData,
options: { options: {
//@ts-ignore filename: binaryData.fileName,
filename: itemBinaryData.fileName, contentType: binaryData.mimeType,
//@ts-ignore
contentType: itemBinaryData.mimeType,
}, },
}; };
responseData = await slackApiRequest.call( responseData = await slackApiRequest.call(

View File

@@ -1,7 +1,6 @@
import type { IExecuteFunctions } from 'n8n-core';
import type { import type {
IDataObject, IDataObject,
IExecuteFunctions,
INodeExecutionData, INodeExecutionData,
INodeType, INodeType,
INodeTypeDescription, INodeTypeDescription,
@@ -295,30 +294,22 @@ export class SpreadsheetFile implements INodeType {
if (operation === 'fromFile') { if (operation === 'fromFile') {
// Read data from spreadsheet file to workflow // Read data from spreadsheet file to workflow
let item: INodeExecutionData;
for (let i = 0; i < items.length; i++) { for (let i = 0; i < items.length; i++) {
try { try {
item = items[i];
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i); const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i);
const options = this.getNodeParameter('options', i, {}); const options = this.getNodeParameter('options', i, {});
if (item.binary === undefined || item.binary[binaryPropertyName] === undefined) { this.helpers.assertBinaryData(i, binaryPropertyName);
// Property did not get found on item
continue;
}
// Read the binary spreadsheet data // Read the binary spreadsheet data
const binaryData = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName); const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName);
let workbook; let workbook;
if (options.readAsString === true) { if (options.readAsString === true) {
workbook = xlsxRead(binaryData.toString(), { workbook = xlsxRead(binaryDataBuffer.toString(), {
type: 'string', type: 'string',
raw: options.rawData as boolean, raw: options.rawData as boolean,
}); });
} else { } else {
workbook = xlsxRead(binaryData, { raw: options.rawData as boolean }); workbook = xlsxRead(binaryDataBuffer, { raw: options.rawData as boolean });
} }
if (workbook.SheetNames.length === 0) { if (workbook.SheetNames.length === 0) {

View File

@@ -1,13 +1,12 @@
import type { IExecuteFunctions } from 'n8n-core';
import { BINARY_ENCODING } from 'n8n-core'; import { BINARY_ENCODING } from 'n8n-core';
import type { import type {
IDataObject, IDataObject,
IExecuteFunctions,
INodeExecutionData, INodeExecutionData,
INodeType, INodeType,
INodeTypeDescription, INodeTypeDescription,
} from 'n8n-workflow'; } from 'n8n-workflow';
import { NodeOperationError } from 'n8n-workflow';
import { rm, writeFile } from 'fs/promises'; import { rm, writeFile } from 'fs/promises';
@@ -341,25 +340,8 @@ export class Ssh implements INodeType {
const parameterPath = this.getNodeParameter('path', i) as string; const parameterPath = this.getNodeParameter('path', i) as string;
const fileName = this.getNodeParameter('options.fileName', i, '') as string; const fileName = this.getNodeParameter('options.fileName', i, '') as string;
const item = items[i]; const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i);
const binaryData = this.helpers.assertBinaryData(i, binaryPropertyName);
if (item.binary === undefined) {
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!', {
itemIndex: i,
});
}
const propertyNameUpload = this.getNodeParameter('binaryPropertyName', i);
const binaryData = item.binary[propertyNameUpload];
if (item.binary[propertyNameUpload] === undefined) {
throw new NodeOperationError(
this.getNode(),
`Item has no binary property called "${propertyNameUpload}"`,
{ itemIndex: i },
);
}
let uploadData: Buffer | Readable; let uploadData: Buffer | Readable;
if (binaryData.id) { if (binaryData.id) {

View File

@@ -1,8 +1,7 @@
/* eslint-disable @typescript-eslint/dot-notation */ /* eslint-disable @typescript-eslint/dot-notation */
import type { IExecuteFunctions } from 'n8n-core';
import type { import type {
IDataObject, IDataObject,
IExecuteFunctions,
ILoadOptionsFunctions, ILoadOptionsFunctions,
INodeExecutionData, INodeExecutionData,
INodeParameters, INodeParameters,
@@ -10,7 +9,6 @@ import type {
INodeType, INodeType,
INodeTypeDescription, INodeTypeDescription,
} from 'n8n-workflow'; } from 'n8n-workflow';
import { NodeOperationError } from 'n8n-workflow';
import { alertFields, alertOperations } from './descriptions/AlertDescription'; import { alertFields, alertOperations } from './descriptions/AlertDescription';
@@ -427,28 +425,8 @@ export class TheHive implements INodeType {
element.data = artifactvalue.data as string; element.data = artifactvalue.data as string;
if (artifactvalue.dataType === 'file') { if (artifactvalue.dataType === 'file') {
const item = items[i];
if (item.binary === undefined) {
throw new NodeOperationError(
this.getNode(),
'No binary data exists on item!',
{ itemIndex: i },
);
}
const binaryPropertyName = artifactvalue.binaryProperty as string; const binaryPropertyName = artifactvalue.binaryProperty as string;
const binaryData = this.helpers.assertBinaryData(i, binaryPropertyName);
if (item.binary[binaryPropertyName] === undefined) {
throw new NodeOperationError(
this.getNode(),
`Item has no binary property called "${binaryPropertyName}"`,
{ itemIndex: i },
);
}
const binaryData = item.binary[binaryPropertyName];
element.data = `${binaryData.fileName};${binaryData.mimeType};${binaryData.data}`; element.data = `${binaryData.fileName};${binaryData.mimeType};${binaryData.data}`;
} }
@@ -704,28 +682,8 @@ export class TheHive implements INodeType {
element.data = artifactvalue.data as string; element.data = artifactvalue.data as string;
if (artifactvalue.dataType === 'file') { if (artifactvalue.dataType === 'file') {
const item = items[i];
if (item.binary === undefined) {
throw new NodeOperationError(
this.getNode(),
'No binary data exists on item!',
{ itemIndex: i },
);
}
const binaryPropertyName = artifactvalue.binaryProperty as string; const binaryPropertyName = artifactvalue.binaryProperty as string;
const binaryData = this.helpers.assertBinaryData(i, binaryPropertyName);
if (item.binary[binaryPropertyName] === undefined) {
throw new NodeOperationError(
this.getNode(),
`Item has no binary property called "${binaryPropertyName}"`,
{ itemIndex: i },
);
}
const binaryData = item.binary[binaryPropertyName];
element.data = `${binaryData.fileName};${binaryData.mimeType};${binaryData.data}`; element.data = `${binaryData.fileName};${binaryData.mimeType};${binaryData.data}`;
} }
@@ -905,25 +863,8 @@ export class TheHive implements INodeType {
let options: IDataObject = {}; let options: IDataObject = {};
if (body.dataType === 'file') { if (body.dataType === 'file') {
const item = items[i];
if (item.binary === undefined) {
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!', {
itemIndex: i,
});
}
const binaryPropertyName = this.getNodeParameter('binaryProperty', i); const binaryPropertyName = this.getNodeParameter('binaryProperty', i);
const binaryData = this.helpers.assertBinaryData(i, binaryPropertyName);
if (item.binary[binaryPropertyName] === undefined) {
throw new NodeOperationError(
this.getNode(),
`Item has no binary property called "${binaryPropertyName}"`,
{ itemIndex: i },
);
}
const binaryData = item.binary[binaryPropertyName];
const dataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName); const dataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName);
options = { options = {
@@ -1765,25 +1706,8 @@ export class TheHive implements INodeType {
.attachmentValues as IDataObject; .attachmentValues as IDataObject;
if (attachmentValues) { if (attachmentValues) {
const item = items[i];
if (item.binary === undefined) {
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!', {
itemIndex: i,
});
}
const binaryPropertyName = attachmentValues.binaryProperty as string; const binaryPropertyName = attachmentValues.binaryProperty as string;
const binaryData = this.helpers.assertBinaryData(i, binaryPropertyName);
if (item.binary[binaryPropertyName] === undefined) {
throw new NodeOperationError(
this.getNode(),
`Item has no binary property called "${binaryPropertyName}"`,
{ itemIndex: i },
);
}
const binaryData = item.binary[binaryPropertyName];
const dataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName); const dataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName);
options = { options = {

View File

@@ -1,15 +1,12 @@
import type { IExecuteFunctions } from 'n8n-core';
import type { import type {
IBinaryKeyData,
IDataObject, IDataObject,
IExecuteFunctions,
ILoadOptionsFunctions, ILoadOptionsFunctions,
INodeExecutionData, INodeExecutionData,
INodePropertyOptions, INodePropertyOptions,
INodeType, INodeType,
INodeTypeDescription, INodeTypeDescription,
} from 'n8n-workflow'; } from 'n8n-workflow';
import { NodeOperationError } from 'n8n-workflow';
import { twistApiRequest } from './GenericFunctions'; import { twistApiRequest } from './GenericFunctions';
@@ -254,18 +251,7 @@ export class Twist implements INodeType {
const attachments: IDataObject[] = []; const attachments: IDataObject[] = [];
for (const binaryProperty of binaryProperties) { for (const binaryProperty of binaryProperties) {
const item = items[i].binary as IBinaryKeyData; const binaryData = this.helpers.assertBinaryData(i, binaryProperty);
const binaryData = item[binaryProperty];
if (binaryData === undefined) {
throw new NodeOperationError(
this.getNode(),
`Item has no binary property called "${binaryProperty}"`,
{ itemIndex: i },
);
}
const dataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryProperty); const dataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryProperty);
attachments.push( attachments.push(
@@ -363,18 +349,7 @@ export class Twist implements INodeType {
const attachments: IDataObject[] = []; const attachments: IDataObject[] = [];
for (const binaryProperty of binaryProperties) { for (const binaryProperty of binaryProperties) {
const item = items[i].binary as IBinaryKeyData; const binaryData = this.helpers.assertBinaryData(i, binaryProperty);
const binaryData = item[binaryProperty];
if (binaryData === undefined) {
throw new NodeOperationError(
this.getNode(),
`Item has no binary property called "${binaryProperty}"`,
{ itemIndex: i },
);
}
const dataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryProperty); const dataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryProperty);
attachments.push( attachments.push(
@@ -442,18 +417,7 @@ export class Twist implements INodeType {
const attachments: IDataObject[] = []; const attachments: IDataObject[] = [];
for (const binaryProperty of binaryProperties) { for (const binaryProperty of binaryProperties) {
const item = items[i].binary as IBinaryKeyData; const binaryData = this.helpers.assertBinaryData(i, binaryProperty);
const binaryData = item[binaryProperty];
if (binaryData === undefined) {
throw new NodeOperationError(
this.getNode(),
`Item has no binary property called "${binaryProperty}"`,
{ itemIndex: i },
);
}
const dataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryProperty); const dataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryProperty);
attachments.push( attachments.push(
@@ -567,18 +531,7 @@ export class Twist implements INodeType {
const attachments: IDataObject[] = []; const attachments: IDataObject[] = [];
for (const binaryProperty of binaryProperties) { for (const binaryProperty of binaryProperties) {
const item = items[i].binary as IBinaryKeyData; const binaryData = this.helpers.assertBinaryData(i, binaryProperty);
const binaryData = item[binaryProperty];
if (binaryData === undefined) {
throw new NodeOperationError(
this.getNode(),
`Item has no binary property called "${binaryProperty}"`,
{ itemIndex: i },
);
}
const dataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryProperty); const dataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryProperty);
attachments.push( attachments.push(
@@ -651,18 +604,7 @@ export class Twist implements INodeType {
const attachments: IDataObject[] = []; const attachments: IDataObject[] = [];
for (const binaryProperty of binaryProperties) { for (const binaryProperty of binaryProperties) {
const item = items[i].binary as IBinaryKeyData; const binaryData = this.helpers.assertBinaryData(i, binaryProperty);
const binaryData = item[binaryProperty];
if (binaryData === undefined) {
throw new NodeOperationError(
this.getNode(),
`Item has no binary property called "${binaryProperty}"`,
{ itemIndex: i },
);
}
const dataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryProperty); const dataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryProperty);
attachments.push( attachments.push(
@@ -759,18 +701,7 @@ export class Twist implements INodeType {
const attachments: IDataObject[] = []; const attachments: IDataObject[] = [];
for (const binaryProperty of binaryProperties) { for (const binaryProperty of binaryProperties) {
const item = items[i].binary as IBinaryKeyData; const binaryData = this.helpers.assertBinaryData(i, binaryProperty);
const binaryData = item[binaryProperty];
if (binaryData === undefined) {
throw new NodeOperationError(
this.getNode(),
`Item has no binary property called "${binaryProperty}"`,
{ itemIndex: i },
);
}
const dataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryProperty); const dataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryProperty);
attachments.push( attachments.push(

View File

@@ -1,13 +1,13 @@
import type { OptionsWithUrl } from 'request'; import type { OptionsWithUrl } from 'request';
import type { import type {
IDataObject,
IExecuteFunctions, IExecuteFunctions,
IExecuteSingleFunctions, IExecuteSingleFunctions,
IHookFunctions, IHookFunctions,
ILoadOptionsFunctions, ILoadOptionsFunctions,
} from 'n8n-core'; JsonObject,
} from 'n8n-workflow';
import type { IBinaryKeyData, IDataObject, INodeExecutionData, JsonObject } from 'n8n-workflow';
import { NodeApiError, NodeOperationError, sleep } from 'n8n-workflow'; import { NodeApiError, NodeOperationError, sleep } from 'n8n-workflow';
export async function twitterApiRequest( export async function twitterApiRequest(
@@ -80,7 +80,6 @@ export function chunks(buffer: Buffer, chunkSize: number) {
export async function uploadAttachments( export async function uploadAttachments(
this: IExecuteFunctions, this: IExecuteFunctions,
binaryProperties: string[], binaryProperties: string[],
items: INodeExecutionData[],
i: number, i: number,
) { ) {
const uploadUri = 'https://upload.twitter.com/1.1/media/upload.json'; const uploadUri = 'https://upload.twitter.com/1.1/media/upload.json';
@@ -88,27 +87,14 @@ export async function uploadAttachments(
const media: IDataObject[] = []; const media: IDataObject[] = [];
for (const binaryPropertyName of binaryProperties) { for (const binaryPropertyName of binaryProperties) {
const binaryData = items[i].binary as IBinaryKeyData;
if (binaryData === undefined) {
throw new NodeOperationError(
this.getNode(),
'No binary data set. So file can not be written!',
{ itemIndex: i },
);
}
if (!binaryData[binaryPropertyName]) {
continue;
}
let attachmentBody = {}; let attachmentBody = {};
let response: IDataObject = {}; let response: IDataObject = {};
const binaryData = this.helpers.assertBinaryData(i, binaryPropertyName);
const dataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName); const dataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName);
const isAnimatedWebp = dataBuffer.toString().indexOf('ANMF') !== -1;
const isImage = binaryData[binaryPropertyName].mimeType.includes('image'); const isAnimatedWebp = dataBuffer.toString().indexOf('ANMF') !== -1;
const isImage = binaryData.mimeType.includes('image');
if (isImage && isAnimatedWebp) { if (isImage && isAnimatedWebp) {
throw new NodeOperationError( throw new NodeOperationError(
@@ -120,7 +106,7 @@ export async function uploadAttachments(
if (isImage) { if (isImage) {
const form = { const form = {
media_data: binaryData[binaryPropertyName].data, media_data: binaryData.data,
}; };
response = await twitterApiRequest.call(this, 'POST', '', {}, {}, uploadUri, { response = await twitterApiRequest.call(this, 'POST', '', {}, {}, uploadUri, {
@@ -130,13 +116,10 @@ export async function uploadAttachments(
media.push(response); media.push(response);
} else { } else {
// https://developer.twitter.com/en/docs/media/upload-media/api-reference/post-media-upload-init // https://developer.twitter.com/en/docs/media/upload-media/api-reference/post-media-upload-init
const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName);
attachmentBody = { attachmentBody = {
command: 'INIT', command: 'INIT',
total_bytes: binaryDataBuffer.byteLength, total_bytes: dataBuffer.byteLength,
media_type: binaryData[binaryPropertyName].mimeType, media_type: binaryData.mimeType,
}; };
response = await twitterApiRequest.call(this, 'POST', '', {}, {}, uploadUri, { response = await twitterApiRequest.call(this, 'POST', '', {}, {}, uploadUri, {
@@ -147,7 +130,7 @@ export async function uploadAttachments(
// break the data on 5mb chunks (max size that can be uploaded at once) // break the data on 5mb chunks (max size that can be uploaded at once)
const binaryParts = chunks(binaryDataBuffer, 5242880); const binaryParts = chunks(dataBuffer, 5242880);
let index = 0; let index = 0;
@@ -155,7 +138,7 @@ export async function uploadAttachments(
//https://developer.twitter.com/en/docs/media/upload-media/api-reference/post-media-upload-append //https://developer.twitter.com/en/docs/media/upload-media/api-reference/post-media-upload-append
attachmentBody = { attachmentBody = {
name: binaryData[binaryPropertyName].fileName, name: binaryData.fileName,
command: 'APPEND', command: 'APPEND',
media_id: mediaId, media_id: mediaId,
media_data: Buffer.from(binaryPart).toString('base64'), media_data: Buffer.from(binaryPart).toString('base64'),

View File

@@ -1,7 +1,7 @@
import type { IExecuteFunctions, ILoadOptionsFunctions } from 'n8n-core';
import type { import type {
IDataObject, IDataObject,
IExecuteFunctions,
ILoadOptionsFunctions,
INodeExecutionData, INodeExecutionData,
INodePropertyOptions, INodePropertyOptions,
INodeType, INodeType,
@@ -125,7 +125,7 @@ export class Twitter implements INodeType {
return propertyName.trim(); return propertyName.trim();
}); });
const medias = await uploadAttachments.call(this, attachmentProperties, items, i); const medias = await uploadAttachments.call(this, attachmentProperties, i);
body.message_create.message_data.attachment = { body.message_create.message_data.attachment = {
type: 'media', type: 'media',
//@ts-ignore //@ts-ignore
@@ -166,7 +166,7 @@ export class Twitter implements INodeType {
return propertyName.trim(); return propertyName.trim();
}); });
const medias = await uploadAttachments.call(this, attachmentProperties, items, i); const medias = await uploadAttachments.call(this, attachmentProperties, i);
body.media_ids = (medias as IDataObject[]) body.media_ids = (medias as IDataObject[])
.map((media: IDataObject) => media.media_id_string) .map((media: IDataObject) => media.media_id_string)

View File

@@ -10,25 +10,20 @@ export async function getUploadFormData(
if (!mediaPropertyName) if (!mediaPropertyName)
throw new NodeOperationError(this.getNode(), 'Parameter "mediaPropertyName" is not defined'); throw new NodeOperationError(this.getNode(), 'Parameter "mediaPropertyName" is not defined');
const { binary: binaryData } = this.getInputData(); const binaryData = this.helpers.assertBinaryData(mediaPropertyName);
if (!binaryData) throw new NodeOperationError(this.getNode(), 'Binary data missing in input');
const binaryFile = binaryData[mediaPropertyName];
if (binaryFile === undefined)
throw new NodeOperationError(this.getNode(), 'Could not find file in node input data');
const mediaFileName = (this.getNodeParameter('additionalFields') as IDataObject).mediaFileName as const mediaFileName = (this.getNodeParameter('additionalFields') as IDataObject).mediaFileName as
| string | string
| undefined; | undefined;
const fileName = mediaFileName || binaryFile.fileName; const fileName = mediaFileName || binaryData.fileName;
if (!fileName) if (!fileName)
throw new NodeOperationError(this.getNode(), 'No file name given for media upload.'); throw new NodeOperationError(this.getNode(), 'No file name given for media upload.');
const buffer = await this.helpers.getBinaryDataBuffer(mediaPropertyName); const buffer = await this.helpers.getBinaryDataBuffer(mediaPropertyName);
const formData = new FormData(); const formData = new FormData();
formData.append('file', buffer, { contentType: binaryFile.mimeType, filename: fileName }); formData.append('file', buffer, { contentType: binaryData.mimeType, filename: fileName });
formData.append('messaging_product', 'whatsapp'); formData.append('messaging_product', 'whatsapp');
return { fileName, formData }; return { fileName, formData };

View File

@@ -1,7 +1,10 @@
import type { IExecuteFunctions } from 'n8n-core';
import { BINARY_ENCODING } from 'n8n-core'; import { BINARY_ENCODING } from 'n8n-core';
import type { INodeExecutionData, INodeType, INodeTypeDescription } from 'n8n-workflow'; import type {
import { NodeOperationError } from 'n8n-workflow'; IExecuteFunctions,
INodeExecutionData,
INodeType,
INodeTypeDescription,
} from 'n8n-workflow';
import { writeFile as fsWriteFile } from 'fs/promises'; import { writeFile as fsWriteFile } from 'fs/promises';
import type { Readable } from 'stream'; import type { Readable } from 'stream';
@@ -76,22 +79,6 @@ export class WriteBinaryFile implements INodeType {
item = items[itemIndex]; item = items[itemIndex];
if (item.binary === undefined) {
throw new NodeOperationError(
this.getNode(),
'No binary data set. So file can not be written!',
{ itemIndex },
);
}
const itemBinaryData = item.binary[dataPropertyName];
if (itemBinaryData === undefined) {
throw new NodeOperationError(
this.getNode(),
`The binary property "${dataPropertyName}" does not exist. So no file can be written!`,
{ itemIndex },
);
}
const newItem: INodeExecutionData = { const newItem: INodeExecutionData = {
json: {}, json: {},
pairedItem: { pairedItem: {
@@ -100,11 +87,13 @@ export class WriteBinaryFile implements INodeType {
}; };
Object.assign(newItem.json, item.json); Object.assign(newItem.json, item.json);
const binaryData = this.helpers.assertBinaryData(itemIndex, dataPropertyName);
let fileContent: Buffer | Readable; let fileContent: Buffer | Readable;
if (itemBinaryData.id) { if (binaryData.id) {
fileContent = this.helpers.getBinaryStream(itemBinaryData.id); fileContent = this.helpers.getBinaryStream(binaryData.id);
} else { } else {
fileContent = Buffer.from(itemBinaryData.data, BINARY_ENCODING); fileContent = Buffer.from(binaryData.data, BINARY_ENCODING);
} }
// Write the file to disk // Write the file to disk

View File

@@ -1,6 +1,6 @@
import type { IExecuteFunctions } from 'n8n-core';
import type { import type {
IDataObject, IDataObject,
IExecuteFunctions,
ILoadOptionsFunctions, ILoadOptionsFunctions,
INodeExecutionData, INodeExecutionData,
INodePropertyOptions, INodePropertyOptions,
@@ -192,29 +192,16 @@ export class Zulip implements INodeType {
//https://zulipchat.com/api/upload-file //https://zulipchat.com/api/upload-file
if (operation === 'updateFile') { if (operation === 'updateFile') {
const credentials = await this.getCredentials('zulipApi'); const credentials = await this.getCredentials('zulipApi');
const binaryProperty = this.getNodeParameter('dataBinaryProperty', i); const dataBinaryProperty = this.getNodeParameter('dataBinaryProperty', i);
if (items[i].binary === undefined) {
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!');
}
//@ts-ignore
if (items[i].binary[binaryProperty] === undefined) {
throw new NodeOperationError(
this.getNode(),
`Item has no binary property called "${binaryProperty}"`,
{ itemIndex: i },
);
}
const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryProperty); const binaryData = this.helpers.assertBinaryData(i, dataBinaryProperty);
const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(i, dataBinaryProperty);
const formData = { const formData = {
file: { file: {
//@ts-ignore
value: binaryDataBuffer, value: binaryDataBuffer,
options: { options: {
//@ts-ignore filename: binaryData.fileName,
filename: items[i].binary[binaryProperty].fileName, contentType: binaryData.mimeType,
//@ts-ignore
contentType: items[i].binary[binaryProperty].mimeType,
}, },
}, },
}; };

View File

@@ -757,6 +757,7 @@ export type IExecuteFunctions = ExecuteFunctions.GetNodeParameterFn &
inputData: INodeExecutionData[], inputData: INodeExecutionData[],
options: { itemData: IPairedItemData | IPairedItemData[] }, options: { itemData: IPairedItemData | IPairedItemData[] },
): NodeExecutionWithMetadata[]; ): NodeExecutionWithMetadata[];
assertBinaryData(itemIndex: number, propertyName: string): IBinaryData;
getBinaryDataBuffer(itemIndex: number, propertyName: string): Promise<Buffer>; getBinaryDataBuffer(itemIndex: number, propertyName: string): Promise<Buffer>;
}; };
}; };
@@ -772,6 +773,7 @@ export interface IExecuteSingleFunctions extends BaseExecutionFunctions {
helpers: RequestHelperFunctions & helpers: RequestHelperFunctions &
BinaryHelperFunctions & { BinaryHelperFunctions & {
assertBinaryData(propertyName: string, inputIndex?: number): IBinaryData;
getBinaryDataBuffer(propertyName: string, inputIndex?: number): Promise<Buffer>; getBinaryDataBuffer(propertyName: string, inputIndex?: number): Promise<Buffer>;
}; };
} }

View File

@@ -457,7 +457,7 @@ function getParameterDependencies(nodePropertiesArray: INodeProperties[]): IPara
* to have the parameters available they depend on * to have the parameters available they depend on
* *
*/ */
export function getParamterResolveOrder( export function getParameterResolveOrder(
nodePropertiesArray: INodeProperties[], nodePropertiesArray: INodeProperties[],
parameterDependencies: IParameterDependencies, parameterDependencies: IParameterDependencies,
): number[] { ): number[] {
@@ -583,7 +583,7 @@ export function getNodeParameters(
nodeValuesRoot = nodeValuesRoot || nodeValuesDisplayCheck; nodeValuesRoot = nodeValuesRoot || nodeValuesDisplayCheck;
// Go through the parameters in order of their dependencies // Go through the parameters in order of their dependencies
const parameterItterationOrderIndex = getParamterResolveOrder( const parameterItterationOrderIndex = getParameterResolveOrder(
nodePropertiesArray, nodePropertiesArray,
parameterDependencies, parameterDependencies,
); );