Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(FTP Node): Fix "Maximum call stack size exceeded" error when dealing with too many files #8657

Merged
merged 1 commit into from
Feb 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 30 additions & 37 deletions packages/nodes-base/nodes/Ftp/Ftp.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -502,9 +502,7 @@ export class Ftp implements INodeType {

async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
const items = this.getInputData();
// const returnData: IDataObject[] = [];
const returnItems: INodeExecutionData[] = [];
let responseData;
let returnItems: INodeExecutionData[] = [];
const operation = this.getNodeParameter('operation', 0);

let credentials: ICredentialDataDecryptedObject | undefined = undefined;
Expand Down Expand Up @@ -569,38 +567,35 @@ export class Ftp implements INodeType {

const recursive = this.getNodeParameter('recursive', i) as boolean;

let responseData: sftpClient.FileInfo[];
if (recursive) {
responseData = await callRecursiveList(path, sftp!, normalizeSFtpItem);
const executionData = this.helpers.constructExecutionMetaData(
this.helpers.returnJsonArray(responseData as unknown as IDataObject[]),
{ itemData: { item: i } },
);
returnItems.push.apply(returnItems, executionData);
} else {
responseData = await sftp!.list(path);
responseData.forEach((item) => normalizeSFtpItem(item, path));
const executionData = this.helpers.constructExecutionMetaData(
this.helpers.returnJsonArray(responseData as unknown as IDataObject[]),
{ itemData: { item: i } },
);
returnItems.push.apply(returnItems, executionData);
}

const executionData = this.helpers.constructExecutionMetaData(
this.helpers.returnJsonArray(responseData as unknown as IDataObject[]),
{ itemData: { item: i } },
);
returnItems = returnItems.concat(executionData);
}

if (operation === 'delete') {
const path = this.getNodeParameter('path', i) as string;
const options = this.getNodeParameter('options', i);

if (options.folder === true) {
responseData = await sftp!.rmdir(path, !!options.recursive);
await sftp!.rmdir(path, !!options.recursive);
} else {
responseData = await sftp!.delete(path);
await sftp!.delete(path);
}
const executionData = this.helpers.constructExecutionMetaData(
[{ json: { success: true } }],
{ itemData: { item: i } },
);
returnItems.push(...executionData);
returnItems = returnItems.concat(executionData);
}

if (operation === 'rename') {
Expand All @@ -614,12 +609,12 @@ export class Ftp implements INodeType {
await recursivelyCreateSftpDirs(sftp!, newPath);
}

responseData = await sftp!.rename(oldPath, newPath);
await sftp!.rename(oldPath, newPath);
const executionData = this.helpers.constructExecutionMetaData(
[{ json: { success: true } }],
{ itemData: { item: i } },
);
returnItems.push(...executionData);
returnItems = returnItems.concat(executionData);
}

if (operation === 'download') {
Expand All @@ -640,7 +635,7 @@ export class Ftp implements INodeType {
this.helpers.returnJsonArray(items[i]),
{ itemData: { item: i } },
);
returnItems.push(...executionData);
returnItems = returnItems.concat(executionData);
} finally {
await binaryFile.cleanup();
}
Expand Down Expand Up @@ -671,7 +666,7 @@ export class Ftp implements INodeType {
this.helpers.returnJsonArray(items[i]),
{ itemData: { item: i } },
);
returnItems.push(...executionData);
returnItems = returnItems.concat(executionData);
}
}

Expand All @@ -681,40 +676,38 @@ export class Ftp implements INodeType {

const recursive = this.getNodeParameter('recursive', i) as boolean;

let responseData;
if (recursive) {
responseData = await callRecursiveList(path, ftp!, normalizeFtpItem);
const executionData = this.helpers.constructExecutionMetaData(
this.helpers.returnJsonArray(responseData as unknown as IDataObject[]),
{ itemData: { item: i } },
);
returnItems.push.apply(returnItems, executionData);
} else {
responseData = await ftp!.list(path);
responseData.forEach((item) =>
normalizeFtpItem(item as ftpClient.ListingElement, path),
);
const executionData = this.helpers.constructExecutionMetaData(
this.helpers.returnJsonArray(responseData as unknown as IDataObject[]),
{ itemData: { item: i } },
);
returnItems.push.apply(returnItems, executionData);
}

const executionData = this.helpers.constructExecutionMetaData(
this.helpers.returnJsonArray(responseData as unknown as IDataObject[]),
{ itemData: { item: i } },
);
returnItems = returnItems.concat(executionData);
}

if (operation === 'delete') {
const path = this.getNodeParameter('path', i) as string;
const options = this.getNodeParameter('options', i);

if (options.folder === true) {
responseData = await ftp!.rmdir(path, !!options.recursive);
await ftp!.rmdir(path, !!options.recursive);
} else {
responseData = await ftp!.delete(path);
await ftp!.delete(path);
}

const executionData = this.helpers.constructExecutionMetaData(
[{ json: { success: true } }],
{ itemData: { item: i } },
);
returnItems.push(...executionData);
returnItems = returnItems.concat(executionData);
}

if (operation === 'download') {
Expand All @@ -736,7 +729,7 @@ export class Ftp implements INodeType {
this.helpers.returnJsonArray(items[i]),
{ itemData: { item: i } },
);
returnItems.push(...executionData);
returnItems = returnItems.concat(executionData);
} finally {
await binaryFile.cleanup();
}
Expand All @@ -747,12 +740,12 @@ export class Ftp implements INodeType {

const newPath = this.getNodeParameter('newPath', i) as string;

responseData = await ftp!.rename(oldPath, newPath);
await ftp!.rename(oldPath, newPath);
const executionData = this.helpers.constructExecutionMetaData(
[{ json: { success: true } }],
{ itemData: { item: i } },
);
returnItems.push(...executionData);
returnItems = returnItems.concat(executionData);
}

if (operation === 'upload') {
Expand Down Expand Up @@ -801,7 +794,7 @@ export class Ftp implements INodeType {
this.helpers.returnJsonArray(items[i]),
{ itemData: { item: i } },
);
returnItems.push(...executionData);
returnItems = returnItems.concat(executionData);
}
}
}
Expand Down
Loading