From 7a614b1e1feb2c57bc646b28d96528d32f135a6b Mon Sep 17 00:00:00 2001 From: Ricardo Espinoza Date: Tue, 22 Dec 2020 02:34:42 -0500 Subject: [PATCH] :zap: Add delete and rename operation (#1265) * :zap: Add delete and rename operation * :zap: Little bit cleanup on FTP-Node Co-authored-by: Jan Oberhauser --- packages/nodes-base/nodes/Ftp.node.ts | 111 +++++++++++++++++++++++++- 1 file changed, 108 insertions(+), 3 deletions(-) diff --git a/packages/nodes-base/nodes/Ftp.node.ts b/packages/nodes-base/nodes/Ftp.node.ts index 71a864bd02..ae728dac7c 100644 --- a/packages/nodes-base/nodes/Ftp.node.ts +++ b/packages/nodes-base/nodes/Ftp.node.ts @@ -97,6 +97,11 @@ export class Ftp implements INodeType { name: 'operation', type: 'options', options: [ + { + name: 'Delete', + value: 'delete', + description: 'Delete a file.', + }, { name: 'Download', value: 'download', @@ -107,6 +112,11 @@ export class Ftp implements INodeType { value: 'list', description: 'List folder content.', }, + { + name: 'Rename', + value: 'rename', + description: 'Rename/move oldPath to newPath.', + }, { name: 'Upload', value: 'upload', @@ -117,6 +127,25 @@ export class Ftp implements INodeType { description: 'Operation to perform.', }, + // ---------------------------------- + // delete + // ---------------------------------- + { + displayName: 'Path', + displayOptions: { + show: { + operation: [ + 'delete', + ], + }, + }, + name: 'path', + type: 'string', + default: '', + description: 'The file path of the file to delete. Has to contain the full path.', + required: true, + }, + // ---------------------------------- // download // ---------------------------------- @@ -152,6 +181,40 @@ export class Ftp implements INodeType { required: true, }, + // ---------------------------------- + // rename + // ---------------------------------- + { + displayName: 'Old Path', + displayOptions: { + show: { + operation: [ + 'rename', + ], + }, + }, + name: 'oldPath', + type: 'string', + default: '', + description: 'The old path', + required: true, + }, + { + displayName: 'New Path', + displayOptions: { + show: { + operation: [ + 'rename', + ], + }, + }, + name: 'newPath', + type: 'string', + default: '', + description: 'The new path', + required: true, + }, + // ---------------------------------- // upload // ---------------------------------- @@ -318,9 +381,10 @@ export class Ftp implements INodeType { items[i] = newItem; if (protocol === 'sftp') { - const path = this.getNodeParameter('path', i) as string; if (operation === 'list') { + const path = this.getNodeParameter('path', i) as string; + const recursive = this.getNodeParameter('recursive', i) as boolean; if (recursive) { @@ -333,7 +397,27 @@ export class Ftp implements INodeType { } } + if (operation === 'delete') { + const path = this.getNodeParameter('path', i) as string; + + responseData = await sftp!.delete(path); + + returnItems.push({ json: { success: true } }); + } + + if (operation === 'rename') { + const oldPath = this.getNodeParameter('oldPath', i) as string; + + const newPath = this.getNodeParameter('newPath', i) as string; + + responseData = await sftp!.rename(oldPath, newPath); + + returnItems.push({ json: { success: true } }); + } + if (operation === 'download') { + const path = this.getNodeParameter('path', i) as string; + responseData = await sftp!.get(path); const dataPropertyNameDownload = this.getNodeParameter('binaryPropertyName', i) as string; @@ -385,9 +469,9 @@ export class Ftp implements INodeType { if (protocol === 'ftp') { - const path = this.getNodeParameter('path', i) as string; - if (operation === 'list') { + const path = this.getNodeParameter('path', i) as string; + const recursive = this.getNodeParameter('recursive', i) as boolean; if (recursive) { @@ -400,7 +484,17 @@ export class Ftp implements INodeType { } } + if (operation === 'delete') { + const path = this.getNodeParameter('path', i) as string; + + responseData = await ftp!.delete(path); + + returnItems.push({ json: { success: true } }); + } + if (operation === 'download') { + const path = this.getNodeParameter('path', i) as string; + responseData = await ftp!.get(path); // Convert readable stream to buffer so that can be displayed properly @@ -420,6 +514,17 @@ export class Ftp implements INodeType { returnItems.push(items[i]); } + if (operation === 'rename') { + + const oldPath = this.getNodeParameter('oldPath', i) as string; + + const newPath = this.getNodeParameter('newPath', i) as string; + + responseData = await ftp!.rename(oldPath, newPath); + + returnItems.push({ json: { success: true } }); + } + if (operation === 'upload') { const remotePath = this.getNodeParameter('path', i) as string; const fileName = basename(remotePath);