Add share operation to OneDrive Node (#1044)

This commit is contained in:
Ricardo Espinoza 2020-10-13 05:08:07 -04:00 committed by GitHub
parent 6c6e7625b9
commit 7f33ff8c3c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 196 additions and 3 deletions

View file

@ -1,4 +1,6 @@
import { INodeProperties } from 'n8n-workflow'; import {
INodeProperties,
} from 'n8n-workflow';
export const fileOperations = [ export const fileOperations = [
{ {
@ -38,6 +40,11 @@ export const fileOperations = [
value: 'search', value: 'search',
description: 'Search a file', description: 'Search a file',
}, },
{
name: 'Share',
value: 'share',
description: 'Share a file',
},
{ {
name: 'Upload', name: 'Upload',
value: 'upload', value: 'upload',
@ -273,6 +280,84 @@ export const fileFields = [
across several fields including filename, metadata, and file content.`, across several fields including filename, metadata, and file content.`,
}, },
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* file:share */
/* -------------------------------------------------------------------------- */
{
displayName: 'File ID',
name: 'fileId',
type: 'string',
displayOptions: {
show: {
operation: [
'share',
],
resource: [
'file',
],
},
},
default: '',
description: 'File ID',
},
{
displayName: 'Type',
name: 'type',
type: 'options',
options: [
{
name: 'View',
value: 'view',
},
{
name: 'Edit',
value: 'edit',
},
{
name: 'Embed',
value: 'embed',
},
],
displayOptions: {
show: {
operation: [
'share',
],
resource: [
'file',
],
},
},
default: '',
description: 'The type of sharing link to create',
},
{
displayName: 'Scope',
name: 'scope',
type: 'options',
options: [
{
name: 'Anonymous',
value: 'anonymous',
},
{
name: 'Organization',
value: 'organization',
},
],
displayOptions: {
show: {
operation: [
'share',
],
resource: [
'file',
],
},
},
default: '',
description: 'The type of sharing link to create',
},
/* -------------------------------------------------------------------------- */
/* file:upload */ /* file:upload */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
{ {

View file

@ -1,4 +1,6 @@
import { INodeProperties } from 'n8n-workflow'; import {
INodeProperties,
} from 'n8n-workflow';
export const folderOperations = [ export const folderOperations = [
{ {
@ -28,6 +30,11 @@ export const folderOperations = [
value: 'search', value: 'search',
description: 'Search a folder', description: 'Search a folder',
}, },
{
name: 'Share',
value: 'share',
description: 'Share a folder',
},
], ],
default: 'getChildren', default: 'getChildren',
description: 'The operation to perform.', description: 'The operation to perform.',
@ -124,4 +131,82 @@ export const folderFields = [
description: `The query text used to search for items. Values may be matched description: `The query text used to search for items. Values may be matched
across several fields including filename, metadata, and file content.`, across several fields including filename, metadata, and file content.`,
}, },
/* -------------------------------------------------------------------------- */
/* folder:share */
/* -------------------------------------------------------------------------- */
{
displayName: 'Folder ID',
name: 'folderId',
type: 'string',
displayOptions: {
show: {
operation: [
'share',
],
resource: [
'folder',
],
},
},
default: '',
description: 'File ID',
},
{
displayName: 'Type',
name: 'type',
type: 'options',
options: [
{
name: 'View',
value: 'view',
},
{
name: 'Edit',
value: 'edit',
},
{
name: 'Embed',
value: 'embed',
},
],
displayOptions: {
show: {
operation: [
'share',
],
resource: [
'folder',
],
},
},
default: '',
description: 'The type of sharing link to create',
},
{
displayName: 'Scope',
name: 'scope',
type: 'options',
options: [
{
name: 'Anonymous',
value: 'anonymous',
},
{
name: 'Organization',
value: 'organization',
},
],
displayOptions: {
show: {
operation: [
'share',
],
resource: [
'folder',
],
},
},
default: '',
description: 'The type of sharing link to create',
},
] as INodeProperties[]; ] as INodeProperties[];

View file

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

View file

@ -159,6 +159,18 @@ export class MicrosoftOneDrive implements INodeType {
responseData = responseData.filter((item: IDataObject) => item.file); responseData = responseData.filter((item: IDataObject) => item.file);
returnData.push.apply(returnData, responseData as IDataObject[]); returnData.push.apply(returnData, responseData as IDataObject[]);
} }
//https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_createlink?view=odsp-graph-online
if (operation === 'share') {
const fileId = this.getNodeParameter('fileId', i) as string;
const type = this.getNodeParameter('type', i) as string;
const scope = this.getNodeParameter('scope', i) as string;
const body: IDataObject = {
type,
scope,
};
responseData = await microsoftApiRequest.call(this, 'POST', `/drive/items/${fileId}/createLink`, body);
returnData.push(responseData);
}
//https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_put_content?view=odsp-graph-online#example-upload-a-new-file //https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_put_content?view=odsp-graph-online#example-upload-a-new-file
if (operation === 'upload') { if (operation === 'upload') {
const parentId = this.getNodeParameter('parentId', i) as string; const parentId = this.getNodeParameter('parentId', i) as string;
@ -221,6 +233,18 @@ export class MicrosoftOneDrive implements INodeType {
responseData = responseData.filter((item: IDataObject) => item.folder); responseData = responseData.filter((item: IDataObject) => item.folder);
returnData.push.apply(returnData, responseData as IDataObject[]); returnData.push.apply(returnData, responseData as IDataObject[]);
} }
//https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_createlink?view=odsp-graph-online
if (operation === 'share') {
const folderId = this.getNodeParameter('folderId', i) as string;
const type = this.getNodeParameter('type', i) as string;
const scope = this.getNodeParameter('scope', i) as string;
const body: IDataObject = {
type,
scope,
};
responseData = await microsoftApiRequest.call(this, 'POST', `/drive/items/${folderId}/createLink`, body);
returnData.push(responseData);
}
} }
} }
if (resource === 'file' && operation === 'download') { if (resource === 'file' && operation === 'download') {