From 49fbea75516a7ff6600c86f51aaaa9aff48c0387 Mon Sep 17 00:00:00 2001 From: Roberto Damiani Date: Sun, 10 Oct 2021 02:42:25 +0200 Subject: [PATCH 1/4] onedrive folders hierarchy creation support --- .../Microsoft/OneDrive/FolderDescription.ts | 2 +- .../OneDrive/MicrosoftOneDrive.node.ts | 25 ++++++++++++------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/packages/nodes-base/nodes/Microsoft/OneDrive/FolderDescription.ts b/packages/nodes-base/nodes/Microsoft/OneDrive/FolderDescription.ts index 16f1ccdf4d..f910265bb0 100644 --- a/packages/nodes-base/nodes/Microsoft/OneDrive/FolderDescription.ts +++ b/packages/nodes-base/nodes/Microsoft/OneDrive/FolderDescription.ts @@ -67,7 +67,7 @@ export const folderFields = [ }, }, default: '', - description: `Folder's name`, + description: `Folder's name, or a folders slash (/) separated hierarchy`, }, { displayName: 'Options', diff --git a/packages/nodes-base/nodes/Microsoft/OneDrive/MicrosoftOneDrive.node.ts b/packages/nodes-base/nodes/Microsoft/OneDrive/MicrosoftOneDrive.node.ts index da16900725..62cc9e0494 100644 --- a/packages/nodes-base/nodes/Microsoft/OneDrive/MicrosoftOneDrive.node.ts +++ b/packages/nodes-base/nodes/Microsoft/OneDrive/MicrosoftOneDrive.node.ts @@ -209,17 +209,24 @@ export class MicrosoftOneDrive implements INodeType { if (resource === 'folder') { //https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_post_children?view=odsp-graph-online if (operation === 'create') { - const name = this.getNodeParameter('name', i) as string; + const names = (this.getNodeParameter('name', i) as string).split("/").filter( s => s.trim() != "" ); const options = this.getNodeParameter('options', i) as IDataObject; - const body: IDataObject = { - name, - folder: {}, - }; - let endpoint = '/drive/root/children'; - if (options.parentFolderId) { - endpoint = `/drive/items/${options.parentFolderId}/children`; + let parentFolderId = options.parentFolderId ? options.parentFolderId : null; + for( let name of names ) { + let body: IDataObject = { + name, + folder: {}, + }; + let endpoint = '/drive/root/children'; + if (parentFolderId) { + endpoint = `/drive/items/${parentFolderId}/children`; + } + responseData = await microsoftApiRequest.call(this, 'POST', endpoint, body); + if( !responseData.id ) { + break; + } + parentFolderId = responseData.id; } - responseData = await microsoftApiRequest.call(this, 'POST', endpoint, body); returnData.push(responseData); } //https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_delete?view=odsp-graph-online From c888b0512ac81c8007df6fb0689ceb279c83199b Mon Sep 17 00:00:00 2001 From: ricardo Date: Sun, 17 Oct 2021 09:28:29 -0400 Subject: [PATCH 2/4] :zap: Small change to #2305 --- .../Microsoft/OneDrive/MicrosoftOneDrive.node.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/nodes-base/nodes/Microsoft/OneDrive/MicrosoftOneDrive.node.ts b/packages/nodes-base/nodes/Microsoft/OneDrive/MicrosoftOneDrive.node.ts index 62cc9e0494..d71ce3fb9b 100644 --- a/packages/nodes-base/nodes/Microsoft/OneDrive/MicrosoftOneDrive.node.ts +++ b/packages/nodes-base/nodes/Microsoft/OneDrive/MicrosoftOneDrive.node.ts @@ -97,7 +97,7 @@ export class MicrosoftOneDrive implements INodeType { body.name = additionalFields.name as string; } responseData = await microsoftApiRequest.call(this, 'POST', `/drive/items/${fileId}/copy`, body, {}, undefined, {}, { json: true, resolveWithFullResponse: true }); - responseData = { location : responseData.headers.location }; + responseData = { location: responseData.headers.location }; returnData.push(responseData as IDataObject); } //https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_delete?view=odsp-graph-online @@ -193,7 +193,7 @@ export class MicrosoftOneDrive implements INodeType { const binaryData = (items[i].binary as IBinaryKeyData)[binaryPropertyName]; const body = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName); - responseData = await microsoftApiRequest.call(this, 'PUT', `/drive/items/${parentId}:/${fileName || binaryData.fileName}:/content`, body, {}, undefined, { 'Content-Type': binaryData.mimeType, 'Content-length': body.length }, {} ); + responseData = await microsoftApiRequest.call(this, 'PUT', `/drive/items/${parentId}:/${fileName || binaryData.fileName}:/content`, body, {}, undefined, { 'Content-Type': binaryData.mimeType, 'Content-length': body.length }, {}); returnData.push(JSON.parse(responseData) as IDataObject); } else { @@ -201,7 +201,7 @@ export class MicrosoftOneDrive implements INodeType { if (fileName === '') { throw new NodeOperationError(this.getNode(), 'File name must be set!'); } - responseData = await microsoftApiRequest.call(this, 'PUT', `/drive/items/${parentId}:/${fileName}:/content`, body , {}, undefined, { 'Content-Type': 'text/plain' } ); + responseData = await microsoftApiRequest.call(this, 'PUT', `/drive/items/${parentId}:/${fileName}:/content`, body, {}, undefined, { 'Content-Type': 'text/plain' }); returnData.push(responseData as IDataObject); } } @@ -209,11 +209,11 @@ export class MicrosoftOneDrive implements INodeType { if (resource === 'folder') { //https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_post_children?view=odsp-graph-online if (operation === 'create') { - const names = (this.getNodeParameter('name', i) as string).split("/").filter( s => s.trim() != "" ); + const names = (this.getNodeParameter('name', i) as string).split('/').filter(s => s.trim() !== ''); const options = this.getNodeParameter('options', i) as IDataObject; let parentFolderId = options.parentFolderId ? options.parentFolderId : null; - for( let name of names ) { - let body: IDataObject = { + for (const name of names) { + const body: IDataObject = { name, folder: {}, }; @@ -222,7 +222,7 @@ export class MicrosoftOneDrive implements INodeType { endpoint = `/drive/items/${parentFolderId}/children`; } responseData = await microsoftApiRequest.call(this, 'POST', endpoint, body); - if( !responseData.id ) { + if (!responseData.id) { break; } parentFolderId = responseData.id; From 467ecdbe4cbbf0e4879d3b6c1859b49990a16957 Mon Sep 17 00:00:00 2001 From: ricardo Date: Wed, 20 Oct 2021 22:24:10 -0400 Subject: [PATCH 3/4] :zap: Improve description --- .../nodes-base/nodes/Microsoft/OneDrive/FolderDescription.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/nodes-base/nodes/Microsoft/OneDrive/FolderDescription.ts b/packages/nodes-base/nodes/Microsoft/OneDrive/FolderDescription.ts index f910265bb0..471faa2abf 100644 --- a/packages/nodes-base/nodes/Microsoft/OneDrive/FolderDescription.ts +++ b/packages/nodes-base/nodes/Microsoft/OneDrive/FolderDescription.ts @@ -56,6 +56,7 @@ export const folderFields = [ name: 'name', required: true, type: 'string', + placeholder: '/root/folder', displayOptions: { show: { operation: [ @@ -67,7 +68,7 @@ export const folderFields = [ }, }, default: '', - description: `Folder's name, or a folders slash (/) separated hierarchy`, + description: 'The name or path of the folder', }, { displayName: 'Options', From 2c278bf8e2af3ad763a54eb06e677310ad6ecc1e Mon Sep 17 00:00:00 2001 From: Jan Oberhauser Date: Wed, 20 Oct 2021 22:07:33 -0500 Subject: [PATCH 4/4] :zap: Rename placeholder --- .../nodes-base/nodes/Microsoft/OneDrive/FolderDescription.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/nodes-base/nodes/Microsoft/OneDrive/FolderDescription.ts b/packages/nodes-base/nodes/Microsoft/OneDrive/FolderDescription.ts index 471faa2abf..2c6f8b5190 100644 --- a/packages/nodes-base/nodes/Microsoft/OneDrive/FolderDescription.ts +++ b/packages/nodes-base/nodes/Microsoft/OneDrive/FolderDescription.ts @@ -56,7 +56,7 @@ export const folderFields = [ name: 'name', required: true, type: 'string', - placeholder: '/root/folder', + placeholder: '/Pictures/2021', displayOptions: { show: { operation: [