n8n/packages/nodes-base/nodes/Files/ReadWriteFile/ReadWriteFile.node.ts
Michael Kret 5e16dd4ab4
feat(core): Improvements/overhaul for nodes working with binary data (#7651)
Github issue / Community forum post (link here to close automatically):

---------

Co-authored-by: Giulio Andreini <andreini@netseven.it>
Co-authored-by: Marcus <marcus@n8n.io>
2024-01-03 13:08:16 +02:00

74 lines
1.8 KiB
TypeScript

import type {
IExecuteFunctions,
INodeExecutionData,
INodeType,
INodeTypeDescription,
} from 'n8n-workflow';
import * as read from './actions/read.operation';
import * as write from './actions/write.operation';
export class ReadWriteFile implements INodeType {
description: INodeTypeDescription = {
displayName: 'Read/Write Files from Disk',
name: 'readWriteFile',
icon: 'file:readWriteFile.svg',
group: ['input'],
version: 1,
description: 'Read or write files from the computer that runs n8n',
defaults: {
name: 'Read/Write Files from Disk',
},
inputs: ['main'],
outputs: ['main'],
properties: [
{
displayName:
'Use this node to read and write files on the same computer running n8n. To handle files between different computers please use other nodes (e.g. FTP, HTTP Request, AWS).',
name: 'info',
type: 'notice',
default: '',
},
{
displayName: 'Operation',
name: 'operation',
type: 'options',
noDataExpression: true,
options: [
{
name: 'Read File(s) From Disk',
value: 'read',
description: 'Retrieve one or more files from the computer that runs n8n',
action: 'Read File(s) From Disk',
},
{
name: 'Write File to Disk',
value: 'write',
description: 'Create a binary file on the computer that runs n8n',
action: 'Write File to Disk',
},
],
default: 'read',
},
...read.description,
...write.description,
],
};
async execute(this: IExecuteFunctions) {
const operation = this.getNodeParameter('operation', 0, 'read');
const items = this.getInputData();
let returnData: INodeExecutionData[] = [];
if (operation === 'read') {
returnData = await read.execute.call(this, items);
}
if (operation === 'write') {
returnData = await write.execute.call(this, items);
}
return [returnData];
}
}