mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 01:56:46 +00:00
refactor: Format nodes-base package (A-F) (#3800)
* 🔨 prettier formated nodes - A * 🔨 prettier formated nodes - B * ⚡ prettier formated nodes - C * ⚡ prettier formated nodes - D * ⚡ prettier formated nodes - E-F * 🎨 Adjust nodes-base formatting command (#3805) * Format additional files in nodes A-F (#3811) * ⚡ fixes * 🎨 Add Mindee to ignored dirs Co-authored-by: Iván Ovejero <ivov.src@gmail.com>
This commit is contained in:
@@ -1,6 +1,4 @@
|
||||
import {
|
||||
IExecuteFunctions,
|
||||
} from 'n8n-core';
|
||||
import { IExecuteFunctions } from 'n8n-core';
|
||||
|
||||
import {
|
||||
IBinaryKeyData,
|
||||
@@ -11,26 +9,15 @@ import {
|
||||
NodeOperationError,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import {
|
||||
boxApiRequest,
|
||||
boxApiRequestAllItems,
|
||||
} from './GenericFunctions';
|
||||
import { boxApiRequest, boxApiRequestAllItems } from './GenericFunctions';
|
||||
|
||||
import {
|
||||
fileFields,
|
||||
fileOperations,
|
||||
} from './FileDescription';
|
||||
import { fileFields, fileOperations } from './FileDescription';
|
||||
|
||||
import {
|
||||
folderFields,
|
||||
folderOperations,
|
||||
} from './FolderDescription';
|
||||
import { folderFields, folderOperations } from './FolderDescription';
|
||||
|
||||
import moment from 'moment-timezone';
|
||||
|
||||
import {
|
||||
noCase,
|
||||
} from 'change-case';
|
||||
import { noCase } from 'change-case';
|
||||
|
||||
export class Box implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
@@ -110,7 +97,13 @@ export class Box implements INodeType {
|
||||
if (additionalFields.version) {
|
||||
body.version = additionalFields.version as string;
|
||||
}
|
||||
responseData = await boxApiRequest.call(this, 'POST', `/files/${fileId}/copy`, body, qs);
|
||||
responseData = await boxApiRequest.call(
|
||||
this,
|
||||
'POST',
|
||||
`/files/${fileId}/copy`,
|
||||
body,
|
||||
qs,
|
||||
);
|
||||
|
||||
returnData.push(responseData as IDataObject);
|
||||
}
|
||||
@@ -124,14 +117,25 @@ export class Box implements INodeType {
|
||||
// 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;
|
||||
const dataPropertyNameDownload = this.getNodeParameter(
|
||||
'binaryPropertyName',
|
||||
i,
|
||||
) as string;
|
||||
responseData = await boxApiRequest.call(this, 'GET', `/files/${fileId}`);
|
||||
|
||||
const fileName = responseData.name;
|
||||
|
||||
let mimeType: string | undefined;
|
||||
|
||||
responseData = await boxApiRequest.call(this, 'GET', `/files/${fileId}/content`, {}, {}, undefined, { encoding: null, resolveWithFullResponse: true });
|
||||
responseData = await boxApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
`/files/${fileId}/content`,
|
||||
{},
|
||||
{},
|
||||
undefined,
|
||||
{ encoding: null, resolveWithFullResponse: true },
|
||||
);
|
||||
|
||||
const newItem: INodeExecutionData = {
|
||||
json: items[i].json,
|
||||
@@ -153,7 +157,11 @@ export class Box implements INodeType {
|
||||
|
||||
const data = Buffer.from(responseData.body);
|
||||
|
||||
items[i].binary![dataPropertyNameDownload] = await this.helpers.prepareBinaryData(data as unknown as Buffer, fileName, mimeType);
|
||||
items[i].binary![dataPropertyNameDownload] = await this.helpers.prepareBinaryData(
|
||||
data as unknown as Buffer,
|
||||
fileName,
|
||||
mimeType,
|
||||
);
|
||||
}
|
||||
// https://developer.box.com/reference/get-files-id
|
||||
if (operation === 'get') {
|
||||
@@ -180,23 +188,36 @@ export class Box implements INodeType {
|
||||
}
|
||||
|
||||
if (additionalFields.createdRangeUi) {
|
||||
const createdRangeValues = (additionalFields.createdRangeUi as IDataObject).createdRangeValuesUi as IDataObject;
|
||||
const createdRangeValues = (additionalFields.createdRangeUi as IDataObject)
|
||||
.createdRangeValuesUi as IDataObject;
|
||||
if (createdRangeValues) {
|
||||
qs.created_at_range = `${moment.tz(createdRangeValues.from, timezone).format()},${moment.tz(createdRangeValues.to, timezone).format()}`;
|
||||
qs.created_at_range = `${moment
|
||||
.tz(createdRangeValues.from, timezone)
|
||||
.format()},${moment.tz(createdRangeValues.to, timezone).format()}`;
|
||||
}
|
||||
delete qs.createdRangeUi;
|
||||
}
|
||||
|
||||
if (additionalFields.updatedRangeUi) {
|
||||
const updateRangeValues = (additionalFields.updatedRangeUi as IDataObject).updatedRangeValuesUi as IDataObject;
|
||||
const updateRangeValues = (additionalFields.updatedRangeUi as IDataObject)
|
||||
.updatedRangeValuesUi as IDataObject;
|
||||
if (updateRangeValues) {
|
||||
qs.updated_at_range = `${moment.tz(updateRangeValues.from, timezone).format()},${moment.tz(updateRangeValues.to, timezone).format()}`;
|
||||
qs.updated_at_range = `${moment
|
||||
.tz(updateRangeValues.from, timezone)
|
||||
.format()},${moment.tz(updateRangeValues.to, timezone).format()}`;
|
||||
}
|
||||
delete qs.updatedRangeUi;
|
||||
}
|
||||
|
||||
if (returnAll) {
|
||||
responseData = await boxApiRequestAllItems.call(this, 'entries', 'GET', `/search`, {}, qs);
|
||||
responseData = await boxApiRequestAllItems.call(
|
||||
this,
|
||||
'entries',
|
||||
'GET',
|
||||
`/search`,
|
||||
{},
|
||||
qs,
|
||||
);
|
||||
} else {
|
||||
qs.limit = this.getNodeParameter('limit', i) as number;
|
||||
responseData = await boxApiRequest.call(this, 'GET', `/search`, {}, qs);
|
||||
@@ -211,13 +232,13 @@ export class Box implements INodeType {
|
||||
const accessibleBy = this.getNodeParameter('accessibleBy', i) as string;
|
||||
const options = this.getNodeParameter('options', i) as IDataObject;
|
||||
// tslint:disable-next-line: no-any
|
||||
const body: { accessible_by: IDataObject, [key: string]: any } = {
|
||||
const body: { accessible_by: IDataObject; [key: string]: any } = {
|
||||
accessible_by: {},
|
||||
item: {
|
||||
id: fileId,
|
||||
type: 'file',
|
||||
},
|
||||
role: (role === 'coOwner') ? 'co-owner' : noCase(role),
|
||||
role: role === 'coOwner' ? 'co-owner' : noCase(role),
|
||||
...options,
|
||||
};
|
||||
|
||||
@@ -268,15 +289,24 @@ export class Box implements INodeType {
|
||||
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', 0) as string;
|
||||
|
||||
if (items[i].binary === undefined) {
|
||||
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!', { itemIndex: i });
|
||||
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!', {
|
||||
itemIndex: i,
|
||||
});
|
||||
}
|
||||
//@ts-ignore
|
||||
if (items[i].binary[binaryPropertyName] === undefined) {
|
||||
throw new NodeOperationError(this.getNode(), `No binary data property "${binaryPropertyName}" does not exists on item!`, { itemIndex: i });
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
`No binary data property "${binaryPropertyName}" does not exists on item!`,
|
||||
{ itemIndex: i },
|
||||
);
|
||||
}
|
||||
|
||||
const binaryData = (items[i].binary as IBinaryKeyData)[binaryPropertyName];
|
||||
const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName);
|
||||
const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(
|
||||
i,
|
||||
binaryPropertyName,
|
||||
);
|
||||
|
||||
const body: IDataObject = {};
|
||||
|
||||
@@ -292,15 +322,24 @@ export class Box implements INodeType {
|
||||
},
|
||||
};
|
||||
|
||||
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[]);
|
||||
|
||||
} else {
|
||||
const content = this.getNodeParameter('fileContent', i) as string;
|
||||
|
||||
if (fileName === '') {
|
||||
throw new NodeOperationError(this.getNode(), 'File name must be set!', { itemIndex: i });
|
||||
throw new NodeOperationError(this.getNode(), 'File name must be set!', {
|
||||
itemIndex: i,
|
||||
});
|
||||
}
|
||||
|
||||
attributes['name'] = fileName;
|
||||
@@ -316,7 +355,15 @@ 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[]);
|
||||
}
|
||||
@@ -383,23 +430,36 @@ export class Box implements INodeType {
|
||||
}
|
||||
|
||||
if (additionalFields.createdRangeUi) {
|
||||
const createdRangeValues = (additionalFields.createdRangeUi as IDataObject).createdRangeValuesUi as IDataObject;
|
||||
const createdRangeValues = (additionalFields.createdRangeUi as IDataObject)
|
||||
.createdRangeValuesUi as IDataObject;
|
||||
if (createdRangeValues) {
|
||||
qs.created_at_range = `${moment.tz(createdRangeValues.from, timezone).format()},${moment.tz(createdRangeValues.to, timezone).format()}`;
|
||||
qs.created_at_range = `${moment
|
||||
.tz(createdRangeValues.from, timezone)
|
||||
.format()},${moment.tz(createdRangeValues.to, timezone).format()}`;
|
||||
}
|
||||
delete qs.createdRangeUi;
|
||||
}
|
||||
|
||||
if (additionalFields.updatedRangeUi) {
|
||||
const updateRangeValues = (additionalFields.updatedRangeUi as IDataObject).updatedRangeValuesUi as IDataObject;
|
||||
const updateRangeValues = (additionalFields.updatedRangeUi as IDataObject)
|
||||
.updatedRangeValuesUi as IDataObject;
|
||||
if (updateRangeValues) {
|
||||
qs.updated_at_range = `${moment.tz(updateRangeValues.from, timezone).format()},${moment.tz(updateRangeValues.to, timezone).format()}`;
|
||||
qs.updated_at_range = `${moment
|
||||
.tz(updateRangeValues.from, timezone)
|
||||
.format()},${moment.tz(updateRangeValues.to, timezone).format()}`;
|
||||
}
|
||||
delete qs.updatedRangeUi;
|
||||
}
|
||||
|
||||
if (returnAll) {
|
||||
responseData = await boxApiRequestAllItems.call(this, 'entries', 'GET', `/search`, {}, qs);
|
||||
responseData = await boxApiRequestAllItems.call(
|
||||
this,
|
||||
'entries',
|
||||
'GET',
|
||||
`/search`,
|
||||
{},
|
||||
qs,
|
||||
);
|
||||
} else {
|
||||
qs.limit = this.getNodeParameter('limit', i) as number;
|
||||
responseData = await boxApiRequest.call(this, 'GET', `/search`, {}, qs);
|
||||
@@ -414,13 +474,13 @@ export class Box implements INodeType {
|
||||
const accessibleBy = this.getNodeParameter('accessibleBy', i) as string;
|
||||
const options = this.getNodeParameter('options', i) as IDataObject;
|
||||
// tslint:disable-next-line: no-any
|
||||
const body: { accessible_by: IDataObject, [key: string]: any } = {
|
||||
const body: { accessible_by: IDataObject; [key: string]: any } = {
|
||||
accessible_by: {},
|
||||
item: {
|
||||
id: folderId,
|
||||
type: 'folder',
|
||||
},
|
||||
role: (role === 'coOwner') ? 'co-owner' : noCase(role),
|
||||
role: role === 'coOwner' ? 'co-owner' : noCase(role),
|
||||
...options,
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user