mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-26 05:04:05 -08:00
bdb84130d6
* ✨ Add pairedItem support * 👕 Fix lint issue * 🐛 Fix resolution in frontend * 🐛 Fix resolution issue * 🐛 Fix resolution in frontend * 🐛 Fix another resolution issue in frontend * ⚡ Try to automatically add pairedItem data if possible * ⚡ Cleanup * ⚡ Display expression errors in editor UI * 🐛 Fix issue that it did not display errors in production * 🐛 Fix auto-fix of missing pairedItem data * 🐛 Fix frontend resolution for not executed nodes * ⚡ Fail execution on pairedItem resolve issue and display information about itemIndex and runIndex * ⚡ Allow that pairedItem is only set to number if runIndex is 0 * ✨ Improve Expression Errors * ⚡ Remove no longer needed code * ⚡ Make errors more helpful * ⚡ Add additional errors * 👕 Fix lint issue * ⚡ Add pairedItem support to core nodes * ⚡ Improve support in Merge-Node * ⚡ Fix issue with not correctly converted incoming pairedItem data * 🐛 Fix frontend resolve issue * 🐛 Fix frontend parameter name display issue * ⚡ Improve errors * 👕 Fix lint issue * ⚡ Improve errors * ⚡ Make it possible to display parameter name in error messages * ⚡ Improve error messages * ⚡ Fix error message * ⚡ Improve error messages * ⚡ Add another error message * ⚡ Simplify
79 lines
1.7 KiB
TypeScript
79 lines
1.7 KiB
TypeScript
import { IExecuteFunctions } from 'n8n-core';
|
|
import {
|
|
INodeExecutionData,
|
|
INodeType,
|
|
INodeTypeDescription,
|
|
} from 'n8n-workflow';
|
|
import glob from 'fast-glob';
|
|
import path from 'path';
|
|
|
|
import {
|
|
readFile as fsReadFile,
|
|
} from 'fs/promises';
|
|
|
|
|
|
export class ReadBinaryFiles implements INodeType {
|
|
description: INodeTypeDescription = {
|
|
displayName: 'Read Binary Files',
|
|
name: 'readBinaryFiles',
|
|
icon: 'fa:file-import',
|
|
group: ['input'],
|
|
version: 1,
|
|
description: 'Reads binary files from disk',
|
|
defaults: {
|
|
name: 'Read Binary Files',
|
|
color: '#44AA44',
|
|
},
|
|
inputs: ['main'],
|
|
outputs: ['main'],
|
|
properties: [
|
|
{
|
|
displayName: 'File Selector',
|
|
name: 'fileSelector',
|
|
type: 'string',
|
|
default: '',
|
|
required: true,
|
|
placeholder: '*.jpg',
|
|
description: 'Pattern for files to read',
|
|
},
|
|
{
|
|
displayName: 'Property Name',
|
|
name: 'dataPropertyName',
|
|
type: 'string',
|
|
default: 'data',
|
|
required: true,
|
|
description: 'Name of the binary property to which to write the data of the read files',
|
|
},
|
|
],
|
|
};
|
|
|
|
|
|
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
|
const fileSelector = this.getNodeParameter('fileSelector', 0) as string;
|
|
const dataPropertyName = this.getNodeParameter('dataPropertyName', 0) as string;
|
|
|
|
const files = await glob(fileSelector);
|
|
|
|
const items: INodeExecutionData[] = [];
|
|
let item: INodeExecutionData;
|
|
let data: Buffer;
|
|
for (const filePath of files) {
|
|
data = await fsReadFile(filePath) as Buffer;
|
|
|
|
item = {
|
|
binary: {
|
|
[dataPropertyName]: await this.helpers.prepareBinaryData(data, filePath),
|
|
},
|
|
json: {},
|
|
pairedItem: {
|
|
item: 0,
|
|
},
|
|
};
|
|
|
|
items.push(item);
|
|
}
|
|
|
|
return this.prepareOutputData(items);
|
|
}
|
|
}
|