mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
fix(core & function nodes): Update function nodes to work with binary-data-mode 'filesystem'. (#3845)
* Initial Fix * Self-Review #1 * Lint * Added support for FunctionItem. Minor updates. * Self-review * review comments. Added testing. * Self Review * Fixed memory handling on data manager use. * Fixes for unnecessary memory leaks.
This commit is contained in:
@@ -75,22 +75,70 @@ return item;`,
|
||||
};
|
||||
|
||||
for (let itemIndex = 0; itemIndex < length; itemIndex++) {
|
||||
const mode = this.getMode();
|
||||
|
||||
try {
|
||||
item = items[itemIndex];
|
||||
item.index = itemIndex;
|
||||
|
||||
// Copy the items as they may get changed in the functions
|
||||
item = JSON.parse(JSON.stringify(item));
|
||||
|
||||
// Define the global objects for the custom function
|
||||
const sandbox = {
|
||||
/** @deprecated for removal - replaced by getBinaryDataAsync() */
|
||||
getBinaryData: (): IBinaryKeyData | undefined => {
|
||||
if (mode === 'manual') {
|
||||
this.sendMessageToUI(
|
||||
'getBinaryData(...) is deprecated and will be removed in a future version. Please consider switching to getBinaryDataAsync(...) instead.',
|
||||
);
|
||||
}
|
||||
return item.binary;
|
||||
},
|
||||
/** @deprecated for removal - replaced by setBinaryDataAsync() */
|
||||
setBinaryData: async (data: IBinaryKeyData) => {
|
||||
if (mode === 'manual') {
|
||||
this.sendMessageToUI(
|
||||
'setBinaryData(...) is deprecated and will be removed in a future version. Please consider switching to setBinaryDataAsync(...) instead.',
|
||||
);
|
||||
}
|
||||
item.binary = data;
|
||||
},
|
||||
getNodeParameter: this.getNodeParameter,
|
||||
getWorkflowStaticData: this.getWorkflowStaticData,
|
||||
helpers: this.helpers,
|
||||
item: item.json,
|
||||
setBinaryData: (data: IBinaryKeyData) => {
|
||||
getBinaryDataAsync: async (): Promise<IBinaryKeyData | undefined> => {
|
||||
// Fetch Binary Data, if available. Cannot check item with `if (item?.index)`, as index may be 0.
|
||||
if (item?.binary && item?.index !== undefined && item?.index !== null) {
|
||||
for (const binaryPropertyName of Object.keys(item.binary)) {
|
||||
item.binary[binaryPropertyName].data = (
|
||||
await this.helpers.getBinaryDataBuffer(item.index, binaryPropertyName)
|
||||
)?.toString('base64');
|
||||
}
|
||||
}
|
||||
// Retrun Data
|
||||
return item.binary;
|
||||
},
|
||||
setBinaryDataAsync: async (data: IBinaryKeyData) => {
|
||||
// Ensure data is present
|
||||
if (!data) {
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
'No data was provided to setBinaryDataAsync (data: IBinaryKeyData).',
|
||||
);
|
||||
}
|
||||
|
||||
// Set Binary Data
|
||||
for (const binaryPropertyName of Object.keys(data)) {
|
||||
const binaryItem = data[binaryPropertyName];
|
||||
data[binaryPropertyName] = await this.helpers.setBinaryDataBuffer(
|
||||
binaryItem,
|
||||
Buffer.from(binaryItem.data, 'base64'),
|
||||
);
|
||||
}
|
||||
|
||||
// Set Item Reference
|
||||
item.binary = data;
|
||||
},
|
||||
};
|
||||
@@ -99,8 +147,6 @@ return item;`,
|
||||
const dataProxy = this.getWorkflowDataProxy(itemIndex);
|
||||
Object.assign(sandbox, dataProxy);
|
||||
|
||||
const mode = this.getMode();
|
||||
|
||||
const options = {
|
||||
console: mode === 'manual' ? 'redirect' : 'inherit',
|
||||
sandbox,
|
||||
|
||||
Reference in New Issue
Block a user