Skip to content

Commit

Permalink
fix(core): Setup nodeHelpers that aren't exposed in the code sandbox …
Browse files Browse the repository at this point in the history
…(no-changelog) (#5753)
  • Loading branch information
netroy authored Mar 23, 2023
1 parent d3a34ab commit b0cfd69
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 10 deletions.
15 changes: 13 additions & 2 deletions packages/core/src/NodeExecuteFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import type {
IPairedItemData,
ICredentialTestFunctions,
BinaryHelperFunctions,
NodeHelperFunctions,
RequestHelperFunctions,
FunctionsBase,
IExecuteFunctions,
Expand Down Expand Up @@ -2054,6 +2055,13 @@ const getFileSystemHelperFunctions = (node: INode): FileSystemHelperFunctions =>
},
});

const getNodeHelperFunctions = ({
executionId,
}: IWorkflowExecuteAdditionalData): NodeHelperFunctions => ({
copyBinaryFile: async (filePath, fileName, mimeType) =>
copyBinaryFile(executionId!, filePath, fileName, mimeType),
});

const getBinaryHelperFunctions = ({
executionId,
}: IWorkflowExecuteAdditionalData): BinaryHelperFunctions => ({
Expand All @@ -2064,8 +2072,9 @@ const getBinaryHelperFunctions = ({
prepareBinaryData(binaryData, executionId!, filePath, mimeType),
setBinaryDataBuffer: async (data, binaryData) =>
setBinaryDataBuffer(data, binaryData, executionId!),
copyBinaryFile: async (filePath, fileName, mimeType) =>
copyBinaryFile(executionId!, filePath, fileName, mimeType),
copyBinaryFile: async () => {
throw new Error('copyBinaryFile has been removed. Please upgrade this node');
},
});

/**
Expand Down Expand Up @@ -2368,6 +2377,7 @@ export function getExecuteFunctions(
normalizeItems,
constructExecutionMetaData,
},
nodeHelpers: getNodeHelperFunctions(additionalData),
};
})(workflow, runExecutionData, connectionInputData, inputData, node) as IExecuteFunctions;
}
Expand Down Expand Up @@ -2758,6 +2768,7 @@ export function getExecuteWebhookFunctions(
...getBinaryHelperFunctions(additionalData),
returnJsonArray,
},
nodeHelpers: getNodeHelperFunctions(additionalData),
};
})(workflow, node);
}
4 changes: 2 additions & 2 deletions packages/nodes-base/nodes/Ftp/Ftp.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ export class Ftp implements INodeType {
const dataPropertyNameDownload = this.getNodeParameter('binaryPropertyName', i);
const filePathDownload = this.getNodeParameter('path', i) as string;

items[i].binary![dataPropertyNameDownload] = await this.helpers.copyBinaryFile(
items[i].binary![dataPropertyNameDownload] = await this.nodeHelpers.copyBinaryFile(
binaryFile.path,
filePathDownload,
);
Expand Down Expand Up @@ -699,7 +699,7 @@ export class Ftp implements INodeType {
const dataPropertyNameDownload = this.getNodeParameter('binaryPropertyName', i);
const filePathDownload = this.getNodeParameter('path', i) as string;

items[i].binary![dataPropertyNameDownload] = await this.helpers.copyBinaryFile(
items[i].binary![dataPropertyNameDownload] = await this.nodeHelpers.copyBinaryFile(
binaryFile.path,
filePathDownload,
);
Expand Down
2 changes: 1 addition & 1 deletion packages/nodes-base/nodes/Ssh/Ssh.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ export class Ssh implements INodeType {

items[i] = newItem;

items[i].binary![dataPropertyNameDownload] = await this.helpers.copyBinaryFile(
items[i].binary![dataPropertyNameDownload] = await this.nodeHelpers.copyBinaryFile(
path,
parameterPath,
);
Expand Down
4 changes: 2 additions & 2 deletions packages/nodes-base/nodes/Wait/Wait.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ export class Wait implements INodeType {
}

const fileJson = file.toJSON();
returnItem.binary![binaryPropertyName] = await this.helpers.copyBinaryFile(
returnItem.binary![binaryPropertyName] = await this.nodeHelpers.copyBinaryFile(
file.path,
fileJson.name || fileJson.filename,
fileJson.type as string,
Expand Down Expand Up @@ -747,7 +747,7 @@ export class Wait implements INodeType {
};

const binaryPropertyName = (options.binaryPropertyName || 'data') as string;
returnItem.binary![binaryPropertyName] = await this.helpers.copyBinaryFile(
returnItem.binary![binaryPropertyName] = await this.nodeHelpers.copyBinaryFile(
binaryFile.path,
mimeType,
);
Expand Down
4 changes: 2 additions & 2 deletions packages/nodes-base/nodes/Webhook/Webhook.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ export class Webhook implements INodeType {
}

const fileJson = file.toJSON();
returnItem.binary![binaryPropertyName] = await this.helpers.copyBinaryFile(
returnItem.binary![binaryPropertyName] = await this.nodeHelpers.copyBinaryFile(
file.path,
fileJson.name || fileJson.filename,
fileJson.type as string,
Expand Down Expand Up @@ -559,7 +559,7 @@ export class Webhook implements INodeType {
};

const binaryPropertyName = (options.binaryPropertyName || 'data') as string;
returnItem.binary![binaryPropertyName] = await this.helpers.copyBinaryFile(
returnItem.binary![binaryPropertyName] = await this.nodeHelpers.copyBinaryFile(
binaryFile.path,
mimeType,
);
Expand Down
8 changes: 7 additions & 1 deletion packages/workflow/src/Interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -676,12 +676,16 @@ export interface BinaryHelperFunctions {
mimeType?: string,
): Promise<IBinaryData>;
setBinaryDataBuffer(data: IBinaryData, binaryData: Buffer): Promise<IBinaryData>;
copyBinaryFile(filePath: string, fileName: string, mimeType?: string): Promise<IBinaryData>;
copyBinaryFile(): Promise<never>;
binaryToBuffer(body: Buffer | Readable): Promise<Buffer>;
getBinaryStream(binaryDataId: string, chunkSize?: number): Readable;
getBinaryMetadata(binaryDataId: string): Promise<BinaryMetadata>;
}

export interface NodeHelperFunctions {
copyBinaryFile(filePath: string, fileName: string, mimeType?: string): Promise<IBinaryData>;
}

export interface RequestHelperFunctions {
request(uriOrObject: string | IDataObject | any, options?: IDataObject): Promise<any>;
requestWithAuthentication(
Expand Down Expand Up @@ -753,6 +757,7 @@ export type IExecuteFunctions = ExecuteFunctions.GetNodeParameterFn &
sendMessageToUI(message: any): void;
sendResponse(response: IExecuteResponsePromiseData): void;

nodeHelpers: NodeHelperFunctions;
helpers: RequestHelperFunctions &
BaseHelperFunctions &
BinaryHelperFunctions &
Expand Down Expand Up @@ -875,6 +880,7 @@ export interface IWebhookFunctions extends FunctionsBaseWithRequiredKeys<'getMod
outputData: INodeExecutionData[],
outputIndex?: number,
): Promise<INodeExecutionData[][]>;
nodeHelpers: NodeHelperFunctions;
helpers: RequestHelperFunctions &
BaseHelperFunctions &
BinaryHelperFunctions &
Expand Down

0 comments on commit b0cfd69

Please sign in to comment.