🔀 Merge branch 'onedrive-creatt push origin mastere-folder-hierarchy'

This commit is contained in:
Jan Oberhauser 2021-10-20 22:08:15 -05:00
commit 3898b86cc9
2 changed files with 21 additions and 13 deletions

View file

@ -56,6 +56,7 @@ export const folderFields = [
name: 'name', name: 'name',
required: true, required: true,
type: 'string', type: 'string',
placeholder: '/Pictures/2021',
displayOptions: { displayOptions: {
show: { show: {
operation: [ operation: [
@ -67,7 +68,7 @@ export const folderFields = [
}, },
}, },
default: '', default: '',
description: `Folder's name`, description: 'The name or path of the folder',
}, },
{ {
displayName: 'Options', displayName: 'Options',

View file

@ -209,17 +209,24 @@ export class MicrosoftOneDrive implements INodeType {
if (resource === 'folder') { if (resource === 'folder') {
//https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_post_children?view=odsp-graph-online //https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_post_children?view=odsp-graph-online
if (operation === 'create') { 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 options = this.getNodeParameter('options', i) as IDataObject;
let parentFolderId = options.parentFolderId ? options.parentFolderId : null;
for (const name of names) {
const body: IDataObject = { const body: IDataObject = {
name, name,
folder: {}, folder: {},
}; };
let endpoint = '/drive/root/children'; let endpoint = '/drive/root/children';
if (options.parentFolderId) { if (parentFolderId) {
endpoint = `/drive/items/${options.parentFolderId}/children`; endpoint = `/drive/items/${parentFolderId}/children`;
} }
responseData = await microsoftApiRequest.call(this, 'POST', endpoint, body); responseData = await microsoftApiRequest.call(this, 'POST', endpoint, body);
if (!responseData.id) {
break;
}
parentFolderId = responseData.id;
}
returnData.push(responseData); returnData.push(responseData);
} }
//https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_delete?view=odsp-graph-online //https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_delete?view=odsp-graph-online