mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +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:
@@ -35,21 +35,33 @@ export class BinaryDataService {
|
||||
}
|
||||
|
||||
@LogCatch((error) => Logger.error('Failed to copy binary data file', { error }))
|
||||
async copyBinaryFile(binaryData: IBinaryData, path: string, executionId: string) {
|
||||
async copyBinaryFile(
|
||||
workflowId: string,
|
||||
executionId: string,
|
||||
binaryData: IBinaryData,
|
||||
filePath: string,
|
||||
) {
|
||||
const manager = this.managers[this.mode];
|
||||
|
||||
if (!manager) {
|
||||
const { size } = await stat(path);
|
||||
const { size } = await stat(filePath);
|
||||
binaryData.fileSize = prettyBytes(size);
|
||||
binaryData.data = await readFile(path, { encoding: BINARY_ENCODING });
|
||||
binaryData.data = await readFile(filePath, { encoding: BINARY_ENCODING });
|
||||
|
||||
return binaryData;
|
||||
}
|
||||
|
||||
const { fileId, fileSize } = await manager.copyByFilePath(path, executionId, {
|
||||
const metadata = {
|
||||
fileName: binaryData.fileName,
|
||||
mimeType: binaryData.mimeType,
|
||||
});
|
||||
};
|
||||
|
||||
const { fileId, fileSize } = await manager.copyByFilePath(
|
||||
workflowId,
|
||||
executionId,
|
||||
filePath,
|
||||
metadata,
|
||||
);
|
||||
|
||||
binaryData.id = this.createBinaryDataId(fileId);
|
||||
binaryData.fileSize = prettyBytes(fileSize);
|
||||
@@ -59,7 +71,12 @@ export class BinaryDataService {
|
||||
}
|
||||
|
||||
@LogCatch((error) => Logger.error('Failed to write binary data file', { error }))
|
||||
async store(binaryData: IBinaryData, bufferOrStream: Buffer | Readable, executionId: string) {
|
||||
async store(
|
||||
workflowId: string,
|
||||
executionId: string,
|
||||
bufferOrStream: Buffer | Readable,
|
||||
binaryData: IBinaryData,
|
||||
) {
|
||||
const manager = this.managers[this.mode];
|
||||
|
||||
if (!manager) {
|
||||
@@ -70,10 +87,17 @@ export class BinaryDataService {
|
||||
return binaryData;
|
||||
}
|
||||
|
||||
const { fileId, fileSize } = await manager.store(bufferOrStream, executionId, {
|
||||
const metadata = {
|
||||
fileName: binaryData.fileName,
|
||||
mimeType: binaryData.mimeType,
|
||||
});
|
||||
};
|
||||
|
||||
const { fileId, fileSize } = await manager.store(
|
||||
workflowId,
|
||||
executionId,
|
||||
bufferOrStream,
|
||||
metadata,
|
||||
);
|
||||
|
||||
binaryData.id = this.createBinaryDataId(fileId);
|
||||
binaryData.fileSize = prettyBytes(fileSize);
|
||||
@@ -128,7 +152,11 @@ export class BinaryDataService {
|
||||
@LogCatch((error) =>
|
||||
Logger.error('Failed to copy all binary data files for execution', { error }),
|
||||
)
|
||||
async duplicateBinaryData(inputData: Array<INodeExecutionData[] | null>, executionId: string) {
|
||||
async duplicateBinaryData(
|
||||
workflowId: string,
|
||||
executionId: string,
|
||||
inputData: Array<INodeExecutionData[] | null>,
|
||||
) {
|
||||
if (inputData && this.managers[this.mode]) {
|
||||
const returnInputData = (inputData as INodeExecutionData[][]).map(
|
||||
async (executionDataArray) => {
|
||||
@@ -136,7 +164,7 @@ export class BinaryDataService {
|
||||
return Promise.all(
|
||||
executionDataArray.map(async (executionData) => {
|
||||
if (executionData.binary) {
|
||||
return this.duplicateBinaryDataInExecData(executionData, executionId);
|
||||
return this.duplicateBinaryDataInExecData(workflowId, executionId, executionData);
|
||||
}
|
||||
|
||||
return executionData;
|
||||
@@ -174,8 +202,9 @@ export class BinaryDataService {
|
||||
}
|
||||
|
||||
private async duplicateBinaryDataInExecData(
|
||||
executionData: INodeExecutionData,
|
||||
workflowId: string,
|
||||
executionId: string,
|
||||
executionData: INodeExecutionData,
|
||||
) {
|
||||
const manager = this.managers[this.mode];
|
||||
|
||||
@@ -193,7 +222,7 @@ export class BinaryDataService {
|
||||
|
||||
const [_mode, fileId] = binaryDataId.split(':');
|
||||
|
||||
return manager?.copyByFileId(fileId, executionId).then((newFileId) => ({
|
||||
return manager?.copyByFileId(workflowId, executionId, fileId).then((newFileId) => ({
|
||||
newId: this.createBinaryDataId(newFileId),
|
||||
key,
|
||||
}));
|
||||
|
||||
Reference in New Issue
Block a user