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
6 changed files with 27 additions and 10 deletions

View File

@@ -49,6 +49,7 @@ import type {
IPairedItemData,
ICredentialTestFunctions,
BinaryHelperFunctions,
NodeHelperFunctions,
RequestHelperFunctions,
FunctionsBase,
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 = ({
executionId,
}: IWorkflowExecuteAdditionalData): BinaryHelperFunctions => ({
@@ -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');
},
});
/**
@@ -2368,6 +2377,7 @@ export function getExecuteFunctions(
normalizeItems,
constructExecutionMetaData,
},
nodeHelpers: getNodeHelperFunctions(additionalData),
};
})(workflow, runExecutionData, connectionInputData, inputData, node) as IExecuteFunctions;
}
@@ -2758,6 +2768,7 @@ export function getExecuteWebhookFunctions(
...getBinaryHelperFunctions(additionalData),
returnJsonArray,
},
nodeHelpers: getNodeHelperFunctions(additionalData),
};
})(workflow, node);
}

View File

@@ -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,
);
@@ -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,
);

View File

@@ -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,
);

View File

@@ -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,
@@ -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,
);

View File

@@ -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,
@@ -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,
);

View File

@@ -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(
@@ -753,6 +757,7 @@ export type IExecuteFunctions = ExecuteFunctions.GetNodeParameterFn &
sendMessageToUI(message: any): void;
sendResponse(response: IExecuteResponsePromiseData): void;
nodeHelpers: NodeHelperFunctions;
helpers: RequestHelperFunctions &
BaseHelperFunctions &
BinaryHelperFunctions &
@@ -875,6 +880,7 @@ export interface IWebhookFunctions extends FunctionsBaseWithRequiredKeys<'getMod
outputData: INodeExecutionData[],
outputIndex?: number,
): Promise<INodeExecutionData[][]>;
nodeHelpers: NodeHelperFunctions;
helpers: RequestHelperFunctions &
BaseHelperFunctions &
BinaryHelperFunctions &