From b1ad897a8634226105cc2daa3d84b5b5c03e8861 Mon Sep 17 00:00:00 2001 From: Ricardo Espinoza Date: Thu, 4 Feb 2021 09:43:48 -0500 Subject: [PATCH] :sparkles: Add download field to Airtable Trigger (#1406) --- .../nodes/Airtable/AirtableTrigger.node.ts | 30 +++++++++++++++++++ .../nodes/Airtable/GenericFunctions.ts | 2 +- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/packages/nodes-base/nodes/Airtable/AirtableTrigger.node.ts b/packages/nodes-base/nodes/Airtable/AirtableTrigger.node.ts index 6cb1d3a6c9..abba82b256 100644 --- a/packages/nodes-base/nodes/Airtable/AirtableTrigger.node.ts +++ b/packages/nodes-base/nodes/Airtable/AirtableTrigger.node.ts @@ -11,6 +11,7 @@ import { import { apiRequestAllItems, + downloadRecordAttachments, } from './GenericFunctions'; import * as moment from 'moment'; @@ -64,6 +65,28 @@ export class AirtableTrigger implements INodeType { because without this field trigger will not work correctly.`, required: true, }, + { + displayName: 'Download Attachments', + name: 'downloadAttachments', + type: 'boolean', + default: false, + description: `When set to true the attachment fields define in 'Download Fields' will be downloaded.`, + }, + { + displayName: 'Download Fields', + name: 'downloadFieldNames', + type: 'string', + required: true, + displayOptions: { + show: { + downloadAttachments: [ + true, + ], + }, + }, + default: '', + description: `Name of the fields of type 'attachment' that should be downloaded. Multiple ones can be defined separated by comma. Case sensitive.`, + }, { displayName: 'Additional Fields', name: 'additionalFields', @@ -100,6 +123,7 @@ export class AirtableTrigger implements INodeType { }; async poll(this: IPollFunctions): Promise { + const downloadAttachments = this.getNodeParameter('downloadAttachments', 0) as boolean; const webhookData = this.getWorkflowStaticData('node'); @@ -149,6 +173,12 @@ export class AirtableTrigger implements INodeType { throw new Error(`The Field "${triggerField}" does not exist.`); } + if (downloadAttachments === true) { + const downloadFieldNames = (this.getNodeParameter('downloadFieldNames', 0) as string).split(','); + const data = await downloadRecordAttachments.call(this, records, downloadFieldNames); + return [data]; + } + return [this.helpers.returnJsonArray(records)]; } diff --git a/packages/nodes-base/nodes/Airtable/GenericFunctions.ts b/packages/nodes-base/nodes/Airtable/GenericFunctions.ts index 09be7c40bd..d13b3a5723 100644 --- a/packages/nodes-base/nodes/Airtable/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Airtable/GenericFunctions.ts @@ -130,7 +130,7 @@ export async function apiRequestAllItems(this: IHookFunctions | IExecuteFunction }; } -export async function downloadRecordAttachments(this: IExecuteFunctions, records: IRecord[], fieldNames: string[]): Promise { +export async function downloadRecordAttachments(this: IExecuteFunctions | IPollFunctions, records: IRecord[], fieldNames: string[]): Promise { const elements: INodeExecutionData[] = []; for (const record of records) { const element: INodeExecutionData = { json: {}, binary: {} };