Files
n8n/packages/nodes-base/nodes/Airtop/actions/file/get.operation.ts
T
alighasami 3d5eaf9445
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
first commit
2026-03-17 16:22:57 +03:30

77 lines
1.9 KiB
TypeScript

import { NodeOperationError } from 'n8n-workflow';
import type { IExecuteFunctions, INodeExecutionData, INodeProperties } from 'n8n-workflow';
import { ERROR_MESSAGES } from '../../constants';
import { apiRequest } from '../../transport';
import type { IAirtopResponseWithFiles } from '../../transport/types';
const displayOptions = {
show: {
resource: ['file'],
operation: ['get'],
},
};
export const description: INodeProperties[] = [
{
displayName: 'File ID',
name: 'fileId',
type: 'string',
default: '',
required: true,
description: 'ID of the file to retrieve',
displayOptions,
},
{
displayName: 'Output Binary File',
name: 'outputBinaryFile',
type: 'boolean',
default: false,
description: 'Whether to output the file in binary format if the file is ready for download',
displayOptions,
},
];
export async function execute(
this: IExecuteFunctions,
index: number,
): Promise<INodeExecutionData[]> {
const fileId = this.getNodeParameter('fileId', index, '') as string;
const outputBinaryFile = this.getNodeParameter('outputBinaryFile', index, false);
if (!fileId) {
throw new NodeOperationError(
this.getNode(),
ERROR_MESSAGES.REQUIRED_PARAMETER.replace('{{field}}', 'File ID'),
);
}
const response = (await apiRequest.call(
this,
'GET',
`/files/${fileId}`,
)) as IAirtopResponseWithFiles;
const { fileName = '', downloadUrl = '', status = '' } = response?.data ?? {};
// Handle binary file output
if (outputBinaryFile && downloadUrl && status === 'available') {
const buffer = (await this.helpers.httpRequest({
url: downloadUrl,
json: false,
encoding: 'arraybuffer',
})) as Buffer;
const file = await this.helpers.prepareBinaryData(buffer, fileName);
return [
{
json: {
...response,
},
binary: { data: file },
},
];
}
return this.helpers.returnJsonArray({ ...response });
}