first commit
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,199 @@
|
||||
import iconv from 'iconv-lite';
|
||||
import set from 'lodash/set';
|
||||
import unset from 'lodash/unset';
|
||||
import type {
|
||||
IDataObject,
|
||||
IExecuteFunctions,
|
||||
INodeExecutionData,
|
||||
INodeProperties,
|
||||
IBinaryData,
|
||||
} from 'n8n-workflow';
|
||||
import {
|
||||
BINARY_ENCODING,
|
||||
NodeOperationError,
|
||||
deepCopy,
|
||||
jsonParse,
|
||||
BINARY_MODE_COMBINED,
|
||||
} from 'n8n-workflow';
|
||||
import { icsCalendarToObject } from 'ts-ics';
|
||||
|
||||
import { encodeDecodeOptions } from '@utils/descriptions';
|
||||
import { updateDisplayOptions } from '@utils/utilities';
|
||||
|
||||
export const properties: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Input Binary Field',
|
||||
name: 'binaryPropertyName',
|
||||
type: 'string',
|
||||
default: 'data',
|
||||
required: true,
|
||||
placeholder: 'e.g data',
|
||||
hint: 'The name of the input field containing the file data to be processed',
|
||||
},
|
||||
{
|
||||
displayName: 'Destination Output Field',
|
||||
name: 'destinationKey',
|
||||
type: 'string',
|
||||
default: 'data',
|
||||
required: true,
|
||||
placeholder: 'e.g data',
|
||||
description: 'The name of the output field that will contain the extracted data',
|
||||
},
|
||||
{
|
||||
displayName: 'Options',
|
||||
name: 'options',
|
||||
type: 'collection',
|
||||
placeholder: 'Add option',
|
||||
default: {},
|
||||
options: [
|
||||
{
|
||||
displayName: 'File Encoding',
|
||||
name: 'encoding',
|
||||
type: 'options',
|
||||
options: encodeDecodeOptions,
|
||||
default: 'utf8',
|
||||
description: 'Specify the encoding of the file, defaults to UTF-8',
|
||||
},
|
||||
{
|
||||
displayName: 'Strip BOM',
|
||||
name: 'stripBOM',
|
||||
displayOptions: {
|
||||
show: {
|
||||
encoding: ['utf8', 'cesu8', 'ucs2'],
|
||||
},
|
||||
},
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
description:
|
||||
'Whether to strip the BOM (Byte Order Mark) from the file, this could help in an environment where the presence of the BOM is causing issues or inconsistencies',
|
||||
},
|
||||
{
|
||||
displayName: 'Keep Source',
|
||||
name: 'keepSource',
|
||||
type: 'options',
|
||||
default: 'json',
|
||||
options: [
|
||||
{
|
||||
name: 'JSON',
|
||||
value: 'json',
|
||||
description: 'Include JSON data of the input item',
|
||||
},
|
||||
{
|
||||
name: 'Binary',
|
||||
value: 'binary',
|
||||
description: 'Include binary data of the input item',
|
||||
},
|
||||
{
|
||||
name: 'Both',
|
||||
value: 'both',
|
||||
description: 'Include both JSON and binary data of the input item',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
const displayOptions = {
|
||||
show: {
|
||||
operation: ['binaryToPropery', 'fromJson', 'text', 'fromIcs', 'xml'],
|
||||
},
|
||||
};
|
||||
|
||||
export const description = updateDisplayOptions(displayOptions, properties);
|
||||
|
||||
export async function execute(
|
||||
this: IExecuteFunctions,
|
||||
items: INodeExecutionData[],
|
||||
operation: string,
|
||||
) {
|
||||
const returnData: INodeExecutionData[] = [];
|
||||
const { binaryMode } = this.getWorkflowSettings();
|
||||
|
||||
for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
|
||||
try {
|
||||
const item = items[itemIndex];
|
||||
const options = this.getNodeParameter('options', itemIndex);
|
||||
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', itemIndex) as
|
||||
| string
|
||||
| IBinaryData;
|
||||
|
||||
const newItem: INodeExecutionData = {
|
||||
json: {},
|
||||
pairedItem: { item: itemIndex },
|
||||
};
|
||||
|
||||
const value = this.helpers.assertBinaryData(itemIndex, binaryPropertyName);
|
||||
|
||||
if (!value) continue;
|
||||
|
||||
const buffer = await this.helpers.getBinaryDataBuffer(itemIndex, binaryPropertyName);
|
||||
const encoding = (options.encoding as string) || this.helpers.detectBinaryEncoding(buffer);
|
||||
|
||||
if (options.keepSource && options.keepSource !== 'binary') {
|
||||
newItem.json = deepCopy(item.json);
|
||||
}
|
||||
|
||||
let convertedValue: string | IDataObject;
|
||||
if (operation !== 'binaryToPropery') {
|
||||
convertedValue = iconv.decode(buffer, encoding, {
|
||||
stripBOM: options.stripBOM as boolean,
|
||||
});
|
||||
} else {
|
||||
convertedValue = Buffer.from(buffer).toString(BINARY_ENCODING);
|
||||
}
|
||||
|
||||
if (operation === 'fromJson') {
|
||||
if (convertedValue === '') {
|
||||
convertedValue = {};
|
||||
} else {
|
||||
convertedValue = jsonParse(convertedValue);
|
||||
}
|
||||
}
|
||||
|
||||
if (operation === 'fromIcs') {
|
||||
convertedValue = icsCalendarToObject(convertedValue as string);
|
||||
}
|
||||
|
||||
const destinationKey = this.getNodeParameter('destinationKey', itemIndex, '') as string;
|
||||
set(newItem.json, destinationKey, convertedValue);
|
||||
|
||||
if (typeof binaryPropertyName === 'string' && binaryMode !== BINARY_MODE_COMBINED) {
|
||||
if (options.keepSource === 'binary' || options.keepSource === 'both') {
|
||||
newItem.binary = item.binary;
|
||||
} else {
|
||||
// this binary data would not be included, but there also might be other binary data
|
||||
// which should be included, copy it over and unset current binary data
|
||||
newItem.binary = deepCopy(item.binary);
|
||||
unset(newItem.binary, binaryPropertyName);
|
||||
}
|
||||
}
|
||||
|
||||
returnData.push(newItem);
|
||||
} catch (error) {
|
||||
let errorDescription;
|
||||
if (typeof error.message === 'string' && error.message.includes('Unexpected token')) {
|
||||
error.message = "The file selected in 'Input Binary Field' is not in JSON format";
|
||||
errorDescription =
|
||||
"Try to change the operation or select a JSON file in 'Input Binary Field'";
|
||||
}
|
||||
if (this.continueOnFail()) {
|
||||
returnData.push({
|
||||
json: {
|
||||
error: error.message,
|
||||
},
|
||||
pairedItem: {
|
||||
item: itemIndex,
|
||||
},
|
||||
});
|
||||
continue;
|
||||
}
|
||||
throw new NodeOperationError(this.getNode(), error, {
|
||||
itemIndex,
|
||||
description: errorDescription,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return returnData;
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
import unset from 'lodash/unset';
|
||||
import type { IExecuteFunctions, INodeExecutionData, INodeProperties } from 'n8n-workflow';
|
||||
import { NodeOperationError, deepCopy } from 'n8n-workflow';
|
||||
|
||||
import { extractDataFromPDF } from '@utils/binary';
|
||||
import { updateDisplayOptions } from '@utils/utilities';
|
||||
|
||||
export const properties: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Input Binary Field',
|
||||
name: 'binaryPropertyName',
|
||||
type: 'string',
|
||||
default: 'data',
|
||||
required: true,
|
||||
placeholder: 'e.g data',
|
||||
hint: 'The name of the input binary field containing the file to be extracted',
|
||||
},
|
||||
{
|
||||
displayName: 'Options',
|
||||
name: 'options',
|
||||
type: 'collection',
|
||||
placeholder: 'Add option',
|
||||
default: {},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Join Pages',
|
||||
name: 'joinPages',
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
description:
|
||||
'Whether to join the text from all pages or return an array of text from each page',
|
||||
},
|
||||
{
|
||||
displayName: 'Keep Source',
|
||||
name: 'keepSource',
|
||||
type: 'options',
|
||||
default: 'json',
|
||||
options: [
|
||||
{
|
||||
name: 'JSON',
|
||||
value: 'json',
|
||||
description: 'Include JSON data of the input item',
|
||||
},
|
||||
{
|
||||
name: 'Binary',
|
||||
value: 'binary',
|
||||
description: 'Include binary data of the input item',
|
||||
},
|
||||
{
|
||||
name: 'Both',
|
||||
value: 'both',
|
||||
description: 'Include both JSON and binary data of the input item',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
displayName: 'Max Pages',
|
||||
name: 'maxPages',
|
||||
type: 'number',
|
||||
default: 0,
|
||||
description: 'Maximum number of pages to include',
|
||||
},
|
||||
{
|
||||
displayName: 'Password',
|
||||
name: 'password',
|
||||
type: 'string',
|
||||
typeOptions: { password: true },
|
||||
default: '',
|
||||
description: 'Prowide password, if the PDF is encrypted',
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
const displayOptions = {
|
||||
show: {
|
||||
operation: ['pdf'],
|
||||
},
|
||||
};
|
||||
|
||||
export const description = updateDisplayOptions(displayOptions, properties);
|
||||
|
||||
export async function execute(this: IExecuteFunctions, items: INodeExecutionData[]) {
|
||||
const returnData: INodeExecutionData[] = [];
|
||||
|
||||
for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
|
||||
try {
|
||||
const item = items[itemIndex];
|
||||
const options = this.getNodeParameter('options', itemIndex);
|
||||
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', itemIndex);
|
||||
|
||||
const json = await extractDataFromPDF.call(
|
||||
this,
|
||||
binaryPropertyName,
|
||||
options.password as string,
|
||||
options.maxPages as number,
|
||||
options.joinPages as boolean,
|
||||
itemIndex,
|
||||
);
|
||||
|
||||
const newItem: INodeExecutionData = {
|
||||
json: {},
|
||||
pairedItem: { item: itemIndex },
|
||||
};
|
||||
|
||||
if (options.keepSource && options.keepSource !== 'binary') {
|
||||
newItem.json = { ...deepCopy(item.json), ...json };
|
||||
} else {
|
||||
newItem.json = json;
|
||||
}
|
||||
|
||||
if (options.keepSource === 'binary' || options.keepSource === 'both') {
|
||||
newItem.binary = item.binary;
|
||||
} else {
|
||||
// this binary data would not be included, but there also might be other binary data
|
||||
// which should be included, copy it over and unset current binary data
|
||||
newItem.binary = deepCopy(item.binary);
|
||||
unset(newItem.binary, binaryPropertyName);
|
||||
}
|
||||
|
||||
returnData.push(newItem);
|
||||
} catch (error) {
|
||||
if (this.continueOnFail()) {
|
||||
returnData.push({
|
||||
json: {
|
||||
error: error.message,
|
||||
},
|
||||
pairedItem: {
|
||||
item: itemIndex,
|
||||
},
|
||||
});
|
||||
continue;
|
||||
}
|
||||
throw new NodeOperationError(this.getNode(), error, { itemIndex });
|
||||
}
|
||||
}
|
||||
|
||||
return returnData;
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
import type { IExecuteFunctions, INodeExecutionData, INodeProperties } from 'n8n-workflow';
|
||||
|
||||
import * as fromFile from '../../../SpreadsheetFile/v2/fromFile.operation';
|
||||
|
||||
export const operations = ['csv', 'html', 'rtf', 'ods', 'xls', 'xlsx'];
|
||||
|
||||
export const description: INodeProperties[] = fromFile.description
|
||||
.filter((property) => property.name !== 'fileFormat')
|
||||
.map((property) => {
|
||||
const newProperty = { ...property };
|
||||
newProperty.displayOptions = {
|
||||
show: {
|
||||
operation: operations,
|
||||
},
|
||||
};
|
||||
|
||||
if (newProperty.name === 'options') {
|
||||
newProperty.options = (newProperty.options as INodeProperties[]).map((option) => {
|
||||
let newOption = option;
|
||||
if (
|
||||
[
|
||||
'delimiter',
|
||||
'encoding',
|
||||
'fromLine',
|
||||
'maxRowCount',
|
||||
'enableBOM',
|
||||
'relaxQuotes',
|
||||
'skipRecordsWithErrors',
|
||||
].includes(option.name)
|
||||
) {
|
||||
newOption = { ...option, displayOptions: { show: { '/operation': ['csv'] } } };
|
||||
}
|
||||
if (option.name === 'sheetName') {
|
||||
newOption = {
|
||||
...option,
|
||||
displayOptions: { show: { '/operation': ['ods', 'xls', 'xlsx'] } },
|
||||
description: 'Name of the sheet to read from in the spreadsheet',
|
||||
};
|
||||
}
|
||||
if (option.name === 'range') {
|
||||
newOption = {
|
||||
...option,
|
||||
displayOptions: { show: { '/operation': ['ods', 'xls', 'xlsx'] } },
|
||||
};
|
||||
}
|
||||
if (['includeEmptyCells', 'headerRow'].includes(option.name)) {
|
||||
newOption = {
|
||||
...option,
|
||||
displayOptions: { show: { '/operation': ['ods', 'xls', 'xlsx', 'csv', 'html'] } },
|
||||
};
|
||||
}
|
||||
return newOption;
|
||||
});
|
||||
}
|
||||
return newProperty;
|
||||
});
|
||||
|
||||
export async function execute(
|
||||
this: IExecuteFunctions,
|
||||
items: INodeExecutionData[],
|
||||
fileFormatProperty: string,
|
||||
options?: fromFile.FromFileOptions,
|
||||
) {
|
||||
const returnData: INodeExecutionData[] = await fromFile.execute.call(
|
||||
this,
|
||||
items,
|
||||
fileFormatProperty,
|
||||
options,
|
||||
);
|
||||
return returnData;
|
||||
}
|
||||
Reference in New Issue
Block a user