Add download field to Airtable Trigger (#1406)

This commit is contained in:
Ricardo Espinoza 2021-02-04 09:43:48 -05:00 committed by GitHub
parent 39ef004021
commit b1ad897a86
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 1 deletions

View file

@ -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<INodeExecutionData[][] | null> {
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)];
}

View file

@ -130,7 +130,7 @@ export async function apiRequestAllItems(this: IHookFunctions | IExecuteFunction
};
}
export async function downloadRecordAttachments(this: IExecuteFunctions, records: IRecord[], fieldNames: string[]): Promise<INodeExecutionData[]> {
export async function downloadRecordAttachments(this: IExecuteFunctions | IPollFunctions, records: IRecord[], fieldNames: string[]): Promise<INodeExecutionData[]> {
const elements: INodeExecutionData[] = [];
for (const record of records) {
const element: INodeExecutionData = { json: {}, binary: {} };