mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 02:21:13 +00:00
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>
This commit is contained in:
@@ -0,0 +1,134 @@
|
||||
import type {
|
||||
IExecuteFunctions,
|
||||
INodeExecutionData,
|
||||
INodeType,
|
||||
INodeTypeDescription,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import * as spreadsheet from './actions/spreadsheet.operation';
|
||||
import * as moveTo from './actions/moveTo.operation';
|
||||
import * as pdf from './actions/pdf.operation';
|
||||
|
||||
export class ExtractFromFile implements INodeType {
|
||||
// eslint-disable-next-line n8n-nodes-base/node-class-description-missing-subtitle
|
||||
description: INodeTypeDescription = {
|
||||
displayName: 'Extract From File',
|
||||
name: 'extractFromFile',
|
||||
icon: 'file:extractFromFile.svg',
|
||||
group: ['input'],
|
||||
version: 1,
|
||||
description: 'Convert binary data to JSON',
|
||||
defaults: {
|
||||
name: 'Extract From File',
|
||||
},
|
||||
inputs: ['main'],
|
||||
outputs: ['main'],
|
||||
properties: [
|
||||
{
|
||||
displayName: 'Operation',
|
||||
name: 'operation',
|
||||
type: 'options',
|
||||
noDataExpression: true,
|
||||
// eslint-disable-next-line n8n-nodes-base/node-param-options-type-unsorted-items
|
||||
options: [
|
||||
{
|
||||
name: 'Extract From CSV',
|
||||
value: 'csv',
|
||||
action: 'Extract from CSV',
|
||||
description: 'Transform a CSV file into output items',
|
||||
},
|
||||
{
|
||||
name: 'Extract From HTML',
|
||||
value: 'html',
|
||||
action: 'Extract from HTML',
|
||||
description: 'Transform a table in an HTML file into output items',
|
||||
},
|
||||
{
|
||||
name: 'Extract From JSON',
|
||||
value: 'fromJson',
|
||||
action: 'Extract from JSON',
|
||||
description: 'Transform a JSON file into output items',
|
||||
},
|
||||
{
|
||||
name: 'Extract From ICS',
|
||||
value: 'fromIcs',
|
||||
action: 'Extract from ICS',
|
||||
description: 'Transform a ICS file into output items',
|
||||
},
|
||||
{
|
||||
name: 'Extract From ODS',
|
||||
value: 'ods',
|
||||
action: 'Extract from ODS',
|
||||
description: 'Transform an ODS file into output items',
|
||||
},
|
||||
{
|
||||
name: 'Extract From PDF',
|
||||
value: 'pdf',
|
||||
action: 'Extract from PDF',
|
||||
description: 'Extracts the content and metadata from a PDF file',
|
||||
},
|
||||
{
|
||||
name: 'Extract From RTF',
|
||||
value: 'rtf',
|
||||
action: 'Extract from RTF',
|
||||
description: 'Transform a table in an RTF file into output items',
|
||||
},
|
||||
{
|
||||
name: 'Extract From Text File',
|
||||
value: 'text',
|
||||
action: 'Extract from text file',
|
||||
description: 'Extracts the content of a text file',
|
||||
},
|
||||
{
|
||||
name: 'Extract From XML',
|
||||
value: 'xml',
|
||||
action: 'Extract from XLS',
|
||||
description: 'Extracts the content of an XML file',
|
||||
},
|
||||
{
|
||||
name: 'Extract From XLS',
|
||||
value: 'xls',
|
||||
action: 'Extract from XLS',
|
||||
description: 'Transform an Excel file into output items',
|
||||
},
|
||||
{
|
||||
name: 'Extract From XLSX',
|
||||
value: 'xlsx',
|
||||
action: 'Extract from XLSX',
|
||||
description: 'Transform an Excel file into output items',
|
||||
},
|
||||
{
|
||||
name: 'Move File to Base64 String',
|
||||
value: 'binaryToPropery',
|
||||
action: 'Move file to base64 string',
|
||||
description: 'Convert a file into a base64-encoded string',
|
||||
},
|
||||
],
|
||||
default: 'csv',
|
||||
},
|
||||
...spreadsheet.description,
|
||||
...moveTo.description,
|
||||
...pdf.description,
|
||||
],
|
||||
};
|
||||
|
||||
async execute(this: IExecuteFunctions) {
|
||||
const items = this.getInputData();
|
||||
const operation = this.getNodeParameter('operation', 0);
|
||||
let returnData: INodeExecutionData[] = [];
|
||||
|
||||
if (spreadsheet.operations.includes(operation)) {
|
||||
returnData = await spreadsheet.execute.call(this, items, 'operation');
|
||||
}
|
||||
|
||||
if (['binaryToPropery', 'fromJson', 'text', 'fromIcs', 'xml'].includes(operation)) {
|
||||
returnData = await moveTo.execute.call(this, items, operation);
|
||||
}
|
||||
|
||||
if (operation === 'pdf') {
|
||||
returnData = await pdf.execute.call(this, items);
|
||||
}
|
||||
|
||||
return [returnData];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user