From 49fbea75516a7ff6600c86f51aaaa9aff48c0387 Mon Sep 17 00:00:00 2001 From: Roberto Damiani Date: Sun, 10 Oct 2021 02:42:25 +0200 Subject: [PATCH] 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