mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-26 03:52:23 -08:00
✨ Add download field to Airtable Trigger (#1406)
This commit is contained in:
parent
39ef004021
commit
b1ad897a86
|
@ -11,6 +11,7 @@ import {
|
||||||
|
|
||||||
import {
|
import {
|
||||||
apiRequestAllItems,
|
apiRequestAllItems,
|
||||||
|
downloadRecordAttachments,
|
||||||
} from './GenericFunctions';
|
} from './GenericFunctions';
|
||||||
|
|
||||||
import * as moment from 'moment';
|
import * as moment from 'moment';
|
||||||
|
@ -64,6 +65,28 @@ export class AirtableTrigger implements INodeType {
|
||||||
because without this field trigger will not work correctly.`,
|
because without this field trigger will not work correctly.`,
|
||||||
required: true,
|
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',
|
displayName: 'Additional Fields',
|
||||||
name: 'additionalFields',
|
name: 'additionalFields',
|
||||||
|
@ -100,6 +123,7 @@ export class AirtableTrigger implements INodeType {
|
||||||
};
|
};
|
||||||
|
|
||||||
async poll(this: IPollFunctions): Promise<INodeExecutionData[][] | null> {
|
async poll(this: IPollFunctions): Promise<INodeExecutionData[][] | null> {
|
||||||
|
const downloadAttachments = this.getNodeParameter('downloadAttachments', 0) as boolean;
|
||||||
|
|
||||||
const webhookData = this.getWorkflowStaticData('node');
|
const webhookData = this.getWorkflowStaticData('node');
|
||||||
|
|
||||||
|
@ -149,6 +173,12 @@ export class AirtableTrigger implements INodeType {
|
||||||
throw new Error(`The Field "${triggerField}" does not exist.`);
|
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)];
|
return [this.helpers.returnJsonArray(records)];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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[] = [];
|
const elements: INodeExecutionData[] = [];
|
||||||
for (const record of records) {
|
for (const record of records) {
|
||||||
const element: INodeExecutionData = { json: {}, binary: {} };
|
const element: INodeExecutionData = { json: {}, binary: {} };
|
||||||
|
|
Loading…
Reference in a new issue