Files
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

57 lines
1.5 KiB
TypeScript

import FormData from 'form-data';
import type { IDataObject, IExecuteFunctions, ILoadOptionsFunctions } from 'n8n-workflow';
import { apiRequest } from '../transport';
import type { File } from './interfaces';
export function getMimeType(contentType?: string) {
return contentType?.split(';')?.[0];
}
export async function downloadFile(this: IExecuteFunctions, url: string, qs?: IDataObject) {
const downloadResponse = (await this.helpers.httpRequest({
method: 'GET',
url,
qs,
returnFullResponse: true,
encoding: 'arraybuffer',
})) as { body: ArrayBuffer; headers: IDataObject };
const mimeType =
getMimeType(downloadResponse.headers?.['content-type'] as string) ?? 'application/octet-stream';
const fileContent = Buffer.from(downloadResponse.body);
return {
fileContent,
mimeType,
};
}
export async function uploadFile(
this: IExecuteFunctions,
fileContent: Buffer,
mimeType: string,
fileName?: string,
) {
const form = new FormData();
form.append('file', fileContent, {
filename: fileName ?? 'file',
contentType: mimeType,
});
return (await apiRequest.call(this, 'POST', '/v1/files', {
headers: form.getHeaders(),
body: form,
})) as File;
}
export function splitByComma(str: string) {
return str
.split(',')
.map((s) => s.trim())
.filter((s) => s);
}
export async function getBaseUrl(this: IExecuteFunctions | ILoadOptionsFunctions) {
const credentials = await this.getCredentials('anthropicApi');
return (credentials.url ?? 'https://api.anthropic.com') as string;
}