From 50246d174a274fc9ba3dea44fc83c3605b4db691 Mon Sep 17 00:00:00 2001 From: Jonathan Bennetts Date: Sun, 15 May 2022 18:55:09 +0100 Subject: [PATCH] feat(Microsoft OneDrive Node): Add rename option for files and folders (#3224) --- .../Microsoft/OneDrive/FileDescription.ts | 42 +++++++++++++++++++ .../Microsoft/OneDrive/FolderDescription.ts | 42 +++++++++++++++++++ .../OneDrive/MicrosoftOneDrive.node.ts | 9 ++++ 3 files changed, 93 insertions(+) diff --git a/packages/nodes-base/nodes/Microsoft/OneDrive/FileDescription.ts b/packages/nodes-base/nodes/Microsoft/OneDrive/FileDescription.ts index 14132021d4..b0abc08c1b 100644 --- a/packages/nodes-base/nodes/Microsoft/OneDrive/FileDescription.ts +++ b/packages/nodes-base/nodes/Microsoft/OneDrive/FileDescription.ts @@ -35,6 +35,11 @@ export const fileOperations: INodeProperties[] = [ value: 'get', description: 'Get a file', }, + { + name: 'Rename', + value: 'rename', + description: 'Rename a file', + }, { name: 'Search', value: 'search', @@ -257,6 +262,43 @@ export const fileFields: INodeProperties[] = [ description: 'Field ID', }, /* -------------------------------------------------------------------------- */ +/* file:rename */ +/* -------------------------------------------------------------------------- */ +{ + displayName: 'Item ID', + name: 'itemId', + type: 'string', + displayOptions: { + show: { + operation: [ + 'rename', + ], + resource: [ + 'file', + ], + }, + }, + default: '', + description: 'ID of the file', +}, +{ + displayName: 'New Name', + name: 'newName', + type: 'string', + displayOptions: { + show: { + operation: [ + 'rename', + ], + resource: [ + 'file', + ], + }, + }, + default: '', + description: 'New name for file', +}, +/* -------------------------------------------------------------------------- */ /* file:search */ /* -------------------------------------------------------------------------- */ { diff --git a/packages/nodes-base/nodes/Microsoft/OneDrive/FolderDescription.ts b/packages/nodes-base/nodes/Microsoft/OneDrive/FolderDescription.ts index 0b31456ae6..0fefc74c9e 100644 --- a/packages/nodes-base/nodes/Microsoft/OneDrive/FolderDescription.ts +++ b/packages/nodes-base/nodes/Microsoft/OneDrive/FolderDescription.ts @@ -30,6 +30,11 @@ export const folderOperations: INodeProperties[] = [ value: 'getChildren', description: 'Get items inside a folder', }, + { + name: 'Rename', + value: 'rename', + description: 'Rename a folder', + }, { name: 'Search', value: 'search', @@ -117,6 +122,43 @@ export const folderFields: INodeProperties[] = [ default: '', }, /* -------------------------------------------------------------------------- */ +/* folder:rename */ +/* -------------------------------------------------------------------------- */ +{ + displayName: 'Item ID', + name: 'itemId', + type: 'string', + displayOptions: { + show: { + operation: [ + 'rename', + ], + resource: [ + 'folder', + ], + }, + }, + default: '', + description: 'ID of the folder', +}, +{ + displayName: 'New Name', + name: 'newName', + type: 'string', + displayOptions: { + show: { + operation: [ + 'rename', + ], + resource: [ + 'folder', + ], + }, + }, + default: '', + description: 'New name for folder', +}, +/* -------------------------------------------------------------------------- */ /* folder:search */ /* -------------------------------------------------------------------------- */ { diff --git a/packages/nodes-base/nodes/Microsoft/OneDrive/MicrosoftOneDrive.node.ts b/packages/nodes-base/nodes/Microsoft/OneDrive/MicrosoftOneDrive.node.ts index f4c6a63757..732496ab02 100644 --- a/packages/nodes-base/nodes/Microsoft/OneDrive/MicrosoftOneDrive.node.ts +++ b/packages/nodes-base/nodes/Microsoft/OneDrive/MicrosoftOneDrive.node.ts @@ -271,6 +271,15 @@ export class MicrosoftOneDrive implements INodeType { returnData.push(responseData); } } + if (resource === 'file' || resource === 'folder') { + if (operation === 'rename') { + const itemId = this.getNodeParameter('itemId', i) as string; + const newName = this.getNodeParameter('newName', i) as string; + const body = {name: newName}; + responseData = await microsoftApiRequest.call(this, 'PATCH', `/drive/items/${itemId}`, body); + returnData.push(responseData as IDataObject); + } + } } catch (error) { if (this.continueOnFail()) { if (resource === 'file' && operation === 'download') {