mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2026-09-26 19:51:42 +02:00
feat(core): Add support for signed URLs for binary data (#14492)
Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
This commit is contained in:
co-authored by
कारतोफ्फेलस्क्रिप्ट™
parent
23f25cefbf
commit
7723a138a1
+23
-1
@@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
+5
-1
@@ -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) =>
|
||||
|
||||
Reference in New Issue
Block a user