first commit
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
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
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user