Skip to content

Commit

Permalink
feat(core): Improvements/overhaul for nodes working with binary data (#…
Browse files Browse the repository at this point in the history
…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>
  • Loading branch information
3 people authored Jan 3, 2024
1 parent 259323b commit 5e16dd4
Show file tree
Hide file tree
Showing 119 changed files with 4,463 additions and 1,187 deletions.
8 changes: 5 additions & 3 deletions cypress/e2e/16-webhook-node.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,14 @@ describe('Webhook Trigger node', async () => {

ndv.getters.backToCanvas().click();

workflowPage.actions.addNodeToCanvas('Convert to/from binary data');
workflowPage.actions.addNodeToCanvas('Convert to File');
workflowPage.actions.zoomToFit();

workflowPage.actions.openNode('Convert to/from binary data');
workflowPage.actions.openNode('Convert to File');
cy.getByTestId('parameter-input-operation').click();
getVisibleSelect().find('.option-headline').contains('Convert to JSON').click();
cy.getByTestId('parameter-input-mode').click();
getVisibleSelect().find('.option-headline').contains('JSON to Binary').click();
getVisibleSelect().find('.option-headline').contains('Each Item to Separate File').click();
ndv.getters.backToCanvas().click();

workflowPage.actions.executeWorkflow();
Expand Down
7 changes: 4 additions & 3 deletions cypress/e2e/4-node-creator.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ describe('Node Creator', () => {
it('should not show actions for single action nodes', () => {
const singleActionNodes = [
'DHL',
'iCalendar',
'Edit Fields',
'LingvaNex',
'Mailcheck',
'MSG91',
Expand Down Expand Up @@ -484,8 +484,9 @@ describe('Node Creator', () => {
nodeCreatorFeature.getters.nodeItemName().first().should('have.text', 'Wait');

nodeCreatorFeature.getters.searchBar().find('input').clear().type('spreadsheet');
nodeCreatorFeature.getters.nodeItemName().first().should('have.text', 'Spreadsheet File');
nodeCreatorFeature.getters.nodeItemName().eq(1).should('have.text', 'Google Sheets');
nodeCreatorFeature.getters.nodeItemName().first().should('have.text', 'Convert to File');
nodeCreatorFeature.getters.nodeItemName().eq(1).should('have.text', 'Extract From File');
nodeCreatorFeature.getters.nodeItemName().eq(2).should('have.text', 'Google Sheets');

nodeCreatorFeature.getters.searchBar().find('input').clear().type('sheets');
nodeCreatorFeature.getters.nodeItemName().first().should('have.text', 'Google Sheets');
Expand Down
23 changes: 17 additions & 6 deletions packages/core/src/NodeExecuteFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -987,16 +987,27 @@ export function assertBinaryData(
): IBinaryData {
const binaryKeyData = inputData.main[inputIndex]![itemIndex]!.binary;
if (binaryKeyData === undefined) {
throw new NodeOperationError(node, 'No binary data exists on item!', {
itemIndex,
});
throw new NodeOperationError(
node,
`This operation expects the node's input data to contain a binary file '${propertyName}', but none was found [item ${itemIndex}]`,
{
itemIndex,
description: 'Make sure that the previous node outputs a binary file',
},
);
}

const binaryPropertyData = binaryKeyData[propertyName];
if (binaryPropertyData === undefined) {
throw new NodeOperationError(node, `Item has no binary property called "${propertyName}"`, {
itemIndex,
});
throw new NodeOperationError(
node,
`The item has no binary field '${propertyName}' [item ${itemIndex}]`,
{
itemIndex,
description:
'Check that the parameter where you specified the input binary field name is correct, and that it matches a field in the binary input',
},
);
}

return binaryPropertyData;
Expand Down
22 changes: 21 additions & 1 deletion packages/editor-ui/src/components/Node/NodeCreator/viewsData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import {
AI_CATEGORY_EMBEDDING,
AI_OTHERS_NODE_CREATOR_VIEW,
AI_UNCATEGORIZED_CATEGORY,
CONVERT_TO_FILE_NODE_TYPE,
EXTRACT_FROM_FILE_NODE_TYPE,
SET_NODE_TYPE,
CODE_NODE_TYPE,
DATETIME_NODE_TYPE,
Expand All @@ -48,6 +50,8 @@ import {
HELPERS_SUBCATEGORY,
RSS_READ_NODE_TYPE,
EMAIL_SEND_NODE_TYPE,
EDIT_IMAGE_NODE_TYPE,
COMPRESSION_NODE_TYPE,
} from '@/constants';
import { useI18n } from '@/composables/useI18n';
import { useNodeTypesStore } from '@/stores/nodeTypes.store';
Expand Down Expand Up @@ -394,7 +398,16 @@ export function RegularView(nodes: SimplifiedNodeType[]) {
{
key: 'convert',
title: i18n.baseText('nodeCreator.sectionNames.transform.convert'),
items: [HTML_NODE_TYPE, MARKDOWN_NODE_TYPE, XML_NODE_TYPE, CRYPTO_NODE_TYPE],
items: [
HTML_NODE_TYPE,
MARKDOWN_NODE_TYPE,
XML_NODE_TYPE,
CRYPTO_NODE_TYPE,
EXTRACT_FROM_FILE_NODE_TYPE,
CONVERT_TO_FILE_NODE_TYPE,
COMPRESSION_NODE_TYPE,
EDIT_IMAGE_NODE_TYPE,
],
},
],
},
Expand Down Expand Up @@ -422,6 +435,13 @@ export function RegularView(nodes: SimplifiedNodeType[]) {
properties: {
title: FILES_SUBCATEGORY,
icon: 'file-alt',
sections: [
{
key: 'popular',
title: i18n.baseText('nodeCreator.sectionNames.popular'),
items: [CONVERT_TO_FILE_NODE_TYPE, EXTRACT_FROM_FILE_NODE_TYPE],
},
],
},
},
{
Expand Down
4 changes: 4 additions & 0 deletions packages/editor-ui/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ export const XERO_NODE_TYPE = 'n8n-nodes-base.xero';
export const ZENDESK_NODE_TYPE = 'n8n-nodes-base.zendesk';
export const ZENDESK_TRIGGER_NODE_TYPE = 'n8n-nodes-base.zendeskTrigger';
export const DISCORD_NODE_TYPE = 'n8n-nodes-base.discord';
export const EXTRACT_FROM_FILE_NODE_TYPE = 'n8n-nodes-base.extractFromFile';
export const CONVERT_TO_FILE_NODE_TYPE = 'n8n-nodes-base.convertToFile';
export const DATETIME_NODE_TYPE = 'n8n-nodes-base.dateTime';
export const REMOVE_DUPLICATES_NODE_TYPE = 'n8n-nodes-base.removeDuplicates';
export const SPLIT_OUT_NODE_TYPE = 'n8n-nodes-base.splitOut';
Expand All @@ -172,6 +174,8 @@ export const MARKDOWN_NODE_TYPE = 'n8n-nodes-base.markdown';
export const XML_NODE_TYPE = 'n8n-nodes-base.xml';
export const CRYPTO_NODE_TYPE = 'n8n-nodes-base.crypto';
export const RSS_READ_NODE_TYPE = 'n8n-nodes-base.rssFeedRead';
export const COMPRESSION_NODE_TYPE = 'n8n-nodes-base.compression';
export const EDIT_IMAGE_NODE_TYPE = 'n8n-nodes-base.editImage';

export const CREDENTIAL_ONLY_NODE_PREFIX = 'n8n-creds-base';
export const CREDENTIAL_ONLY_HTTP_NODE_VERSION = 4.1;
Expand Down
4 changes: 2 additions & 2 deletions packages/nodes-base/nodes/ApiTemplateIo/ApiTemplateIo.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,12 @@ export class ApiTemplateIo implements INodeType {
description: 'Name of the binary property to which to write the data of the read file',
},
{
displayName: 'Binary Property',
displayName: 'Put Output File in Field',
name: 'binaryProperty',
type: 'string',
required: true,
default: 'data',
description: 'Name of the binary property to which to write to',
hint: 'The name of the output binary field to put the file in',
displayOptions: {
show: {
resource: ['pdf', 'image'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export class AwsRekognition implements INodeType {
default: 'detectFaces',
},
{
displayName: 'Binary Data',
displayName: 'Binary File',
name: 'binaryData',
type: 'boolean',
default: false,
Expand All @@ -104,7 +104,7 @@ export class AwsRekognition implements INodeType {
description: 'Whether the image to analyze should be taken from binary field',
},
{
displayName: 'Binary Property',
displayName: 'Input Binary Field',
displayOptions: {
show: {
operation: ['analyze'],
Expand All @@ -115,7 +115,7 @@ export class AwsRekognition implements INodeType {
name: 'binaryPropertyName',
type: 'string',
default: 'data',
description: 'Object property name which holds binary data',
hint: 'The name of the input binary field containing the file to be written',
required: true,
},
{
Expand Down
10 changes: 5 additions & 5 deletions packages/nodes-base/nodes/Aws/S3/V1/FileDescription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ export const fileFields: INodeProperties[] = [
description: 'If not set the binary data filename will be used',
},
{
displayName: 'Binary Data',
displayName: 'Binary File',
name: 'binaryData',
type: 'boolean',
default: true,
Expand Down Expand Up @@ -401,7 +401,7 @@ export const fileFields: INodeProperties[] = [
description: 'The text content of the file to upload',
},
{
displayName: 'Binary Property',
displayName: 'Input Binary Field',
name: 'binaryPropertyName',
type: 'string',
default: 'data',
Expand All @@ -414,7 +414,7 @@ export const fileFields: INodeProperties[] = [
},
},
placeholder: '',
description: 'Name of the binary property which contains the data for the file to be uploaded',
hint: 'The name of the input binary field containing the file to be uploaded',
},
{
displayName: 'Additional Fields',
Expand Down Expand Up @@ -698,7 +698,7 @@ export const fileFields: INodeProperties[] = [
},
},
{
displayName: 'Binary Property',
displayName: 'Put Output File in Field',
name: 'binaryPropertyName',
type: 'string',
required: true,
Expand All @@ -709,7 +709,7 @@ export const fileFields: INodeProperties[] = [
resource: ['file'],
},
},
description: 'Name of the binary property to which to write the data of the read file',
hint: 'The name of the output binary field to put the file in',
},
/* -------------------------------------------------------------------------- */
/* file:delete */
Expand Down
10 changes: 5 additions & 5 deletions packages/nodes-base/nodes/Aws/S3/V2/FileDescription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ export const fileFields: INodeProperties[] = [
description: 'If not set the binary data filename will be used',
},
{
displayName: 'Binary Data',
displayName: 'Binary File',
name: 'binaryData',
type: 'boolean',
default: true,
Expand Down Expand Up @@ -401,7 +401,7 @@ export const fileFields: INodeProperties[] = [
description: 'The text content of the file to upload',
},
{
displayName: 'Binary Property',
displayName: 'Input Binary Field',
name: 'binaryPropertyName',
type: 'string',
default: 'data',
Expand All @@ -414,7 +414,7 @@ export const fileFields: INodeProperties[] = [
},
},
placeholder: '',
description: 'Name of the binary property which contains the data for the file to be uploaded',
hint: 'The name of the input binary field containing the file to be uploaded',
},
{
displayName: 'Additional Fields',
Expand Down Expand Up @@ -698,7 +698,7 @@ export const fileFields: INodeProperties[] = [
},
},
{
displayName: 'Binary Property',
displayName: 'Put Output File in Field',
name: 'binaryPropertyName',
type: 'string',
required: true,
Expand All @@ -709,7 +709,7 @@ export const fileFields: INodeProperties[] = [
resource: ['file'],
},
},
description: 'Name of the binary property to which to write the data of the read file',
hint: 'The name of the output binary field to put the file in',
},
/* -------------------------------------------------------------------------- */
/* file:delete */
Expand Down
10 changes: 5 additions & 5 deletions packages/nodes-base/nodes/Box/FileDescription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export const fileFields: INodeProperties[] = [
default: '',
},
{
displayName: 'Binary Property',
displayName: 'Put Output File in Field',
name: 'binaryPropertyName',
type: 'string',
required: true,
Expand All @@ -172,7 +172,7 @@ export const fileFields: INodeProperties[] = [
resource: ['file'],
},
},
description: 'Name of the binary property to which to write the data of the read file',
hint: 'The name of the output binary field to put the file in',
},

/* -------------------------------------------------------------------------- */
Expand Down Expand Up @@ -671,7 +671,7 @@ export const fileFields: INodeProperties[] = [
description: 'The name the file should be saved as',
},
{
displayName: 'Binary Data',
displayName: 'Binary File',
name: 'binaryData',
type: 'boolean',
default: false,
Expand Down Expand Up @@ -700,7 +700,7 @@ export const fileFields: INodeProperties[] = [
description: 'The text content of the file',
},
{
displayName: 'Binary Property',
displayName: 'Input Binary Field',
name: 'binaryPropertyName',
type: 'string',
default: 'data',
Expand All @@ -712,7 +712,7 @@ export const fileFields: INodeProperties[] = [
resource: ['file'],
},
},
description: 'Name of the binary property which contains the data for the file',
hint: 'The name of the input binary field containing the file to be uploaded',
},
{
displayName: 'Parent ID',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ export const messageFields: INodeProperties[] = [
value: 'url',
},
{
name: 'Binary Data',
name: 'Binary File',
value: 'binaryData',
},
],
Expand Down
15 changes: 13 additions & 2 deletions packages/nodes-base/nodes/Compression/Compression.node.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,19 @@
}
]
},
"alias": ["Zip", "Gzip", "uncompress"],
"alias": [
"Zip",
"Gzip",
"uncompress",
"compress",
"decompress",
"archive",
"unarchive",
"Binary",
"Files",
"File"
],
"subcategories": {
"Core Nodes": ["Files"]
"Core Nodes": ["Files", "Data Transformation"]
}
}
Loading

0 comments on commit 5e16dd4

Please sign in to comment.