mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-24 20:24:05 -08:00
⚡ Add delete and rename operation (#1265)
* ⚡ Add delete and rename operation * ⚡ Little bit cleanup on FTP-Node Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com>
This commit is contained in:
parent
54bd145a3b
commit
7a614b1e1f
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue