mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-10 06:34:05 -08:00
⚡ Add share operation to OneDrive Node (#1044)
This commit is contained in:
parent
6c6e7625b9
commit
7f33ff8c3c
|
@ -1,4 +1,6 @@
|
|||
import { INodeProperties } from 'n8n-workflow';
|
||||
import {
|
||||
INodeProperties,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
export const fileOperations = [
|
||||
{
|
||||
|
@ -38,6 +40,11 @@ export const fileOperations = [
|
|||
value: 'search',
|
||||
description: 'Search a file',
|
||||
},
|
||||
{
|
||||
name: 'Share',
|
||||
value: 'share',
|
||||
description: 'Share a file',
|
||||
},
|
||||
{
|
||||
name: 'Upload',
|
||||
value: 'upload',
|
||||
|
@ -273,6 +280,84 @@ export const fileFields = [
|
|||
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 */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
import { INodeProperties } from 'n8n-workflow';
|
||||
import {
|
||||
INodeProperties,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
export const folderOperations = [
|
||||
{
|
||||
|
@ -28,6 +30,11 @@ export const folderOperations = [
|
|||
value: 'search',
|
||||
description: 'Search a folder',
|
||||
},
|
||||
{
|
||||
name: 'Share',
|
||||
value: 'share',
|
||||
description: 'Share a folder',
|
||||
},
|
||||
],
|
||||
default: 'getChildren',
|
||||
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
|
||||
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[];
|
||||
|
|
|
@ -33,7 +33,6 @@ export async function microsoftApiRequest(this: IExecuteFunctions | IExecuteSing
|
|||
if (Object.keys(body).length === 0) {
|
||||
delete options.body;
|
||||
}
|
||||
|
||||
//@ts-ignore
|
||||
return await this.helpers.requestOAuth2.call(this, 'microsoftOneDriveOAuth2Api', options);
|
||||
} catch (error) {
|
||||
|
|
|
@ -159,6 +159,18 @@ export class MicrosoftOneDrive implements INodeType {
|
|||
responseData = responseData.filter((item: IDataObject) => item.file);
|
||||
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
|
||||
if (operation === 'upload') {
|
||||
const parentId = this.getNodeParameter('parentId', i) as string;
|
||||
|
@ -221,6 +233,18 @@ export class MicrosoftOneDrive implements INodeType {
|
|||
responseData = responseData.filter((item: IDataObject) => item.folder);
|
||||
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') {
|
||||
|
|
Loading…
Reference in a new issue