mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
Reverted "prettier" styling
This commit is contained in:
parent
dc6cf5b9a7
commit
95d0eb6313
|
@ -1,12 +1,18 @@
|
||||||
import { BINARY_ENCODING, IExecuteFunctions } from 'n8n-core';
|
import {
|
||||||
|
BINARY_ENCODING,
|
||||||
|
IExecuteFunctions,
|
||||||
|
} from 'n8n-core';
|
||||||
import {
|
import {
|
||||||
IDataObject,
|
IDataObject,
|
||||||
|
INodeTypeDescription,
|
||||||
INodeExecutionData,
|
INodeExecutionData,
|
||||||
INodeType,
|
INodeType,
|
||||||
INodeTypeDescription
|
|
||||||
} from 'n8n-workflow';
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
|
import { OptionsWithUri } from 'request';
|
||||||
import { dropboxApiRequest } from './GenericFunctions';
|
import { dropboxApiRequest } from './GenericFunctions';
|
||||||
|
|
||||||
|
|
||||||
export class Dropbox implements INodeType {
|
export class Dropbox implements INodeType {
|
||||||
description: INodeTypeDescription = {
|
description: INodeTypeDescription = {
|
||||||
displayName: 'Dropbox',
|
displayName: 'Dropbox',
|
||||||
|
@ -18,7 +24,7 @@ export class Dropbox implements INodeType {
|
||||||
description: 'Access data on Dropbox',
|
description: 'Access data on Dropbox',
|
||||||
defaults: {
|
defaults: {
|
||||||
name: 'Dropbox',
|
name: 'Dropbox',
|
||||||
color: '#22BB44'
|
color: '#22BB44',
|
||||||
},
|
},
|
||||||
inputs: ['main'],
|
inputs: ['main'],
|
||||||
outputs: ['main'],
|
outputs: ['main'],
|
||||||
|
@ -28,7 +34,9 @@ export class Dropbox implements INodeType {
|
||||||
required: true,
|
required: true,
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
authentication: ['accessToken']
|
authentication: [
|
||||||
|
'accessToken',
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -37,7 +45,9 @@ export class Dropbox implements INodeType {
|
||||||
required: true,
|
required: true,
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
authentication: ['oAuth2']
|
authentication: [
|
||||||
|
'oAuth2',
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -67,15 +77,15 @@ export class Dropbox implements INodeType {
|
||||||
options: [
|
options: [
|
||||||
{
|
{
|
||||||
name: 'File',
|
name: 'File',
|
||||||
value: 'file'
|
value: 'file',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Folder',
|
name: 'Folder',
|
||||||
value: 'folder'
|
value: 'folder',
|
||||||
}
|
},
|
||||||
],
|
],
|
||||||
default: 'file',
|
default: 'file',
|
||||||
description: 'The resource to operate on.'
|
description: 'The resource to operate on.',
|
||||||
},
|
},
|
||||||
|
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
|
@ -87,38 +97,40 @@ export class Dropbox implements INodeType {
|
||||||
type: 'options',
|
type: 'options',
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
resource: ['file']
|
resource: [
|
||||||
}
|
'file',
|
||||||
|
],
|
||||||
|
},
|
||||||
},
|
},
|
||||||
options: [
|
options: [
|
||||||
{
|
{
|
||||||
name: 'Copy',
|
name: 'Copy',
|
||||||
value: 'copy',
|
value: 'copy',
|
||||||
description: 'Copy a file'
|
description: 'Copy a file',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Delete',
|
name: 'Delete',
|
||||||
value: 'delete',
|
value: 'delete',
|
||||||
description: 'Delete a file'
|
description: 'Delete a file',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Download',
|
name: 'Download',
|
||||||
value: 'download',
|
value: 'download',
|
||||||
description: 'Download a file'
|
description: 'Download a file',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Move',
|
name: 'Move',
|
||||||
value: 'move',
|
value: 'move',
|
||||||
description: 'Move a file'
|
description: 'Move a file',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Upload',
|
name: 'Upload',
|
||||||
value: 'upload',
|
value: 'upload',
|
||||||
description: 'Upload a file'
|
description: 'Upload a file',
|
||||||
}
|
},
|
||||||
],
|
],
|
||||||
default: 'upload',
|
default: 'upload',
|
||||||
description: 'The operation to perform.'
|
description: 'The operation to perform.',
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -127,38 +139,40 @@ export class Dropbox implements INodeType {
|
||||||
type: 'options',
|
type: 'options',
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
resource: ['folder']
|
resource: [
|
||||||
}
|
'folder',
|
||||||
|
],
|
||||||
|
},
|
||||||
},
|
},
|
||||||
options: [
|
options: [
|
||||||
{
|
{
|
||||||
name: 'Copy',
|
name: 'Copy',
|
||||||
value: 'copy',
|
value: 'copy',
|
||||||
description: 'Copy a folder'
|
description: 'Copy a folder',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Create',
|
name: 'Create',
|
||||||
value: 'create',
|
value: 'create',
|
||||||
description: 'Create a folder'
|
description: 'Create a folder',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Delete',
|
name: 'Delete',
|
||||||
value: 'delete',
|
value: 'delete',
|
||||||
description: 'Delete a folder'
|
description: 'Delete a folder',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'List',
|
name: 'List',
|
||||||
value: 'list',
|
value: 'list',
|
||||||
description: 'Return the files and folders in a given folder'
|
description: 'Return the files and folders in a given folder',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Move',
|
name: 'Move',
|
||||||
value: 'move',
|
value: 'move',
|
||||||
description: 'Move a folder'
|
description: 'Move a folder',
|
||||||
}
|
},
|
||||||
],
|
],
|
||||||
default: 'create',
|
default: 'create',
|
||||||
description: 'The operation to perform.'
|
description: 'The operation to perform.',
|
||||||
},
|
},
|
||||||
|
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
|
@ -176,12 +190,17 @@ export class Dropbox implements INodeType {
|
||||||
required: true,
|
required: true,
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
operation: ['copy'],
|
operation: [
|
||||||
resource: ['file', 'folder']
|
'copy'
|
||||||
}
|
],
|
||||||
|
resource: [
|
||||||
|
'file',
|
||||||
|
'folder',
|
||||||
|
],
|
||||||
|
},
|
||||||
},
|
},
|
||||||
placeholder: '/invoices/original.txt',
|
placeholder: '/invoices/original.txt',
|
||||||
description: 'The path of file or folder to copy.'
|
description: 'The path of file or folder to copy.',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayName: 'To Path',
|
displayName: 'To Path',
|
||||||
|
@ -191,12 +210,17 @@ export class Dropbox implements INodeType {
|
||||||
required: true,
|
required: true,
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
operation: ['copy'],
|
operation: [
|
||||||
resource: ['file', 'folder']
|
'copy'
|
||||||
}
|
],
|
||||||
|
resource: [
|
||||||
|
'file',
|
||||||
|
'folder',
|
||||||
|
],
|
||||||
|
},
|
||||||
},
|
},
|
||||||
placeholder: '/invoices/copy.txt',
|
placeholder: '/invoices/copy.txt',
|
||||||
description: 'The destination path of file or folder.'
|
description: 'The destination path of file or folder.',
|
||||||
},
|
},
|
||||||
|
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
|
@ -210,15 +234,20 @@ export class Dropbox implements INodeType {
|
||||||
required: true,
|
required: true,
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
operation: ['delete'],
|
operation: [
|
||||||
resource: ['file', 'folder']
|
'delete'
|
||||||
}
|
],
|
||||||
|
resource: [
|
||||||
|
'file',
|
||||||
|
'folder',
|
||||||
|
],
|
||||||
|
},
|
||||||
},
|
},
|
||||||
placeholder: '/invoices/2019/invoice_1.pdf',
|
placeholder: '/invoices/2019/invoice_1.pdf',
|
||||||
description:
|
description: 'The path to delete. Can be a single file or a whole folder.',
|
||||||
'The path to delete. Can be a single file or a whole folder.'
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
// file/folder:move
|
// file/folder:move
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
|
@ -230,12 +259,17 @@ export class Dropbox implements INodeType {
|
||||||
required: true,
|
required: true,
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
operation: ['move'],
|
operation: [
|
||||||
resource: ['file', 'folder']
|
'move'
|
||||||
}
|
],
|
||||||
|
resource: [
|
||||||
|
'file',
|
||||||
|
'folder',
|
||||||
|
],
|
||||||
|
},
|
||||||
},
|
},
|
||||||
placeholder: '/invoices/old_name.txt',
|
placeholder: '/invoices/old_name.txt',
|
||||||
description: 'The path of file or folder to move.'
|
description: 'The path of file or folder to move.',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayName: 'To Path',
|
displayName: 'To Path',
|
||||||
|
@ -245,12 +279,17 @@ export class Dropbox implements INodeType {
|
||||||
required: true,
|
required: true,
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
operation: ['move'],
|
operation: [
|
||||||
resource: ['file', 'folder']
|
'move'
|
||||||
}
|
],
|
||||||
|
resource: [
|
||||||
|
'file',
|
||||||
|
'folder',
|
||||||
|
],
|
||||||
|
},
|
||||||
},
|
},
|
||||||
placeholder: '/invoices/new_name.txt',
|
placeholder: '/invoices/new_name.txt',
|
||||||
description: 'The new path of file or folder.'
|
description: 'The new path of file or folder.',
|
||||||
},
|
},
|
||||||
|
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
|
@ -264,13 +303,16 @@ export class Dropbox implements INodeType {
|
||||||
required: true,
|
required: true,
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
operation: ['download'],
|
operation: [
|
||||||
resource: ['file']
|
'download'
|
||||||
}
|
],
|
||||||
|
resource: [
|
||||||
|
'file',
|
||||||
|
],
|
||||||
|
},
|
||||||
},
|
},
|
||||||
placeholder: '/invoices/2019/invoice_1.pdf',
|
placeholder: '/invoices/2019/invoice_1.pdf',
|
||||||
description:
|
description: 'The file path of the file to download. Has to contain the full path.',
|
||||||
'The file path of the file to download. Has to contain the full path.'
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Binary Property',
|
displayName: 'Binary Property',
|
||||||
|
@ -280,12 +322,15 @@ export class Dropbox implements INodeType {
|
||||||
default: 'data',
|
default: 'data',
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
operation: ['download'],
|
operation: [
|
||||||
resource: ['file']
|
'download'
|
||||||
}
|
],
|
||||||
|
resource: [
|
||||||
|
'file',
|
||||||
|
],
|
||||||
},
|
},
|
||||||
description:
|
},
|
||||||
'Name of the binary property to which to<br />write the data of the read file.'
|
description: 'Name of the binary property to which to<br />write the data of the read file.',
|
||||||
},
|
},
|
||||||
|
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
|
@ -299,13 +344,16 @@ export class Dropbox implements INodeType {
|
||||||
required: true,
|
required: true,
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
operation: ['upload'],
|
operation: [
|
||||||
resource: ['file']
|
'upload'
|
||||||
}
|
],
|
||||||
|
resource: [
|
||||||
|
'file',
|
||||||
|
],
|
||||||
|
},
|
||||||
},
|
},
|
||||||
placeholder: '/invoices/2019/invoice_1.pdf',
|
placeholder: '/invoices/2019/invoice_1.pdf',
|
||||||
description:
|
description: 'The file path of the file to upload. Has to contain the full path. The parent folder has to exist. Existing files get overwritten.',
|
||||||
'The file path of the file to upload. Has to contain the full path. The parent folder has to exist. Existing files get overwritten.'
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Binary Data',
|
displayName: 'Binary Data',
|
||||||
|
@ -314,11 +362,15 @@ export class Dropbox implements INodeType {
|
||||||
default: false,
|
default: false,
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
operation: ['upload'],
|
operation: [
|
||||||
resource: ['file']
|
'upload'
|
||||||
}
|
],
|
||||||
|
resource: [
|
||||||
|
'file',
|
||||||
|
],
|
||||||
},
|
},
|
||||||
description: 'If the data to upload should be taken from binary field.'
|
},
|
||||||
|
description: 'If the data to upload should be taken from binary field.',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayName: 'File Content',
|
displayName: 'File Content',
|
||||||
|
@ -327,13 +379,20 @@ export class Dropbox implements INodeType {
|
||||||
default: '',
|
default: '',
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
operation: ['upload'],
|
operation: [
|
||||||
resource: ['file'],
|
'upload'
|
||||||
binaryData: [false]
|
],
|
||||||
}
|
resource: [
|
||||||
|
'file',
|
||||||
|
],
|
||||||
|
binaryData: [
|
||||||
|
false
|
||||||
|
],
|
||||||
|
},
|
||||||
|
|
||||||
},
|
},
|
||||||
placeholder: '',
|
placeholder: '',
|
||||||
description: 'The text content of the file to upload.'
|
description: 'The text content of the file to upload.',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Binary Property',
|
displayName: 'Binary Property',
|
||||||
|
@ -343,16 +402,24 @@ export class Dropbox implements INodeType {
|
||||||
required: true,
|
required: true,
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
operation: ['upload'],
|
operation: [
|
||||||
resource: ['file'],
|
'upload'
|
||||||
binaryData: [true]
|
],
|
||||||
}
|
resource: [
|
||||||
|
'file',
|
||||||
|
],
|
||||||
|
binaryData: [
|
||||||
|
true
|
||||||
|
],
|
||||||
|
},
|
||||||
|
|
||||||
},
|
},
|
||||||
placeholder: '',
|
placeholder: '',
|
||||||
description:
|
description: 'Name of the binary property which contains<br />the data for the file to be uploaded.',
|
||||||
'Name of the binary property which contains<br />the data for the file to be uploaded.'
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
// folder
|
// folder
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
|
@ -368,12 +435,16 @@ export class Dropbox implements INodeType {
|
||||||
required: true,
|
required: true,
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
operation: ['create'],
|
operation: [
|
||||||
resource: ['folder']
|
'create'
|
||||||
}
|
],
|
||||||
|
resource: [
|
||||||
|
'folder',
|
||||||
|
],
|
||||||
|
},
|
||||||
},
|
},
|
||||||
placeholder: '/invoices/2019',
|
placeholder: '/invoices/2019',
|
||||||
description: 'The folder to create. The parent folder has to exist.'
|
description: 'The folder to create. The parent folder has to exist.',
|
||||||
},
|
},
|
||||||
|
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
|
@ -386,20 +457,27 @@ export class Dropbox implements INodeType {
|
||||||
default: '',
|
default: '',
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
operation: ['list'],
|
operation: [
|
||||||
resource: ['folder']
|
'list'
|
||||||
}
|
],
|
||||||
|
resource: [
|
||||||
|
'folder',
|
||||||
|
],
|
||||||
|
},
|
||||||
},
|
},
|
||||||
placeholder: '/invoices/2019/',
|
placeholder: '/invoices/2019/',
|
||||||
description: 'The path of which to list the content.'
|
description: 'The path of which to list the content.',
|
||||||
}
|
},
|
||||||
]
|
|
||||||
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
||||||
const items = this.getInputData();
|
const items = this.getInputData();
|
||||||
const returnData: IDataObject[] = [];
|
const returnData: IDataObject[] = [];
|
||||||
|
|
||||||
|
|
||||||
const resource = this.getNodeParameter('resource', 0) as string;
|
const resource = this.getNodeParameter('resource', 0) as string;
|
||||||
const operation = this.getNodeParameter('operation', 0) as string;
|
const operation = this.getNodeParameter('operation', 0) as string;
|
||||||
|
|
||||||
|
@ -420,10 +498,11 @@ export class Dropbox implements INodeType {
|
||||||
|
|
||||||
requestMethod = 'POST';
|
requestMethod = 'POST';
|
||||||
headers['Dropbox-API-Arg'] = JSON.stringify({
|
headers['Dropbox-API-Arg'] = JSON.stringify({
|
||||||
path: this.getNodeParameter('path', i) as string
|
path: this.getNodeParameter('path', i) as string,
|
||||||
});
|
});
|
||||||
|
|
||||||
endpoint = 'https://content.dropboxapi.com/2/files/download';
|
endpoint = 'https://content.dropboxapi.com/2/files/download';
|
||||||
|
|
||||||
} else if (operation === 'upload') {
|
} else if (operation === 'upload') {
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
// upload
|
// upload
|
||||||
|
@ -433,7 +512,7 @@ export class Dropbox implements INodeType {
|
||||||
headers['Content-Type'] = 'application/octet-stream';
|
headers['Content-Type'] = 'application/octet-stream';
|
||||||
headers['Dropbox-API-Arg'] = JSON.stringify({
|
headers['Dropbox-API-Arg'] = JSON.stringify({
|
||||||
mode: 'overwrite',
|
mode: 'overwrite',
|
||||||
path: this.getNodeParameter('path', i) as string
|
path: this.getNodeParameter('path', i) as string,
|
||||||
});
|
});
|
||||||
|
|
||||||
endpoint = 'https://content.dropboxapi.com/2/files/upload';
|
endpoint = 'https://content.dropboxapi.com/2/files/upload';
|
||||||
|
@ -446,29 +525,19 @@ export class Dropbox implements INodeType {
|
||||||
throw new Error('No binary data exists on item!');
|
throw new Error('No binary data exists on item!');
|
||||||
}
|
}
|
||||||
|
|
||||||
const propertyNameUpload = this.getNodeParameter(
|
const propertyNameUpload = this.getNodeParameter('binaryPropertyName', i) as string;
|
||||||
'binaryPropertyName',
|
|
||||||
i
|
|
||||||
) as string;
|
|
||||||
|
|
||||||
if (item.binary[propertyNameUpload] === undefined) {
|
if (item.binary[propertyNameUpload] === undefined) {
|
||||||
throw new Error(
|
throw new Error(`No binary data property "${propertyNameUpload}" does not exists on item!`);
|
||||||
`No binary data property "${propertyNameUpload}" does not exists on item!`
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
body = Buffer.from(
|
body = Buffer.from(item.binary[propertyNameUpload].data, BINARY_ENCODING);
|
||||||
item.binary[propertyNameUpload].data,
|
|
||||||
BINARY_ENCODING
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
// Is text file
|
// Is text file
|
||||||
body = Buffer.from(
|
body = Buffer.from(this.getNodeParameter('fileContent', i) as string, 'utf8');
|
||||||
this.getNodeParameter('fileContent', i) as string,
|
|
||||||
'utf8'
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (resource === 'folder') {
|
} else if (resource === 'folder') {
|
||||||
if (operation === 'create') {
|
if (operation === 'create') {
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
|
@ -477,10 +546,11 @@ export class Dropbox implements INodeType {
|
||||||
|
|
||||||
requestMethod = 'POST';
|
requestMethod = 'POST';
|
||||||
body = {
|
body = {
|
||||||
path: this.getNodeParameter('path', i) as string
|
path: this.getNodeParameter('path', i) as string,
|
||||||
};
|
};
|
||||||
|
|
||||||
endpoint = 'https://api.dropboxapi.com/2/files/create_folder_v2';
|
endpoint = 'https://api.dropboxapi.com/2/files/create_folder_v2';
|
||||||
|
|
||||||
} else if (operation === 'list') {
|
} else if (operation === 'list') {
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
// list
|
// list
|
||||||
|
@ -489,13 +559,14 @@ export class Dropbox implements INodeType {
|
||||||
requestMethod = 'POST';
|
requestMethod = 'POST';
|
||||||
body = {
|
body = {
|
||||||
path: this.getNodeParameter('path', i) as string,
|
path: this.getNodeParameter('path', i) as string,
|
||||||
limit: 2000
|
limit: 2000,
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO: If more files than the max-amount exist it has to be possible to
|
// TODO: If more files than the max-amount exist it has to be possible to
|
||||||
// also request them.
|
// also request them.
|
||||||
|
|
||||||
endpoint = 'https://api.dropboxapi.com/2/files/list_folder';
|
endpoint = 'https://api.dropboxapi.com/2/files/list_folder';
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (['file', 'folder'].includes(resource)) {
|
if (['file', 'folder'].includes(resource)) {
|
||||||
|
@ -507,10 +578,11 @@ export class Dropbox implements INodeType {
|
||||||
requestMethod = 'POST';
|
requestMethod = 'POST';
|
||||||
body = {
|
body = {
|
||||||
from_path: this.getNodeParameter('path', i) as string,
|
from_path: this.getNodeParameter('path', i) as string,
|
||||||
to_path: this.getNodeParameter('toPath', i) as string
|
to_path: this.getNodeParameter('toPath', i) as string,
|
||||||
};
|
};
|
||||||
|
|
||||||
endpoint = 'https://api.dropboxapi.com/2/files/copy_v2';
|
endpoint = 'https://api.dropboxapi.com/2/files/copy_v2';
|
||||||
|
|
||||||
} else if (operation === 'delete') {
|
} else if (operation === 'delete') {
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
// delete
|
// delete
|
||||||
|
@ -518,10 +590,11 @@ export class Dropbox implements INodeType {
|
||||||
|
|
||||||
requestMethod = 'POST';
|
requestMethod = 'POST';
|
||||||
body = {
|
body = {
|
||||||
path: this.getNodeParameter('path', i) as string
|
path: this.getNodeParameter('path', i) as string,
|
||||||
};
|
};
|
||||||
|
|
||||||
endpoint = 'https://api.dropboxapi.com/2/files/delete_v2';
|
endpoint = 'https://api.dropboxapi.com/2/files/delete_v2';
|
||||||
|
|
||||||
} else if (operation === 'move') {
|
} else if (operation === 'move') {
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
// move
|
// move
|
||||||
|
@ -530,7 +603,7 @@ export class Dropbox implements INodeType {
|
||||||
requestMethod = 'POST';
|
requestMethod = 'POST';
|
||||||
body = {
|
body = {
|
||||||
from_path: this.getNodeParameter('path', i) as string,
|
from_path: this.getNodeParameter('path', i) as string,
|
||||||
to_path: this.getNodeParameter('toPath', i) as string
|
to_path: this.getNodeParameter('toPath', i) as string,
|
||||||
};
|
};
|
||||||
|
|
||||||
endpoint = 'https://api.dropboxapi.com/2/files/move_v2';
|
endpoint = 'https://api.dropboxapi.com/2/files/move_v2';
|
||||||
|
@ -545,19 +618,13 @@ export class Dropbox implements INodeType {
|
||||||
encoding = null;
|
encoding = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const responseData = await dropboxApiRequest.call(
|
const responseData = await dropboxApiRequest.call(this, requestMethod, endpoint, body, headers, encoding);
|
||||||
this,
|
console.log(responseData);
|
||||||
requestMethod,
|
|
||||||
endpoint,
|
|
||||||
body,
|
|
||||||
headers,
|
|
||||||
encoding
|
|
||||||
);
|
|
||||||
|
|
||||||
if (resource === 'file' && operation === 'download') {
|
if (resource === 'file' && operation === 'download') {
|
||||||
|
|
||||||
const newItem: INodeExecutionData = {
|
const newItem: INodeExecutionData = {
|
||||||
json: items[i].json,
|
json: items[i].json,
|
||||||
binary: {}
|
binary: {},
|
||||||
};
|
};
|
||||||
|
|
||||||
if (items[i].binary !== undefined) {
|
if (items[i].binary !== undefined) {
|
||||||
|
@ -569,28 +636,22 @@ export class Dropbox implements INodeType {
|
||||||
|
|
||||||
items[i] = newItem;
|
items[i] = newItem;
|
||||||
|
|
||||||
const dataPropertyNameDownload = this.getNodeParameter(
|
const dataPropertyNameDownload = this.getNodeParameter('binaryPropertyName', i) as string;
|
||||||
'binaryPropertyName',
|
|
||||||
i
|
|
||||||
) as string;
|
|
||||||
|
|
||||||
const filePathDownload = this.getNodeParameter('path', i) as string;
|
const filePathDownload = this.getNodeParameter('path', i) as string;
|
||||||
items[i].binary![
|
items[i].binary![dataPropertyNameDownload] = await this.helpers.prepareBinaryData(Buffer.from(responseData), filePathDownload);
|
||||||
dataPropertyNameDownload
|
|
||||||
] = await this.helpers.prepareBinaryData(
|
|
||||||
Buffer.from(responseData.data),
|
|
||||||
filePathDownload
|
|
||||||
);
|
|
||||||
} else if (resource === 'folder' && operation === 'list') {
|
} else if (resource === 'folder' && operation === 'list') {
|
||||||
|
|
||||||
const propNames: { [key: string]: string } = {
|
const propNames: { [key: string]: string } = {
|
||||||
id: 'id',
|
'id': 'id',
|
||||||
name: 'name',
|
'name': 'name',
|
||||||
client_modified: 'lastModifiedClient',
|
'client_modified': 'lastModifiedClient',
|
||||||
server_modified: 'lastModifiedServer',
|
'server_modified': 'lastModifiedServer',
|
||||||
rev: 'rev',
|
'rev': 'rev',
|
||||||
size: 'contentSize',
|
'size': 'contentSize',
|
||||||
'.tag': 'type',
|
'.tag': 'type',
|
||||||
content_hash: 'contentHash'
|
'content_hash': 'contentHash',
|
||||||
};
|
};
|
||||||
|
|
||||||
for (const item of responseData.entries) {
|
for (const item of responseData.entries) {
|
||||||
|
@ -605,8 +666,6 @@ export class Dropbox implements INodeType {
|
||||||
|
|
||||||
returnData.push(newItem as IDataObject);
|
returnData.push(newItem as IDataObject);
|
||||||
}
|
}
|
||||||
} else if (resource === 'file' && operation === 'upload') {
|
|
||||||
returnData.push(responseData as IDataObject);
|
|
||||||
} else {
|
} else {
|
||||||
returnData.push(responseData as IDataObject);
|
returnData.push(responseData as IDataObject);
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,15 +10,7 @@ import { OptionsWithUri } from 'request';
|
||||||
* @param {object} body
|
* @param {object} body
|
||||||
* @returns {Promise<any>}
|
* @returns {Promise<any>}
|
||||||
*/
|
*/
|
||||||
export async function dropboxApiRequest(
|
export async function dropboxApiRequest(this: IHookFunctions | IExecuteFunctions, method: string, endpoint: string, body: object, headers?: object, encoding?: string | null): Promise<any> {// tslint:disable-line:no-any
|
||||||
this: IHookFunctions | IExecuteFunctions,
|
|
||||||
method: string,
|
|
||||||
endpoint: string,
|
|
||||||
body: object,
|
|
||||||
headers?: object,
|
|
||||||
encoding?: string | null
|
|
||||||
): Promise<any> {
|
|
||||||
// tslint:disable-line:no-any
|
|
||||||
|
|
||||||
const options: OptionsWithUri = {
|
const options: OptionsWithUri = {
|
||||||
headers,
|
headers,
|
||||||
|
@ -37,20 +29,15 @@ export async function dropboxApiRequest(
|
||||||
delete options.encoding;
|
delete options.encoding;
|
||||||
}
|
}
|
||||||
|
|
||||||
const authenticationMethod = this.getNodeParameter(
|
const authenticationMethod = this.getNodeParameter('authentication', 0) as string;
|
||||||
'authentication',
|
|
||||||
0
|
console.log(options);
|
||||||
) as string;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (authenticationMethod === 'accessToken') {
|
if (authenticationMethod === 'accessToken') {
|
||||||
return await this.helpers.request(options);
|
return await this.helpers.request(options);
|
||||||
} else {
|
} else {
|
||||||
return await this.helpers.requestOAuth.call(
|
return await this.helpers.requestOAuth.call(this, 'dropboxOAuth2Api', options);
|
||||||
this,
|
|
||||||
'dropboxOAuth2Api',
|
|
||||||
options
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error.statusCode === 401) {
|
if (error.statusCode === 401) {
|
||||||
|
|
Loading…
Reference in a new issue