feat(core): Add support for signed URLs for binary data (#14492)

Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
This commit is contained in:
Dana
2025-04-14 19:59:40 +02:00
committed by GitHub
co-authored by कारतोफ्फेलस्क्रिप्ट™
parent 23f25cefbf
commit 7723a138a1
22 changed files with 537 additions and 122 deletions
@@ -13,6 +13,7 @@ import { join } from 'path';
import { Readable } from 'stream';
import { BinaryDataService } from '@/binary-data/binary-data.service';
import { type InstanceSettings } from '@/instance-settings';
import {
assertBinaryData,
@@ -41,7 +42,7 @@ describe('test binary data helper methods', () => {
const temporaryDir = mkdtempSync(join(tmpdir(), 'n8n'));
beforeEach(() => {
binaryDataService = new BinaryDataService();
binaryDataService = new BinaryDataService(mock<InstanceSettings>(), mock());
Container.set(BinaryDataService, binaryDataService);
});
@@ -478,3 +479,24 @@ describe('getBinaryHelperFunctions', () => {
);
});
});
describe('createBinarySignedUrl', () => {
const restApiUrl = 'https://n8n.host/rest';
it('should get a signed url', async () => {
const additionalData = { restApiUrl } as IWorkflowExecuteAdditionalData;
const helperFunctions = getBinaryHelperFunctions(additionalData, workflowId);
const binaryData = mock<IBinaryData>();
const token = 'signed-token';
const binaryDataService = mock<BinaryDataService>();
Container.set(BinaryDataService, binaryDataService);
binaryDataService.createSignedToken.mockReturnValueOnce(token);
const result = helperFunctions.createBinarySignedUrl(binaryData);
expect(result).toBe(`${restApiUrl}/binary-data/signed?token=${token}`);
expect(binaryDataService.createSignedToken).toHaveBeenCalledWith(binaryData, undefined);
});
});
@@ -271,7 +271,7 @@ export async function prepareBinaryData(
}
export const getBinaryHelperFunctions = (
{ executionId }: IWorkflowExecuteAdditionalData,
{ executionId, restApiUrl }: IWorkflowExecuteAdditionalData,
workflowId: string,
): BinaryHelperFunctions => ({
getBinaryPath,
@@ -279,6 +279,10 @@ export const getBinaryHelperFunctions = (
getBinaryMetadata,
binaryToBuffer,
binaryToString,
createBinarySignedUrl(binaryData: IBinaryData, expiresIn?: string) {
const token = Container.get(BinaryDataService).createSignedToken(binaryData, expiresIn);
return `${restApiUrl}/binary-data/signed?token=${token}`;
},
prepareBinaryData: async (binaryData, filePath, mimeType) =>
await prepareBinaryData(binaryData, executionId!, workflowId, filePath, mimeType),
setBinaryDataBuffer: async (data, binaryData) =>