Minor improvements to Box Node

This commit is contained in:
Jan Oberhauser 2020-07-25 19:59:12 +02:00
parent 8370940713
commit d726e11af4
5 changed files with 117 additions and 118 deletions

View file

@ -84,7 +84,7 @@ export class Box implements INodeType {
const operation = this.getNodeParameter('operation', 0) as string;
for (let i = 0; i < length; i++) {
if (resource === 'file') {
//https://developer.box.com/reference/post-files-id-copy
// https://developer.box.com/reference/post-files-id-copy
if (operation === 'copy') {
const fileId = this.getNodeParameter('fileId', i) as string;
const parentId = this.getNodeParameter('parentId', i) as string;
@ -108,14 +108,14 @@ export class Box implements INodeType {
returnData.push(responseData as IDataObject);
}
//https://developer.box.com/reference/delete-files-id
// https://developer.box.com/reference/delete-files-id
if (operation === 'delete') {
const fileId = this.getNodeParameter('fileId', i) as string;
responseData = await boxApiRequest.call(this, 'DELETE', `/files/${fileId}`);
responseData = { success: true };
returnData.push(responseData as IDataObject);
}
//https://developer.box.com/reference/get-files-id-content
// https://developer.box.com/reference/get-files-id-content
if (operation === 'download') {
const fileId = this.getNodeParameter('fileId', i) as string;
const dataPropertyNameDownload = this.getNodeParameter('binaryPropertyName', i) as string;
@ -149,7 +149,7 @@ export class Box implements INodeType {
items[i].binary![dataPropertyNameDownload] = await this.helpers.prepareBinaryData(data as unknown as Buffer, fileName, mimeType);
}
//https://developer.box.com/reference/get-files-id
// https://developer.box.com/reference/get-files-id
if (operation === 'get') {
const fileId = this.getNodeParameter('fileId', i) as string;
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
@ -159,7 +159,7 @@ export class Box implements INodeType {
responseData = await boxApiRequest.call(this, 'GET', `/files/${fileId}`, {}, qs);
returnData.push(responseData as IDataObject);
}
//https://developer.box.com/reference/get-search/
// https://developer.box.com/reference/get-search/
if (operation === 'search') {
const query = this.getNodeParameter('query', i) as string;
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
@ -198,7 +198,7 @@ export class Box implements INodeType {
}
returnData.push.apply(returnData, responseData as IDataObject[]);
}
//https://developer.box.com/reference/post-files-content
// https://developer.box.com/reference/post-files-content
if (operation === 'upload') {
const parentId = this.getNodeParameter('parentId', i) as string;
const isBinaryData = this.getNodeParameter('binaryData', i) as boolean;
@ -207,7 +207,7 @@ export class Box implements INodeType {
const attributes: IDataObject = {};
if (parentId !== '') {
attributes['parent'] = { id: parentId };
attributes['parent'] = { id: parentId };
} else {
// if not parent defined save it on the root directory
attributes['parent'] = { id: 0 };
@ -264,14 +264,14 @@ export class Box implements INodeType {
contentType: 'text/plain',
},
};
responseData = await boxApiRequest.call(this, 'POST', '', {} , {}, 'https://upload.box.com/api/2.0/files/content', { formData: body });
responseData = await boxApiRequest.call(this, 'POST', '', {}, {}, 'https://upload.box.com/api/2.0/files/content', { formData: body });
returnData.push.apply(returnData, responseData.entries as IDataObject[]);
}
}
}
if (resource === 'folder') {
//https://developer.box.com/reference/post-folders
// https://developer.box.com/reference/post-folders
if (operation === 'create') {
const name = this.getNodeParameter('name', i) as string;
const parentId = this.getNodeParameter('parentId', i) as string;
@ -300,7 +300,7 @@ export class Box implements INodeType {
returnData.push(responseData);
}
//https://developer.box.com/reference/delete-folders-id
// https://developer.box.com/reference/delete-folders-id
if (operation === 'delete') {
const folderId = this.getNodeParameter('folderId', i) as string;
const recursive = this.getNodeParameter('recursive', i) as boolean;
@ -310,7 +310,7 @@ export class Box implements INodeType {
responseData = { success: true };
returnData.push(responseData as IDataObject);
}
//https://developer.box.com/reference/get-search/
// https://developer.box.com/reference/get-search/
if (operation === 'search') {
const query = this.getNodeParameter('query', i) as string;
const returnAll = this.getNodeParameter('returnAll', i) as boolean;

View file

@ -48,16 +48,16 @@ export class BoxTrigger implements INodeType {
name: 'events',
type: 'multiOptions',
options: [
{
name: 'Collaboration Created',
value: 'COLLABORATION.CREATED',
description: 'A collaboration is created',
},
{
name: 'Collaboration Accepted',
value: 'COLLABORATION.ACCEPTED',
description: 'A collaboration has been accepted',
},
{
name: 'Collaboration Created',
value: 'COLLABORATION.CREATED',
description: 'A collaboration is created',
},
{
name: 'Collaboration Rejected',
value: 'COLLABORATION.REJECTED',
@ -78,45 +78,15 @@ export class BoxTrigger implements INodeType {
value: 'COMMENT.CREATED',
description: 'A comment object is created',
},
{
name: 'Comment Updated',
value: 'COMMENT.UPDATED',
description: 'A comment object is edited',
},
{
name: 'Comment Deleted',
value: 'COMMENT.DELETED',
description: 'A comment object is removed',
},
{
name: 'File Uploaded',
value: 'FILE.UPLOADED',
description: 'A file is uploaded to or moved to this folder',
},
{
name: 'File Previewed',
value: 'FILE.PREVIEWED',
description: 'A file is previewed',
},
{
name: 'File Downloaded',
value: 'FILE.DOWNLOADED',
description: 'A file is downloaded',
},
{
name: 'File Trashed',
value: 'FILE.TRASHED',
description: 'A file is moved to the trash',
},
{
name: 'File Deleted',
value: 'FILE.DELETED',
description: 'A file is moved to the trash',
},
{
name: 'File Restored',
value: 'FILE.RESTORED',
description: 'A file is restored from the trash',
name: 'Comment Updated',
value: 'COMMENT.UPDATED',
description: 'A comment object is edited',
},
{
name: 'File Copied',
@ -124,9 +94,14 @@ export class BoxTrigger implements INodeType {
description: 'A file is copied',
},
{
name: 'File Moved',
value: 'FILE.MOVED',
description: 'A file is moved from one folder to another',
name: 'File Deleted',
value: 'FILE.DELETED',
description: 'A file is moved to the trash',
},
{
name: 'File Downloaded',
value: 'FILE.DOWNLOADED',
description: 'A file is downloaded',
},
{
name: 'File Locked',
@ -134,9 +109,14 @@ export class BoxTrigger implements INodeType {
description: 'A file is locked',
},
{
name: 'File Unlocked',
value: 'FILE.UNLOCKED',
description: 'A file is unlocked',
name: 'File Moved',
value: 'FILE.MOVED',
description: 'A file is moved from one folder to another',
},
{
name: 'File Previewed',
value: 'FILE.PREVIEWED',
description: 'A file is previewed',
},
{
name: 'File Renamed',
@ -144,40 +124,60 @@ export class BoxTrigger implements INodeType {
description: 'A file was renamed.',
},
{
name: 'Folder Created',
value: 'FOLDER.CREATED',
description: 'A folder is created',
name: 'File Restored',
value: 'FILE.RESTORED',
description: 'A file is restored from the trash',
},
{
name: 'Folder Renamed',
value: 'FOLDER.RENAMED',
description: 'A folder was renamed.',
name: 'File Trashed',
value: 'FILE.TRASHED',
description: 'A file is moved to the trash',
},
{
name: 'Folder Downloaded',
value: 'FOLDER.DOWNLOADED',
description: 'A folder is downloaded',
name: 'File Unlocked',
value: 'FILE.UNLOCKED',
description: 'A file is unlocked',
},
{
name: 'Folder Restored',
value: 'FOLDER.RESTORED',
description: 'A folder is restored from the trash',
},
{
name: 'Folder Deleted',
value: 'FOLDER.DELETED',
description: 'A folder is permanently removed',
name: 'File Uploaded',
value: 'FILE.UPLOADED',
description: 'A file is uploaded to or moved to this folder',
},
{
name: 'Folder Copied',
value: 'FOLDER.COPIED',
description: 'A copy of a folder is made',
},
{
name: 'Folder Created',
value: 'FOLDER.CREATED',
description: 'A folder is created',
},
{
name: 'Folder Deleted',
value: 'FOLDER.DELETED',
description: 'A folder is permanently removed',
},
{
name: 'Folder Downloaded',
value: 'FOLDER.DOWNLOADED',
description: 'A folder is downloaded',
},
{
name: 'Folder Moved',
value: 'FOLDER.MOVED',
description: 'A folder is moved to a different folder',
},
{
name: 'Folder Renamed',
value: 'FOLDER.RENAMED',
description: 'A folder was renamed.',
},
{
name: 'Folder Restored',
value: 'FOLDER.RESTORED',
description: 'A folder is restored from the trash',
},
{
name: 'Folder Trashed',
value: 'FOLDER.TRASHED',
@ -188,20 +188,15 @@ export class BoxTrigger implements INodeType {
value: 'METADATA_INSTANCE.CREATED',
description: 'A new metadata template instance is associated with a file or folder',
},
{
name: 'Metadata Instance Updated',
value: 'METADATA_INSTANCE.UPDATED',
description: 'An attribute (value) is updated/deleted for an existing metadata template instance associated with a file or folder',
},
{
name: 'Metadata Instance Deleted',
value: 'METADATA_INSTANCE.DELETED',
description: 'An existing metadata template instance associated with a file or folder is deleted',
},
{
name: 'Sharedlink Deleted',
value: 'SHARED_LINK.DELETED',
description: 'A shared link was deleted',
name: 'Metadata Instance Updated',
value: 'METADATA_INSTANCE.UPDATED',
description: 'An attribute (value) is updated/deleted for an existing metadata template instance associated with a file or folder',
},
{
name: 'Sharedlink Created',
@ -209,7 +204,12 @@ export class BoxTrigger implements INodeType {
description: 'A shared link was created',
},
{
name: 'Sharedlink UPDATED',
name: 'Sharedlink Deleted',
value: 'SHARED_LINK.DELETED',
description: 'A shared link was deleted',
},
{
name: 'Sharedlink Updated',
value: 'SHARED_LINK.UPDATED',
description: 'A shared link was updated',
},

View file

@ -1,6 +1,6 @@
import {
INodeProperties,
} from 'n8n-workflow';
} from 'n8n-workflow';
export const fileOperations = [
{
@ -53,9 +53,9 @@ export const fileOperations = [
export const fileFields = [
/* -------------------------------------------------------------------------- */
/* file:copy */
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* file:copy */
/* -------------------------------------------------------------------------- */
{
displayName: 'File ID',
name: 'fileId',
@ -131,9 +131,10 @@ export const fileFields = [
},
],
},
/* -------------------------------------------------------------------------- */
/* file:delete */
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* file:delete */
/* -------------------------------------------------------------------------- */
{
displayName: 'File ID',
name: 'fileId',
@ -151,9 +152,10 @@ export const fileFields = [
default: '',
description: 'Field ID',
},
/* -------------------------------------------------------------------------- */
/* file:download */
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* file:download */
/* -------------------------------------------------------------------------- */
{
displayName: 'File ID',
name: 'fileId',
@ -189,9 +191,10 @@ export const fileFields = [
},
description: 'Name of the binary property to which to<br />write the data of the read file.',
},
/* -------------------------------------------------------------------------- */
/* file:get */
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* file:get */
/* -------------------------------------------------------------------------- */
{
displayName: 'File ID',
name: 'fileId',
@ -235,9 +238,10 @@ export const fileFields = [
},
],
},
/* -------------------------------------------------------------------------- */
/* file:search */
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* file:search */
/* -------------------------------------------------------------------------- */
{
displayName: 'Query',
name: 'query',
@ -491,9 +495,10 @@ export const fileFields = [
},
],
},
/* -------------------------------------------------------------------------- */
/* file:upload */
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* file:upload */
/* -------------------------------------------------------------------------- */
{
displayName: 'File Name',
name: 'fileName',
@ -550,7 +555,6 @@ export const fileFields = [
},
},
placeholder: '',
description: 'The text content of the file.',
},
{
@ -573,7 +577,6 @@ export const fileFields = [
},
},
placeholder: '',
description: 'Name of the binary property which contains<br />the data for the file.',
},
{

View file

@ -1,6 +1,6 @@
import {
INodeProperties,
} from 'n8n-workflow';
} from 'n8n-workflow';
export const folderOperations = [
{
@ -38,9 +38,9 @@ export const folderOperations = [
export const folderFields = [
/* -------------------------------------------------------------------------- */
/* folder:create */
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* folder:create */
/* -------------------------------------------------------------------------- */
{
displayName: 'Name',
name: 'name',
@ -121,9 +121,10 @@ export const folderFields = [
},
],
},
/* -------------------------------------------------------------------------- */
/* folder:delete */
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* folder:delete */
/* -------------------------------------------------------------------------- */
{
displayName: 'Folder ID',
name: 'folderId',
@ -158,9 +159,10 @@ export const folderFields = [
default: false,
description: 'Delete a folder that is not empty by recursively deleting the folder and all of its content.',
},
/* -------------------------------------------------------------------------- */
/* file:search */
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* file:search */
/* -------------------------------------------------------------------------- */
{
displayName: 'Query',
name: 'query',

View file

@ -47,17 +47,11 @@ export async function boxApiRequest(this: IExecuteFunctions | IExecuteSingleFunc
if (error.response && error.response.body) {
if (error.response.body.context_info && error.response.body.context_info.errors) {
const errors = error.response.body.context_info.errors;
errorMessage = errors.map((e: IDataObject) => e.message);
errorMessage = errorMessage.join('|');
} else if (error.response.body.message) {
errorMessage = error.response.body.message;
}
throw new Error(`Box error response [${error.statusCode}]: ${errorMessage}`);