Remove executeSingle from ReadBinaryFile node

This commit is contained in:
dali 2021-02-16 08:09:10 +01:00
parent 46d1a5fe58
commit 8d119852f6
2 changed files with 36 additions and 28 deletions

View file

@ -134,7 +134,7 @@ export class EmailSend implements INodeType {
for (let itemIndex = 0; itemIndex < length; itemIndex++) { for (let itemIndex = 0; itemIndex < length; itemIndex++) {
item = items[itemIndex]; item = items[itemIndex];
console.log(item,itemIndex)
const fromEmail = this.getNodeParameter('fromEmail', itemIndex) as string; const fromEmail = this.getNodeParameter('fromEmail', itemIndex) as string;
const toEmail = this.getNodeParameter('toEmail', itemIndex) as string; const toEmail = this.getNodeParameter('toEmail', itemIndex) as string;
const ccEmail = this.getNodeParameter('ccEmail', itemIndex) as string; const ccEmail = this.getNodeParameter('ccEmail', itemIndex) as string;

View file

@ -1,4 +1,4 @@
import { IExecuteSingleFunctions } from 'n8n-core'; import { IExecuteFunctions } from 'n8n-core';
import { import {
INodeExecutionData, INodeExecutionData,
INodeType, INodeType,
@ -49,38 +49,46 @@ export class ReadBinaryFile implements INodeType {
}; };
async executeSingle(this: IExecuteSingleFunctions): Promise<INodeExecutionData> { async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
const item = this.getInputData(); const items = this.getInputData();
const dataPropertyName = this.getNodeParameter('dataPropertyName') as string; const returnData: INodeExecutionData[] = [];
const filePath = this.getNodeParameter('filePath') as string; const length = items.length as unknown as number;
let item: INodeExecutionData;
let data; for (let itemIndex = 0; itemIndex < length; itemIndex++) {
try { item = items[itemIndex];
data = await fsReadFileAsync(filePath) as Buffer; const dataPropertyName = this.getNodeParameter('dataPropertyName', itemIndex) as string;
} catch (error) { const filePath = this.getNodeParameter('filePath', itemIndex) as string;
if (error.code === 'ENOENT') {
throw new Error(`The file "${filePath}" could not be found.`); 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 = { if (item.binary !== undefined) {
json: item.json, // Create a shallow copy of the binary data so that the old
binary: {}, // 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) { newItem.binary![dataPropertyName] = await this.helpers.prepareBinaryData(data, filePath);
// Create a shallow copy of the binary data so that the old returnData.push(newItem);
// data references which do not get changed still stay behind }
// but the incoming data does not get changed.
Object.assign(newItem.binary, item.binary); return this.prepareOutputData(returnData);
}
newItem.binary![dataPropertyName] = await this.helpers.prepareBinaryData(data, filePath);
return newItem;
} }
} }