mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
refactor(core): Include workflow ID in binary data writes (no-changelog) (#7220)
Depends on: https://github.com/n8n-io/n8n/pull/7195 | Story: [PAY-837](https://linear.app/n8n/issue/PAY-837/implement-object-store-manager-for-binary-data) This PR includes `workflowId` in binary data writes so that the S3 manager can support this filepath structure `/workflows/{workflowId}/executions/{executionId}/binaryData/{binaryFilename}` to easily delete binary data for workflows. Also all binary data service and manager methods that take `workflowId` and `executionId` are made consistent in arg order. Note: `workflowId` is included in filesystem mode for compatibility with the common interface, but `workflowId` will remain unused by filesystem mode until we decide to restructure how this mode stores data. --------- Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
This commit is contained in:
@@ -999,19 +999,26 @@ export async function getBinaryDataBuffer(
|
||||
* Store an incoming IBinaryData & related buffer using the configured binary data manager.
|
||||
*
|
||||
* @export
|
||||
* @param {IBinaryData} data
|
||||
* @param {Buffer | Readable} binaryData
|
||||
* @param {IBinaryData} binaryData
|
||||
* @param {Buffer | Readable} bufferOrStream
|
||||
* @returns {Promise<IBinaryData>}
|
||||
*/
|
||||
export async function setBinaryDataBuffer(
|
||||
data: IBinaryData,
|
||||
binaryData: Buffer | Readable,
|
||||
binaryData: IBinaryData,
|
||||
bufferOrStream: Buffer | Readable,
|
||||
workflowId: string,
|
||||
executionId: string,
|
||||
): Promise<IBinaryData> {
|
||||
return Container.get(BinaryDataService).store(data, binaryData, executionId);
|
||||
return Container.get(BinaryDataService).store(
|
||||
workflowId,
|
||||
executionId,
|
||||
bufferOrStream,
|
||||
binaryData,
|
||||
);
|
||||
}
|
||||
|
||||
export async function copyBinaryFile(
|
||||
workflowId: string,
|
||||
executionId: string,
|
||||
filePath: string,
|
||||
fileName: string,
|
||||
@@ -1061,7 +1068,12 @@ export async function copyBinaryFile(
|
||||
returnData.fileName = path.parse(filePath).base;
|
||||
}
|
||||
|
||||
return Container.get(BinaryDataService).copyBinaryFile(returnData, filePath, executionId);
|
||||
return Container.get(BinaryDataService).copyBinaryFile(
|
||||
workflowId,
|
||||
executionId,
|
||||
returnData,
|
||||
filePath,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1071,6 +1083,7 @@ export async function copyBinaryFile(
|
||||
async function prepareBinaryData(
|
||||
binaryData: Buffer | Readable,
|
||||
executionId: string,
|
||||
workflowId: string,
|
||||
filePath?: string,
|
||||
mimeType?: string,
|
||||
): Promise<IBinaryData> {
|
||||
@@ -1152,7 +1165,7 @@ async function prepareBinaryData(
|
||||
}
|
||||
}
|
||||
|
||||
return setBinaryDataBuffer(returnData, binaryData, executionId);
|
||||
return setBinaryDataBuffer(returnData, binaryData, workflowId, executionId);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2324,7 +2337,7 @@ export function getNodeWebhookUrl(
|
||||
undefined,
|
||||
false,
|
||||
) as boolean;
|
||||
return NodeHelpers.getNodeWebhookUrl(baseUrl, workflow.id!, node, path.toString(), isFullPath);
|
||||
return NodeHelpers.getNodeWebhookUrl(baseUrl, workflow.id, node, path.toString(), isFullPath);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2560,25 +2573,27 @@ const getFileSystemHelperFunctions = (node: INode): FileSystemHelperFunctions =>
|
||||
},
|
||||
});
|
||||
|
||||
const getNodeHelperFunctions = ({
|
||||
executionId,
|
||||
}: IWorkflowExecuteAdditionalData): NodeHelperFunctions => ({
|
||||
const getNodeHelperFunctions = (
|
||||
{ executionId }: IWorkflowExecuteAdditionalData,
|
||||
workflowId: string,
|
||||
): NodeHelperFunctions => ({
|
||||
copyBinaryFile: async (filePath, fileName, mimeType) =>
|
||||
copyBinaryFile(executionId!, filePath, fileName, mimeType),
|
||||
copyBinaryFile(workflowId, executionId!, filePath, fileName, mimeType),
|
||||
});
|
||||
|
||||
const getBinaryHelperFunctions = ({
|
||||
executionId,
|
||||
}: IWorkflowExecuteAdditionalData): BinaryHelperFunctions => ({
|
||||
const getBinaryHelperFunctions = (
|
||||
{ executionId }: IWorkflowExecuteAdditionalData,
|
||||
workflowId: string,
|
||||
): BinaryHelperFunctions => ({
|
||||
getBinaryPath,
|
||||
getBinaryStream,
|
||||
getBinaryMetadata,
|
||||
binaryToBuffer: async (body: Buffer | Readable) =>
|
||||
Container.get(BinaryDataService).binaryToBuffer(body),
|
||||
prepareBinaryData: async (binaryData, filePath, mimeType) =>
|
||||
prepareBinaryData(binaryData, executionId!, filePath, mimeType),
|
||||
prepareBinaryData(binaryData, executionId!, workflowId, filePath, mimeType),
|
||||
setBinaryDataBuffer: async (data, binaryData) =>
|
||||
setBinaryDataBuffer(data, binaryData, executionId!),
|
||||
setBinaryDataBuffer(data, binaryData, workflowId, executionId!),
|
||||
copyBinaryFile: async () => {
|
||||
throw new Error('copyBinaryFile has been removed. Please upgrade this node');
|
||||
},
|
||||
@@ -2638,7 +2653,7 @@ export function getExecutePollFunctions(
|
||||
helpers: {
|
||||
createDeferredPromise,
|
||||
...getRequestHelperFunctions(workflow, node, additionalData),
|
||||
...getBinaryHelperFunctions(additionalData),
|
||||
...getBinaryHelperFunctions(additionalData, workflow.id),
|
||||
returnJsonArray,
|
||||
},
|
||||
};
|
||||
@@ -2697,7 +2712,7 @@ export function getExecuteTriggerFunctions(
|
||||
helpers: {
|
||||
createDeferredPromise,
|
||||
...getRequestHelperFunctions(workflow, node, additionalData),
|
||||
...getBinaryHelperFunctions(additionalData),
|
||||
...getBinaryHelperFunctions(additionalData, workflow.id),
|
||||
returnJsonArray,
|
||||
},
|
||||
};
|
||||
@@ -2763,8 +2778,9 @@ export function getExecuteFunctions(
|
||||
})
|
||||
.then(async (result) =>
|
||||
Container.get(BinaryDataService).duplicateBinaryData(
|
||||
result,
|
||||
workflow.id,
|
||||
additionalData.executionId!,
|
||||
result,
|
||||
),
|
||||
);
|
||||
},
|
||||
@@ -2872,7 +2888,7 @@ export function getExecuteFunctions(
|
||||
createDeferredPromise,
|
||||
...getRequestHelperFunctions(workflow, node, additionalData),
|
||||
...getFileSystemHelperFunctions(node),
|
||||
...getBinaryHelperFunctions(additionalData),
|
||||
...getBinaryHelperFunctions(additionalData, workflow.id),
|
||||
assertBinaryData: (itemIndex, propertyName) =>
|
||||
assertBinaryData(inputData, node, itemIndex, propertyName, 0),
|
||||
getBinaryDataBuffer: async (itemIndex, propertyName) =>
|
||||
@@ -2882,7 +2898,7 @@ export function getExecuteFunctions(
|
||||
normalizeItems,
|
||||
constructExecutionMetaData,
|
||||
},
|
||||
nodeHelpers: getNodeHelperFunctions(additionalData),
|
||||
nodeHelpers: getNodeHelperFunctions(additionalData, workflow.id),
|
||||
};
|
||||
})(workflow, runExecutionData, connectionInputData, inputData, node) as IExecuteFunctions;
|
||||
}
|
||||
@@ -3014,7 +3030,7 @@ export function getExecuteSingleFunctions(
|
||||
helpers: {
|
||||
createDeferredPromise,
|
||||
...getRequestHelperFunctions(workflow, node, additionalData),
|
||||
...getBinaryHelperFunctions(additionalData),
|
||||
...getBinaryHelperFunctions(additionalData, workflow.id),
|
||||
|
||||
assertBinaryData: (propertyName, inputIndex = 0) =>
|
||||
assertBinaryData(inputData, node, itemIndex, propertyName, inputIndex),
|
||||
@@ -3271,10 +3287,10 @@ export function getExecuteWebhookFunctions(
|
||||
helpers: {
|
||||
createDeferredPromise,
|
||||
...getRequestHelperFunctions(workflow, node, additionalData),
|
||||
...getBinaryHelperFunctions(additionalData),
|
||||
...getBinaryHelperFunctions(additionalData, workflow.id),
|
||||
returnJsonArray,
|
||||
},
|
||||
nodeHelpers: getNodeHelperFunctions(additionalData),
|
||||
nodeHelpers: getNodeHelperFunctions(additionalData, workflow.id),
|
||||
};
|
||||
})(workflow, node);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user