mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 01:56:46 +00:00
🚚 Directorize and alphabetize nodes (#2445)
* 🚚 Directorize nodes * ⚡ Alphabetize nodes and credentials * 🔥 Remove unused node * 🔥 Remove unused codex * 🔥 Remove duplicate cred file references * 🐛 Fix node file paths * 🔥 Remove duplicate node reference
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
import { IExecuteFunctions } from 'n8n-core';
|
||||
import {
|
||||
INodeExecutionData,
|
||||
INodeType,
|
||||
INodeTypeDescription,
|
||||
} from 'n8n-workflow';
|
||||
import * as glob from 'fast-glob';
|
||||
import * as 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: {},
|
||||
};
|
||||
|
||||
items.push(item);
|
||||
}
|
||||
|
||||
return this.prepareOutputData(items);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user