Added create folder operation

This commit is contained in:
ricardo 2020-03-29 22:39:43 -04:00
parent fc5df1e294
commit 79fda65e7e
3 changed files with 112 additions and 0 deletions

View file

@ -0,0 +1,101 @@
import { INodeProperties } from "n8n-workflow";
export const folderOperations = [
{
displayName: 'Operation',
name: 'operation',
type: 'options',
displayOptions: {
show: {
resource: [
'folder',
],
},
},
options: [
{
name: 'Create',
value: 'create',
description: 'Create a folder',
},
{
name: 'Get Children',
value: 'getChildren',
description: 'Get items inside a folder',
},
{
name: 'Search',
value: 'search',
description: 'Search a folder',
},
],
default: 'getChildren',
description: 'The operation to perform.',
},
] as INodeProperties[];
export const folderFields = [
/* -------------------------------------------------------------------------- */
/* folder:create */
/* -------------------------------------------------------------------------- */
{
displayName: 'Name',
name: 'name',
required: true,
type: 'string',
displayOptions: {
show: {
operation: [
'create',
],
resource: [
'folder',
],
},
},
default: '',
description: `Folder's name`,
},
/* -------------------------------------------------------------------------- */
/* folder:getChildren */
/* -------------------------------------------------------------------------- */
{
displayName: 'Folder ID',
name: 'folderId',
type: 'string',
displayOptions: {
show: {
operation: [
'getChildren',
],
resource: [
'folder',
],
},
},
default: '',
description: 'Folder ID',
},
/* -------------------------------------------------------------------------- */
/* folder:search */
/* -------------------------------------------------------------------------- */
{
displayName: 'Query',
name: 'query',
type: 'string',
displayOptions: {
show: {
operation: [
'search',
],
resource: [
'folder',
],
},
},
default: '',
description: `The query text used to search for items. Values may be matched
across several fields including filename, metadata, and file content.`,
},
] as INodeProperties[];

View file

@ -33,6 +33,7 @@ export async function microsoftApiRequest(this: IExecuteFunctions | IExecuteSing
if (Object.keys(body).length === 0) {
delete options.body;
}
//@ts-ignore
return await this.helpers.requestOAuth.call(this, 'microsoftOneDriveOAuth2Api', options);
} catch (error) {

View file

@ -193,6 +193,16 @@ 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 body: IDataObject = {
name,
folder: {},
};
responseData = await microsoftApiRequest.call(this, 'POST', '/drive/root/children', body);
returnData.push(responseData);
}
//https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_list_children?view=odsp-graph-online
if (operation === 'getChildren') {
const folderId = this.getNodeParameter('folderId', i) as string;