mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
Remove executeSingle from WriteBinaryFile node
This commit is contained in:
parent
b0664d2aa0
commit
735a7e6812
|
@ -1,6 +1,7 @@
|
||||||
import {
|
import {
|
||||||
BINARY_ENCODING,
|
BINARY_ENCODING,
|
||||||
IExecuteSingleFunctions,
|
IExecuteFunctions,
|
||||||
|
IExecuteSingleFunctions
|
||||||
} from 'n8n-core';
|
} from 'n8n-core';
|
||||||
import {
|
import {
|
||||||
IDataObject,
|
IDataObject,
|
||||||
|
@ -53,39 +54,53 @@ export class WriteBinaryFile 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 fileName = this.getNodeParameter('fileName') as string;
|
const length = items.length as unknown as number;
|
||||||
|
let item: INodeExecutionData;
|
||||||
|
|
||||||
if (item.binary === undefined) {
|
for (let itemIndex = 0; itemIndex < length; itemIndex++) {
|
||||||
throw new Error('No binary data set. So file can not be written!');
|
|
||||||
|
const dataPropertyName = this.getNodeParameter('dataPropertyName', itemIndex) as string;
|
||||||
|
|
||||||
|
const fileName = this.getNodeParameter('fileName', itemIndex) as string;
|
||||||
|
|
||||||
|
item = items[itemIndex];
|
||||||
|
|
||||||
|
if (item.binary === undefined) {
|
||||||
|
throw new Error('No binary data set. So file can not be written!');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (item.binary[dataPropertyName] === undefined) {
|
||||||
|
throw new Error(`The binary property "${dataPropertyName}" does not exist. So no file can be written!`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write the file to disk
|
||||||
|
await fsWriteFileAsync(fileName, Buffer.from(item.binary[dataPropertyName].data, BINARY_ENCODING), 'binary');
|
||||||
|
|
||||||
|
const newItem: INodeExecutionData = {
|
||||||
|
json: {},
|
||||||
|
};
|
||||||
|
Object.assign(newItem.json, item.json);
|
||||||
|
|
||||||
|
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.
|
||||||
|
newItem.binary = {};
|
||||||
|
Object.assign(newItem.binary, item.binary);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add the file name to data
|
||||||
|
|
||||||
|
(newItem.json as IDataObject).fileName = fileName;
|
||||||
|
|
||||||
|
returnData.push(newItem);
|
||||||
}
|
}
|
||||||
|
return this.prepareOutputData(returnData);
|
||||||
if (item.binary[dataPropertyName] === undefined) {
|
|
||||||
throw new Error(`The binary property "${dataPropertyName}" does not exist. So no file can be written!`);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Write the file to disk
|
|
||||||
await fsWriteFileAsync(fileName, Buffer.from(item.binary[dataPropertyName].data, BINARY_ENCODING), 'binary');
|
|
||||||
|
|
||||||
const newItem: INodeExecutionData = {
|
|
||||||
json: {},
|
|
||||||
};
|
|
||||||
Object.assign(newItem.json, item.json);
|
|
||||||
|
|
||||||
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.
|
|
||||||
newItem.binary = {};
|
|
||||||
Object.assign(newItem.binary, item.binary);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add the file name to data
|
|
||||||
(newItem.json as IDataObject).fileName = fileName;
|
|
||||||
|
|
||||||
return newItem;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue