From 8d119852f64be150525b8326d63e019d8542224f Mon Sep 17 00:00:00 2001 From: dali Date: Tue, 16 Feb 2021 08:09:10 +0100 Subject: [PATCH] Remove executeSingle from ReadBinaryFile node --- packages/nodes-base/nodes/EmailSend.node.ts | 2 +- .../nodes-base/nodes/ReadBinaryFile.node.ts | 62 +++++++++++-------- 2 files changed, 36 insertions(+), 28 deletions(-) diff --git a/packages/nodes-base/nodes/EmailSend.node.ts b/packages/nodes-base/nodes/EmailSend.node.ts index 7e203d8890..2bdc29076f 100644 --- a/packages/nodes-base/nodes/EmailSend.node.ts +++ b/packages/nodes-base/nodes/EmailSend.node.ts @@ -134,7 +134,7 @@ export class EmailSend implements INodeType { for (let itemIndex = 0; itemIndex < length; itemIndex++) { item = items[itemIndex]; - console.log(item,itemIndex) + const fromEmail = this.getNodeParameter('fromEmail', itemIndex) as string; const toEmail = this.getNodeParameter('toEmail', itemIndex) as string; const ccEmail = this.getNodeParameter('ccEmail', itemIndex) as string; diff --git a/packages/nodes-base/nodes/ReadBinaryFile.node.ts b/packages/nodes-base/nodes/ReadBinaryFile.node.ts index ee38fc0cdc..e8be54cd4c 100644 --- a/packages/nodes-base/nodes/ReadBinaryFile.node.ts +++ b/packages/nodes-base/nodes/ReadBinaryFile.node.ts @@ -1,4 +1,4 @@ -import { IExecuteSingleFunctions } from 'n8n-core'; +import { IExecuteFunctions } from 'n8n-core'; import { INodeExecutionData, INodeType, @@ -49,38 +49,46 @@ export class ReadBinaryFile implements INodeType { }; - async executeSingle(this: IExecuteSingleFunctions): Promise { - const item = this.getInputData(); + async execute(this: IExecuteFunctions): Promise { + const items = this.getInputData(); - const dataPropertyName = this.getNodeParameter('dataPropertyName') as string; - const filePath = this.getNodeParameter('filePath') as string; + const returnData: INodeExecutionData[] = []; + const length = items.length as unknown as number; + let item: INodeExecutionData; - let data; - try { - data = await fsReadFileAsync(filePath) as Buffer; - } catch (error) { - if (error.code === 'ENOENT') { - throw new Error(`The file "${filePath}" could not be found.`); + for (let itemIndex = 0; itemIndex < length; itemIndex++) { + item = items[itemIndex]; + const dataPropertyName = this.getNodeParameter('dataPropertyName', itemIndex) as string; + const filePath = this.getNodeParameter('filePath', itemIndex) as string; + + let data; + try { + data = await fsReadFileAsync(filePath) as Buffer; + } catch (error) { + if (error.code === 'ENOENT') { + throw new Error(`The file "${filePath}" could not be found.`); + } + + throw error; } - throw error; - } + const newItem: INodeExecutionData = { + json: item.json, + binary: {}, + }; - const newItem: INodeExecutionData = { - json: item.json, - binary: {}, - }; + if (item.binary !== undefined) { + // Create a shallow copy of the binary data so that the old + // data references which do not get changed still stay behind + // but the incoming data does not get changed. + Object.assign(newItem.binary, item.binary); + } - if (item.binary !== undefined) { - // Create a shallow copy of the binary data so that the old - // data references which do not get changed still stay behind - // but the incoming data does not get changed. - Object.assign(newItem.binary, item.binary); - } - - newItem.binary![dataPropertyName] = await this.helpers.prepareBinaryData(data, filePath); - - return newItem; + newItem.binary![dataPropertyName] = await this.helpers.prepareBinaryData(data, filePath); + returnData.push(newItem); + } + + return this.prepareOutputData(returnData); } }