fix(core): Setup nodeHelpers that aren't exposed in the code sandbox (no-changelog) (#5753)

This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™ 2023-03-23 15:11:18 +01:00 committed by GitHub
parent d3a34ab71b
commit b0cfd69f2b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 27 additions and 10 deletions

View file

@ -49,6 +49,7 @@ import type {
IPairedItemData, IPairedItemData,
ICredentialTestFunctions, ICredentialTestFunctions,
BinaryHelperFunctions, BinaryHelperFunctions,
NodeHelperFunctions,
RequestHelperFunctions, RequestHelperFunctions,
FunctionsBase, FunctionsBase,
IExecuteFunctions, IExecuteFunctions,
@ -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 = ({ const getBinaryHelperFunctions = ({
executionId, executionId,
}: IWorkflowExecuteAdditionalData): BinaryHelperFunctions => ({ }: IWorkflowExecuteAdditionalData): BinaryHelperFunctions => ({
@ -2064,8 +2072,9 @@ const getBinaryHelperFunctions = ({
prepareBinaryData(binaryData, executionId!, filePath, mimeType), prepareBinaryData(binaryData, executionId!, filePath, mimeType),
setBinaryDataBuffer: async (data, binaryData) => setBinaryDataBuffer: async (data, binaryData) =>
setBinaryDataBuffer(data, binaryData, executionId!), setBinaryDataBuffer(data, binaryData, executionId!),
copyBinaryFile: async (filePath, fileName, mimeType) => copyBinaryFile: async () => {
copyBinaryFile(executionId!, filePath, fileName, mimeType), throw new Error('copyBinaryFile has been removed. Please upgrade this node');
},
}); });
/** /**
@ -2368,6 +2377,7 @@ export function getExecuteFunctions(
normalizeItems, normalizeItems,
constructExecutionMetaData, constructExecutionMetaData,
}, },
nodeHelpers: getNodeHelperFunctions(additionalData),
}; };
})(workflow, runExecutionData, connectionInputData, inputData, node) as IExecuteFunctions; })(workflow, runExecutionData, connectionInputData, inputData, node) as IExecuteFunctions;
} }
@ -2758,6 +2768,7 @@ export function getExecuteWebhookFunctions(
...getBinaryHelperFunctions(additionalData), ...getBinaryHelperFunctions(additionalData),
returnJsonArray, returnJsonArray,
}, },
nodeHelpers: getNodeHelperFunctions(additionalData),
}; };
})(workflow, node); })(workflow, node);
} }

View file

@ -603,7 +603,7 @@ export class Ftp implements INodeType {
const dataPropertyNameDownload = this.getNodeParameter('binaryPropertyName', i); const dataPropertyNameDownload = this.getNodeParameter('binaryPropertyName', i);
const filePathDownload = this.getNodeParameter('path', i) as string; 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, binaryFile.path,
filePathDownload, filePathDownload,
); );
@ -699,7 +699,7 @@ export class Ftp implements INodeType {
const dataPropertyNameDownload = this.getNodeParameter('binaryPropertyName', i); const dataPropertyNameDownload = this.getNodeParameter('binaryPropertyName', i);
const filePathDownload = this.getNodeParameter('path', i) as string; 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, binaryFile.path,
filePathDownload, filePathDownload,
); );

View file

@ -329,7 +329,7 @@ export class Ssh implements INodeType {
items[i] = newItem; items[i] = newItem;
items[i].binary![dataPropertyNameDownload] = await this.helpers.copyBinaryFile( items[i].binary![dataPropertyNameDownload] = await this.nodeHelpers.copyBinaryFile(
path, path,
parameterPath, parameterPath,
); );

View file

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

View file

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

View file

@ -676,12 +676,16 @@ export interface BinaryHelperFunctions {
mimeType?: string, mimeType?: string,
): Promise<IBinaryData>; ): Promise<IBinaryData>;
setBinaryDataBuffer(data: IBinaryData, binaryData: Buffer): 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>; binaryToBuffer(body: Buffer | Readable): Promise<Buffer>;
getBinaryStream(binaryDataId: string, chunkSize?: number): Readable; getBinaryStream(binaryDataId: string, chunkSize?: number): Readable;
getBinaryMetadata(binaryDataId: string): Promise<BinaryMetadata>; getBinaryMetadata(binaryDataId: string): Promise<BinaryMetadata>;
} }
export interface NodeHelperFunctions {
copyBinaryFile(filePath: string, fileName: string, mimeType?: string): Promise<IBinaryData>;
}
export interface RequestHelperFunctions { export interface RequestHelperFunctions {
request(uriOrObject: string | IDataObject | any, options?: IDataObject): Promise<any>; request(uriOrObject: string | IDataObject | any, options?: IDataObject): Promise<any>;
requestWithAuthentication( requestWithAuthentication(
@ -753,6 +757,7 @@ export type IExecuteFunctions = ExecuteFunctions.GetNodeParameterFn &
sendMessageToUI(message: any): void; sendMessageToUI(message: any): void;
sendResponse(response: IExecuteResponsePromiseData): void; sendResponse(response: IExecuteResponsePromiseData): void;
nodeHelpers: NodeHelperFunctions;
helpers: RequestHelperFunctions & helpers: RequestHelperFunctions &
BaseHelperFunctions & BaseHelperFunctions &
BinaryHelperFunctions & BinaryHelperFunctions &
@ -875,6 +880,7 @@ export interface IWebhookFunctions extends FunctionsBaseWithRequiredKeys<'getMod
outputData: INodeExecutionData[], outputData: INodeExecutionData[],
outputIndex?: number, outputIndex?: number,
): Promise<INodeExecutionData[][]>; ): Promise<INodeExecutionData[][]>;
nodeHelpers: NodeHelperFunctions;
helpers: RequestHelperFunctions & helpers: RequestHelperFunctions &
BaseHelperFunctions & BaseHelperFunctions &
BinaryHelperFunctions & BinaryHelperFunctions &