2024-01-03 03:08:16 -08:00
|
|
|
import type {
|
|
|
|
IExecuteFunctions,
|
|
|
|
INodeExecutionData,
|
|
|
|
INodeType,
|
|
|
|
INodeTypeDescription,
|
|
|
|
} from 'n8n-workflow';
|
2024-08-29 06:55:53 -07:00
|
|
|
import { NodeConnectionType } from 'n8n-workflow';
|
2024-01-03 03:08:16 -08:00
|
|
|
|
|
|
|
import * as spreadsheet from './actions/spreadsheet.operation';
|
|
|
|
import * as toBinary from './actions/toBinary.operation';
|
2024-02-13 06:52:37 -08:00
|
|
|
import * as toText from './actions/toText.operation';
|
2024-01-03 03:08:16 -08:00
|
|
|
import * as toJson from './actions/toJson.operation';
|
|
|
|
import * as iCall from './actions/iCall.operation';
|
|
|
|
|
|
|
|
export class ConvertToFile implements INodeType {
|
|
|
|
description: INodeTypeDescription = {
|
|
|
|
displayName: 'Convert to File',
|
|
|
|
name: 'convertToFile',
|
2024-06-06 04:34:30 -07:00
|
|
|
icon: { light: 'file:convertToFile.svg', dark: 'file:convertToFile.dark.svg' },
|
2024-01-03 03:08:16 -08:00
|
|
|
group: ['input'],
|
2024-02-13 06:52:37 -08:00
|
|
|
version: [1, 1.1],
|
2024-01-03 03:08:16 -08:00
|
|
|
description: 'Convert JSON data to binary data',
|
|
|
|
defaults: {
|
|
|
|
name: 'Convert to File',
|
|
|
|
},
|
2024-08-29 06:55:53 -07:00
|
|
|
inputs: [NodeConnectionType.Main],
|
|
|
|
outputs: [NodeConnectionType.Main],
|
2024-01-03 03:08:16 -08:00
|
|
|
properties: [
|
|
|
|
{
|
|
|
|
displayName: 'Operation',
|
|
|
|
name: 'operation',
|
|
|
|
type: 'options',
|
|
|
|
noDataExpression: true,
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
name: 'Convert to CSV',
|
|
|
|
value: 'csv',
|
|
|
|
action: 'Convert to CSV',
|
|
|
|
description: 'Transform input data into a CSV file',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Convert to HTML',
|
|
|
|
value: 'html',
|
|
|
|
action: 'Convert to HTML',
|
|
|
|
description: 'Transform input data into a table in an HTML file',
|
|
|
|
},
|
|
|
|
{
|
2024-02-21 08:04:57 -08:00
|
|
|
name: 'Convert to ICS',
|
2024-01-03 03:08:16 -08:00
|
|
|
value: 'iCal',
|
2024-02-21 08:04:57 -08:00
|
|
|
action: 'Convert to ICS',
|
2024-01-03 03:08:16 -08:00
|
|
|
description: 'Converts each input item to an ICS event file',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Convert to JSON',
|
|
|
|
value: 'toJson',
|
|
|
|
action: 'Convert to JSON',
|
|
|
|
description: 'Transform input data into a single or multiple JSON files',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Convert to ODS',
|
|
|
|
value: 'ods',
|
|
|
|
action: 'Convert to ODS',
|
|
|
|
description: 'Transform input data into an ODS file',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Convert to RTF',
|
|
|
|
value: 'rtf',
|
|
|
|
action: 'Convert to RTF',
|
|
|
|
description: 'Transform input data into a table in an RTF file',
|
|
|
|
},
|
2024-02-13 06:52:37 -08:00
|
|
|
{
|
|
|
|
name: 'Convert to Text File',
|
|
|
|
value: 'toText',
|
|
|
|
action: 'Convert to text file',
|
|
|
|
description: 'Transform input data string into a file',
|
|
|
|
},
|
2024-01-03 03:08:16 -08:00
|
|
|
{
|
|
|
|
name: 'Convert to XLS',
|
|
|
|
value: 'xls',
|
|
|
|
action: 'Convert to XLS',
|
|
|
|
description: 'Transform input data into an Excel file',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Convert to XLSX',
|
|
|
|
value: 'xlsx',
|
|
|
|
action: 'Convert to XLSX',
|
|
|
|
description: 'Transform input data into an Excel file',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Move Base64 String to File',
|
|
|
|
value: 'toBinary',
|
|
|
|
action: 'Move base64 string to file',
|
|
|
|
description: 'Convert a base64-encoded string into its original file format',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
default: 'csv',
|
|
|
|
},
|
|
|
|
...spreadsheet.description,
|
|
|
|
...toBinary.description,
|
2024-02-13 06:52:37 -08:00
|
|
|
...toText.description,
|
2024-01-03 03:08:16 -08:00
|
|
|
...toJson.description,
|
|
|
|
...iCall.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 (operation === 'toJson') {
|
|
|
|
returnData = await toJson.execute.call(this, items);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (operation === 'toBinary') {
|
|
|
|
returnData = await toBinary.execute.call(this, items);
|
|
|
|
}
|
|
|
|
|
2024-02-13 06:52:37 -08:00
|
|
|
if (operation === 'toText') {
|
|
|
|
returnData = await toText.execute.call(this, items);
|
|
|
|
}
|
|
|
|
|
2024-01-03 03:08:16 -08:00
|
|
|
if (operation === 'iCal') {
|
|
|
|
returnData = await iCall.execute.call(this, items);
|
|
|
|
}
|
|
|
|
|
|
|
|
return [returnData];
|
|
|
|
}
|
|
|
|
}
|