mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +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,7 +1,4 @@
|
||||
import {
|
||||
BINARY_ENCODING,
|
||||
IExecuteFunctions,
|
||||
} from 'n8n-core';
|
||||
import { BINARY_ENCODING, IExecuteFunctions } from 'n8n-core';
|
||||
import {
|
||||
IDataObject,
|
||||
ILoadOptionsFunctions,
|
||||
@@ -14,17 +11,12 @@ import {
|
||||
} from 'n8n-workflow';
|
||||
import gm from 'gm';
|
||||
import { file } from 'tmp-promise';
|
||||
import {
|
||||
parse as pathParse,
|
||||
} from 'path';
|
||||
import {
|
||||
writeFile as fsWriteFile,
|
||||
} from 'fs';
|
||||
import { parse as pathParse } from 'path';
|
||||
import { writeFile as fsWriteFile } from 'fs';
|
||||
import { promisify } from 'util';
|
||||
const fsWriteFileAsync = promisify(fsWriteFile);
|
||||
import getSystemFonts from 'get-system-fonts';
|
||||
|
||||
|
||||
const nodeOperations: INodePropertyOptions[] = [
|
||||
{
|
||||
name: 'Blur',
|
||||
@@ -83,9 +75,7 @@ const nodeOperations: INodePropertyOptions[] = [
|
||||
},
|
||||
];
|
||||
|
||||
|
||||
const nodeOperationOptions: INodeProperties[] = [
|
||||
|
||||
// ----------------------------------
|
||||
// create
|
||||
// ----------------------------------
|
||||
@@ -99,9 +89,7 @@ const nodeOperationOptions: INodeProperties[] = [
|
||||
},
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: [
|
||||
'create',
|
||||
],
|
||||
operation: ['create'],
|
||||
},
|
||||
},
|
||||
description: 'The background color of the image to create',
|
||||
@@ -116,9 +104,7 @@ const nodeOperationOptions: INodeProperties[] = [
|
||||
},
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: [
|
||||
'create',
|
||||
],
|
||||
operation: ['create'],
|
||||
},
|
||||
},
|
||||
description: 'The width of the image to create',
|
||||
@@ -133,15 +119,12 @@ const nodeOperationOptions: INodeProperties[] = [
|
||||
},
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: [
|
||||
'create',
|
||||
],
|
||||
operation: ['create'],
|
||||
},
|
||||
},
|
||||
description: 'The height of the image to create',
|
||||
},
|
||||
|
||||
|
||||
// ----------------------------------
|
||||
// draw
|
||||
// ----------------------------------
|
||||
@@ -151,9 +134,7 @@ const nodeOperationOptions: INodeProperties[] = [
|
||||
type: 'options',
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: [
|
||||
'draw',
|
||||
],
|
||||
operation: ['draw'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
@@ -183,9 +164,7 @@ const nodeOperationOptions: INodeProperties[] = [
|
||||
},
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: [
|
||||
'draw',
|
||||
],
|
||||
operation: ['draw'],
|
||||
},
|
||||
},
|
||||
description: 'The color of the primitive to draw',
|
||||
@@ -197,14 +176,8 @@ const nodeOperationOptions: INodeProperties[] = [
|
||||
default: 50,
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: [
|
||||
'draw',
|
||||
],
|
||||
primitive: [
|
||||
'circle',
|
||||
'line',
|
||||
'rectangle',
|
||||
],
|
||||
operation: ['draw'],
|
||||
primitive: ['circle', 'line', 'rectangle'],
|
||||
},
|
||||
},
|
||||
description: 'X (horizontal) start position of the primitive',
|
||||
@@ -216,14 +189,8 @@ const nodeOperationOptions: INodeProperties[] = [
|
||||
default: 50,
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: [
|
||||
'draw',
|
||||
],
|
||||
primitive: [
|
||||
'circle',
|
||||
'line',
|
||||
'rectangle',
|
||||
],
|
||||
operation: ['draw'],
|
||||
primitive: ['circle', 'line', 'rectangle'],
|
||||
},
|
||||
},
|
||||
description: 'Y (horizontal) start position of the primitive',
|
||||
@@ -235,14 +202,8 @@ const nodeOperationOptions: INodeProperties[] = [
|
||||
default: 250,
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: [
|
||||
'draw',
|
||||
],
|
||||
primitive: [
|
||||
'circle',
|
||||
'line',
|
||||
'rectangle',
|
||||
],
|
||||
operation: ['draw'],
|
||||
primitive: ['circle', 'line', 'rectangle'],
|
||||
},
|
||||
},
|
||||
description: 'X (horizontal) end position of the primitive',
|
||||
@@ -254,14 +215,8 @@ const nodeOperationOptions: INodeProperties[] = [
|
||||
default: 250,
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: [
|
||||
'draw',
|
||||
],
|
||||
primitive: [
|
||||
'circle',
|
||||
'line',
|
||||
'rectangle',
|
||||
],
|
||||
operation: ['draw'],
|
||||
primitive: ['circle', 'line', 'rectangle'],
|
||||
},
|
||||
},
|
||||
description: 'Y (horizontal) end position of the primitive',
|
||||
@@ -273,12 +228,8 @@ const nodeOperationOptions: INodeProperties[] = [
|
||||
default: 0,
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: [
|
||||
'draw',
|
||||
],
|
||||
primitive: [
|
||||
'rectangle',
|
||||
],
|
||||
operation: ['draw'],
|
||||
primitive: ['rectangle'],
|
||||
},
|
||||
},
|
||||
description: 'The radius of the corner to create round corners',
|
||||
@@ -298,9 +249,7 @@ const nodeOperationOptions: INodeProperties[] = [
|
||||
placeholder: 'Text to render',
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: [
|
||||
'text',
|
||||
],
|
||||
operation: ['text'],
|
||||
},
|
||||
},
|
||||
description: 'Text to write on the image',
|
||||
@@ -312,9 +261,7 @@ const nodeOperationOptions: INodeProperties[] = [
|
||||
default: 18,
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: [
|
||||
'text',
|
||||
],
|
||||
operation: ['text'],
|
||||
},
|
||||
},
|
||||
description: 'Size of the text',
|
||||
@@ -326,9 +273,7 @@ const nodeOperationOptions: INodeProperties[] = [
|
||||
default: '#000000',
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: [
|
||||
'text',
|
||||
],
|
||||
operation: ['text'],
|
||||
},
|
||||
},
|
||||
description: 'Color of the text',
|
||||
@@ -340,9 +285,7 @@ const nodeOperationOptions: INodeProperties[] = [
|
||||
default: 50,
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: [
|
||||
'text',
|
||||
],
|
||||
operation: ['text'],
|
||||
},
|
||||
},
|
||||
description: 'X (horizontal) position of the text',
|
||||
@@ -354,9 +297,7 @@ const nodeOperationOptions: INodeProperties[] = [
|
||||
default: 50,
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: [
|
||||
'text',
|
||||
],
|
||||
operation: ['text'],
|
||||
},
|
||||
},
|
||||
description: 'Y (vertical) position of the text',
|
||||
@@ -371,9 +312,7 @@ const nodeOperationOptions: INodeProperties[] = [
|
||||
default: 80,
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: [
|
||||
'text',
|
||||
],
|
||||
operation: ['text'],
|
||||
},
|
||||
},
|
||||
description: 'Max amount of characters in a line before a line-break should get added',
|
||||
@@ -393,9 +332,7 @@ const nodeOperationOptions: INodeProperties[] = [
|
||||
default: 5,
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: [
|
||||
'blur',
|
||||
],
|
||||
operation: ['blur'],
|
||||
},
|
||||
},
|
||||
description: 'How strong the blur should be',
|
||||
@@ -411,15 +348,12 @@ const nodeOperationOptions: INodeProperties[] = [
|
||||
default: 2,
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: [
|
||||
'blur',
|
||||
],
|
||||
operation: ['blur'],
|
||||
},
|
||||
},
|
||||
description: 'The sigma of the blur',
|
||||
},
|
||||
|
||||
|
||||
// ----------------------------------
|
||||
// border
|
||||
// ----------------------------------
|
||||
@@ -430,9 +364,7 @@ const nodeOperationOptions: INodeProperties[] = [
|
||||
default: 10,
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: [
|
||||
'border',
|
||||
],
|
||||
operation: ['border'],
|
||||
},
|
||||
},
|
||||
description: 'The width of the border',
|
||||
@@ -444,9 +376,7 @@ const nodeOperationOptions: INodeProperties[] = [
|
||||
default: 10,
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: [
|
||||
'border',
|
||||
],
|
||||
operation: ['border'],
|
||||
},
|
||||
},
|
||||
description: 'The height of the border',
|
||||
@@ -458,15 +388,12 @@ const nodeOperationOptions: INodeProperties[] = [
|
||||
default: '#000000',
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: [
|
||||
'border',
|
||||
],
|
||||
operation: ['border'],
|
||||
},
|
||||
},
|
||||
description: 'Color of the border',
|
||||
},
|
||||
|
||||
|
||||
// ----------------------------------
|
||||
// composite
|
||||
// ----------------------------------
|
||||
@@ -478,12 +405,11 @@ const nodeOperationOptions: INodeProperties[] = [
|
||||
placeholder: 'data2',
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: [
|
||||
'composite',
|
||||
],
|
||||
operation: ['composite'],
|
||||
},
|
||||
},
|
||||
description: 'The name of the binary property which contains the data of the image to composite on top of image which is found in Property Name',
|
||||
description:
|
||||
'The name of the binary property which contains the data of the image to composite on top of image which is found in Property Name',
|
||||
},
|
||||
{
|
||||
displayName: 'Operator',
|
||||
@@ -491,9 +417,7 @@ const nodeOperationOptions: INodeProperties[] = [
|
||||
type: 'options',
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: [
|
||||
'composite',
|
||||
],
|
||||
operation: ['composite'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
@@ -596,9 +520,7 @@ const nodeOperationOptions: INodeProperties[] = [
|
||||
default: 0,
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: [
|
||||
'composite',
|
||||
],
|
||||
operation: ['composite'],
|
||||
},
|
||||
},
|
||||
description: 'X (horizontal) position of composite image',
|
||||
@@ -610,9 +532,7 @@ const nodeOperationOptions: INodeProperties[] = [
|
||||
default: 0,
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: [
|
||||
'composite',
|
||||
],
|
||||
operation: ['composite'],
|
||||
},
|
||||
},
|
||||
description: 'Y (vertical) position of composite image',
|
||||
@@ -628,9 +548,7 @@ const nodeOperationOptions: INodeProperties[] = [
|
||||
default: 500,
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: [
|
||||
'crop',
|
||||
],
|
||||
operation: ['crop'],
|
||||
},
|
||||
},
|
||||
description: 'Crop width',
|
||||
@@ -642,9 +560,7 @@ const nodeOperationOptions: INodeProperties[] = [
|
||||
default: 500,
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: [
|
||||
'crop',
|
||||
],
|
||||
operation: ['crop'],
|
||||
},
|
||||
},
|
||||
description: 'Crop height',
|
||||
@@ -656,9 +572,7 @@ const nodeOperationOptions: INodeProperties[] = [
|
||||
default: 0,
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: [
|
||||
'crop',
|
||||
],
|
||||
operation: ['crop'],
|
||||
},
|
||||
},
|
||||
description: 'X (horizontal) position to crop from',
|
||||
@@ -670,9 +584,7 @@ const nodeOperationOptions: INodeProperties[] = [
|
||||
default: 0,
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: [
|
||||
'crop',
|
||||
],
|
||||
operation: ['crop'],
|
||||
},
|
||||
},
|
||||
description: 'Y (vertical) position to crop from',
|
||||
@@ -688,9 +600,7 @@ const nodeOperationOptions: INodeProperties[] = [
|
||||
default: 500,
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: [
|
||||
'resize',
|
||||
],
|
||||
operation: ['resize'],
|
||||
},
|
||||
},
|
||||
description: 'New width of the image',
|
||||
@@ -702,9 +612,7 @@ const nodeOperationOptions: INodeProperties[] = [
|
||||
default: 500,
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: [
|
||||
'resize',
|
||||
],
|
||||
operation: ['resize'],
|
||||
},
|
||||
},
|
||||
description: 'New height of the image',
|
||||
@@ -748,9 +656,7 @@ const nodeOperationOptions: INodeProperties[] = [
|
||||
default: 'maximumArea',
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: [
|
||||
'resize',
|
||||
],
|
||||
operation: ['resize'],
|
||||
},
|
||||
},
|
||||
description: 'How to resize the image',
|
||||
@@ -770,9 +676,7 @@ const nodeOperationOptions: INodeProperties[] = [
|
||||
default: 0,
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: [
|
||||
'rotate',
|
||||
],
|
||||
operation: ['rotate'],
|
||||
},
|
||||
},
|
||||
description: 'How much the image should be rotated',
|
||||
@@ -787,15 +691,13 @@ const nodeOperationOptions: INodeProperties[] = [
|
||||
},
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: [
|
||||
'rotate',
|
||||
],
|
||||
operation: ['rotate'],
|
||||
},
|
||||
},
|
||||
description: 'The color to use for the background when image gets rotated by anything which is not a multiple of 90',
|
||||
description:
|
||||
'The color to use for the background when image gets rotated by anything which is not a multiple of 90',
|
||||
},
|
||||
|
||||
|
||||
// ----------------------------------
|
||||
// shear
|
||||
// ----------------------------------
|
||||
@@ -806,9 +708,7 @@ const nodeOperationOptions: INodeProperties[] = [
|
||||
default: 0,
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: [
|
||||
'shear',
|
||||
],
|
||||
operation: ['shear'],
|
||||
},
|
||||
},
|
||||
description: 'X (horizontal) shear degrees',
|
||||
@@ -820,15 +720,12 @@ const nodeOperationOptions: INodeProperties[] = [
|
||||
default: 0,
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: [
|
||||
'shear',
|
||||
],
|
||||
operation: ['shear'],
|
||||
},
|
||||
},
|
||||
description: 'Y (vertical) shear degrees',
|
||||
},
|
||||
|
||||
|
||||
// ----------------------------------
|
||||
// transparent
|
||||
// ----------------------------------
|
||||
@@ -839,16 +736,13 @@ const nodeOperationOptions: INodeProperties[] = [
|
||||
default: '#ff0000',
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: [
|
||||
'transparent',
|
||||
],
|
||||
operation: ['transparent'],
|
||||
},
|
||||
},
|
||||
description: 'The color to make transparent',
|
||||
},
|
||||
];
|
||||
|
||||
|
||||
export class EditImage implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
displayName: 'Edit Image',
|
||||
@@ -882,8 +776,18 @@ export class EditImage implements INodeType {
|
||||
},
|
||||
...nodeOperations,
|
||||
].sort((a, b) => {
|
||||
if ((a as INodePropertyOptions).name.toLowerCase() < (b as INodePropertyOptions).name.toLowerCase()) { return -1; }
|
||||
if ((a as INodePropertyOptions).name.toLowerCase() > (b as INodePropertyOptions).name.toLowerCase()) { return 1; }
|
||||
if (
|
||||
(a as INodePropertyOptions).name.toLowerCase() <
|
||||
(b as INodePropertyOptions).name.toLowerCase()
|
||||
) {
|
||||
return -1;
|
||||
}
|
||||
if (
|
||||
(a as INodePropertyOptions).name.toLowerCase() >
|
||||
(b as INodePropertyOptions).name.toLowerCase()
|
||||
) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}) as INodePropertyOptions[],
|
||||
default: 'border',
|
||||
@@ -896,7 +800,6 @@ export class EditImage implements INodeType {
|
||||
description: 'Name of the binary property in which the image data can be found',
|
||||
},
|
||||
|
||||
|
||||
// ----------------------------------
|
||||
// multiStep
|
||||
// ----------------------------------
|
||||
@@ -911,9 +814,7 @@ export class EditImage implements INodeType {
|
||||
},
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: [
|
||||
'multiStep',
|
||||
],
|
||||
operation: ['multiStep'],
|
||||
},
|
||||
},
|
||||
description: 'The operations to perform',
|
||||
@@ -938,16 +839,15 @@ export class EditImage implements INodeType {
|
||||
type: 'options',
|
||||
displayOptions: {
|
||||
show: {
|
||||
'operation': [
|
||||
'text',
|
||||
],
|
||||
operation: ['text'],
|
||||
},
|
||||
},
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getFonts',
|
||||
},
|
||||
default: 'default',
|
||||
description: 'The font to use. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
|
||||
description:
|
||||
'The font to use. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
|
||||
},
|
||||
],
|
||||
},
|
||||
@@ -963,9 +863,7 @@ export class EditImage implements INodeType {
|
||||
default: {},
|
||||
displayOptions: {
|
||||
hide: {
|
||||
operation: [
|
||||
'information',
|
||||
],
|
||||
operation: ['information'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
@@ -982,16 +880,15 @@ export class EditImage implements INodeType {
|
||||
type: 'options',
|
||||
displayOptions: {
|
||||
show: {
|
||||
'/operation': [
|
||||
'text',
|
||||
],
|
||||
'/operation': ['text'],
|
||||
},
|
||||
},
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getFonts',
|
||||
},
|
||||
default: 'default',
|
||||
description: 'The font to use. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
|
||||
description:
|
||||
'The font to use. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
|
||||
},
|
||||
{
|
||||
displayName: 'Format',
|
||||
@@ -1033,11 +930,7 @@ export class EditImage implements INodeType {
|
||||
default: 100,
|
||||
displayOptions: {
|
||||
show: {
|
||||
format: [
|
||||
'jpeg',
|
||||
'png',
|
||||
'tiff',
|
||||
],
|
||||
format: ['jpeg', 'png', 'tiff'],
|
||||
},
|
||||
},
|
||||
description: 'Sets the jpeg|png|tiff compression level from 0 to 100 (best)',
|
||||
@@ -1047,11 +940,9 @@ export class EditImage implements INodeType {
|
||||
],
|
||||
};
|
||||
|
||||
|
||||
methods = {
|
||||
loadOptions: {
|
||||
async getFonts(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||
|
||||
// @ts-ignore
|
||||
const files = await getSystemFonts();
|
||||
const returnData: INodePropertyOptions[] = [];
|
||||
@@ -1069,8 +960,12 @@ export class EditImage implements INodeType {
|
||||
});
|
||||
|
||||
returnData.sort((a, b) => {
|
||||
if (a.name < b.name) { return -1; }
|
||||
if (a.name > b.name) { return 1; }
|
||||
if (a.name < b.name) {
|
||||
return -1;
|
||||
}
|
||||
if (a.name > b.name) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
|
||||
@@ -1081,7 +976,6 @@ export class EditImage implements INodeType {
|
||||
|
||||
return returnData;
|
||||
},
|
||||
|
||||
},
|
||||
};
|
||||
|
||||
@@ -1093,50 +987,26 @@ export class EditImage implements INodeType {
|
||||
let item: INodeExecutionData;
|
||||
|
||||
for (let itemIndex = 0; itemIndex < length; itemIndex++) {
|
||||
|
||||
try {
|
||||
|
||||
item = items[itemIndex];
|
||||
|
||||
|
||||
const operation = this.getNodeParameter('operation', itemIndex) as string;
|
||||
const dataPropertyName = this.getNodeParameter('dataPropertyName', itemIndex) as string;
|
||||
|
||||
const options = this.getNodeParameter('options', itemIndex,{}) as IDataObject;
|
||||
const options = this.getNodeParameter('options', itemIndex, {}) as IDataObject;
|
||||
|
||||
const cleanupFunctions: Array<() => void> = [];
|
||||
|
||||
let gmInstance: gm.State;
|
||||
|
||||
const requiredOperationParameters: {
|
||||
[key: string]: string[],
|
||||
[key: string]: string[];
|
||||
} = {
|
||||
blur: [
|
||||
'blur',
|
||||
'sigma',
|
||||
],
|
||||
border: [
|
||||
'borderColor',
|
||||
'borderWidth',
|
||||
'borderHeight',
|
||||
],
|
||||
create: [
|
||||
'backgroundColor',
|
||||
'height',
|
||||
'width',
|
||||
],
|
||||
crop: [
|
||||
'height',
|
||||
'positionX',
|
||||
'positionY',
|
||||
'width',
|
||||
],
|
||||
composite: [
|
||||
'dataPropertyNameComposite',
|
||||
'operator',
|
||||
'positionX',
|
||||
'positionY',
|
||||
],
|
||||
blur: ['blur', 'sigma'],
|
||||
border: ['borderColor', 'borderWidth', 'borderHeight'],
|
||||
create: ['backgroundColor', 'height', 'width'],
|
||||
crop: ['height', 'positionX', 'positionY', 'width'],
|
||||
composite: ['dataPropertyNameComposite', 'operator', 'positionX', 'positionY'],
|
||||
draw: [
|
||||
'color',
|
||||
'cornerRadius',
|
||||
@@ -1147,39 +1017,23 @@ export class EditImage implements INodeType {
|
||||
'startPositionY',
|
||||
],
|
||||
information: [],
|
||||
resize: [
|
||||
'height',
|
||||
'resizeOption',
|
||||
'width',
|
||||
],
|
||||
rotate: [
|
||||
'backgroundColor',
|
||||
'rotate',
|
||||
],
|
||||
shear: [
|
||||
'degreesX',
|
||||
'degreesY',
|
||||
],
|
||||
text: [
|
||||
'font',
|
||||
'fontColor',
|
||||
'fontSize',
|
||||
'lineLength',
|
||||
'positionX',
|
||||
'positionY',
|
||||
'text',
|
||||
],
|
||||
resize: ['height', 'resizeOption', 'width'],
|
||||
rotate: ['backgroundColor', 'rotate'],
|
||||
shear: ['degreesX', 'degreesY'],
|
||||
text: ['font', 'fontColor', 'fontSize', 'lineLength', 'positionX', 'positionY', 'text'],
|
||||
};
|
||||
|
||||
let operations: IDataObject[] = [];
|
||||
if (operation === 'multiStep') {
|
||||
// Operation parameters are already in the correct format
|
||||
const operationsData = this.getNodeParameter('operations', itemIndex ,{ operations: [] }) as IDataObject;
|
||||
const operationsData = this.getNodeParameter('operations', itemIndex, {
|
||||
operations: [],
|
||||
}) as IDataObject;
|
||||
operations = operationsData.operations as IDataObject[];
|
||||
} else {
|
||||
// Operation parameters have to first get collected
|
||||
const operationParameters: IDataObject = {};
|
||||
requiredOperationParameters[operation].forEach(parameterName => {
|
||||
requiredOperationParameters[operation].forEach((parameterName) => {
|
||||
try {
|
||||
operationParameters[parameterName] = this.getNodeParameter(parameterName, itemIndex);
|
||||
} catch (error) {}
|
||||
@@ -1196,14 +1050,23 @@ export class EditImage implements INodeType {
|
||||
if (operations[0].operation !== 'create') {
|
||||
// "create" generates a new image so does not require any incoming data.
|
||||
if (item.binary === undefined) {
|
||||
throw new NodeOperationError(this.getNode(), 'Item does not contain any binary data.', { itemIndex });
|
||||
throw new NodeOperationError(this.getNode(), 'Item does not contain any binary data.', {
|
||||
itemIndex,
|
||||
});
|
||||
}
|
||||
|
||||
if (item.binary[dataPropertyName as string] === undefined) {
|
||||
throw new NodeOperationError(this.getNode(), `Item does not contain any binary data with the name "${dataPropertyName}".`, { itemIndex });
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
`Item does not contain any binary data with the name "${dataPropertyName}".`,
|
||||
{ itemIndex },
|
||||
);
|
||||
}
|
||||
|
||||
const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(itemIndex, dataPropertyName);
|
||||
const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(
|
||||
itemIndex,
|
||||
dataPropertyName,
|
||||
);
|
||||
gmInstance = gm(binaryDataBuffer);
|
||||
gmInstance = gmInstance.background('transparent');
|
||||
}
|
||||
@@ -1234,29 +1097,45 @@ export class EditImage implements INodeType {
|
||||
for (let i = 0; i < operations.length; i++) {
|
||||
const operationData = operations[i];
|
||||
if (operationData.operation === 'blur') {
|
||||
gmInstance = gmInstance!.blur(operationData.blur as number, operationData.sigma as number);
|
||||
gmInstance = gmInstance!.blur(
|
||||
operationData.blur as number,
|
||||
operationData.sigma as number,
|
||||
);
|
||||
} else if (operationData.operation === 'border') {
|
||||
gmInstance = gmInstance!.borderColor(operationData.borderColor as string).border(operationData.borderWidth as number, operationData.borderHeight as number);
|
||||
gmInstance = gmInstance!
|
||||
.borderColor(operationData.borderColor as string)
|
||||
.border(operationData.borderWidth as number, operationData.borderHeight as number);
|
||||
} else if (operationData.operation === 'composite') {
|
||||
const positionX = operationData.positionX as number;
|
||||
const positionY = operationData.positionY as number;
|
||||
const operator = operationData.operator as string;
|
||||
|
||||
const geometryString = (positionX >= 0 ? '+' : '') + positionX + (positionY >= 0 ? '+' : '') + positionY;
|
||||
const geometryString =
|
||||
(positionX >= 0 ? '+' : '') + positionX + (positionY >= 0 ? '+' : '') + positionY;
|
||||
|
||||
if (item.binary![operationData.dataPropertyNameComposite as string] === undefined) {
|
||||
throw new NodeOperationError(this.getNode(), `Item does not contain any binary data with the name "${operationData.dataPropertyNameComposite}".`, { itemIndex });
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
`Item does not contain any binary data with the name "${operationData.dataPropertyNameComposite}".`,
|
||||
{ itemIndex },
|
||||
);
|
||||
}
|
||||
|
||||
const { fd, path, cleanup } = await file();
|
||||
cleanupFunctions.push(cleanup);
|
||||
const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(itemIndex, operationData.dataPropertyNameComposite as string);
|
||||
const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(
|
||||
itemIndex,
|
||||
operationData.dataPropertyNameComposite as string,
|
||||
);
|
||||
await fsWriteFileAsync(fd, binaryDataBuffer);
|
||||
|
||||
if (operations[0].operation === 'create') {
|
||||
// It seems like if the image gets created newly we have to create a new gm instance
|
||||
// else it fails for some reason
|
||||
gmInstance = gm(gmInstance!.stream('png')).compose(operator).geometry(geometryString).composite(path);
|
||||
gmInstance = gm(gmInstance!.stream('png'))
|
||||
.compose(operator)
|
||||
.geometry(geometryString)
|
||||
.composite(path);
|
||||
} else {
|
||||
gmInstance = gmInstance!.compose(operator).geometry(geometryString).composite(path);
|
||||
}
|
||||
@@ -1267,21 +1146,46 @@ export class EditImage implements INodeType {
|
||||
gmInstance = gm(gmInstance.stream());
|
||||
}
|
||||
} else if (operationData.operation === 'create') {
|
||||
gmInstance = gm(operationData.width as number, operationData.height as number, operationData.backgroundColor as string);
|
||||
if (!options.format) {
|
||||
options.format = 'png';
|
||||
}
|
||||
gmInstance = gm(
|
||||
operationData.width as number,
|
||||
operationData.height as number,
|
||||
operationData.backgroundColor as string,
|
||||
);
|
||||
if (!options.format) {
|
||||
options.format = 'png';
|
||||
}
|
||||
} else if (operationData.operation === 'crop') {
|
||||
gmInstance = gmInstance!.crop(operationData.width as number, operationData.height as number, operationData.positionX as number, operationData.positionY as number);
|
||||
gmInstance = gmInstance!.crop(
|
||||
operationData.width as number,
|
||||
operationData.height as number,
|
||||
operationData.positionX as number,
|
||||
operationData.positionY as number,
|
||||
);
|
||||
} else if (operationData.operation === 'draw') {
|
||||
gmInstance = gmInstance!.fill(operationData.color as string);
|
||||
|
||||
if (operationData.primitive === 'line') {
|
||||
gmInstance = gmInstance.drawLine(operationData.startPositionX as number, operationData.startPositionY as number, operationData.endPositionX as number, operationData.endPositionY as number);
|
||||
gmInstance = gmInstance.drawLine(
|
||||
operationData.startPositionX as number,
|
||||
operationData.startPositionY as number,
|
||||
operationData.endPositionX as number,
|
||||
operationData.endPositionY as number,
|
||||
);
|
||||
} else if (operationData.primitive === 'circle') {
|
||||
gmInstance = gmInstance.drawCircle(operationData.startPositionX as number, operationData.startPositionY as number, operationData.endPositionX as number, operationData.endPositionY as number);
|
||||
gmInstance = gmInstance.drawCircle(
|
||||
operationData.startPositionX as number,
|
||||
operationData.startPositionY as number,
|
||||
operationData.endPositionX as number,
|
||||
operationData.endPositionY as number,
|
||||
);
|
||||
} else if (operationData.primitive === 'rectangle') {
|
||||
gmInstance = gmInstance.drawRectangle(operationData.startPositionX as number, operationData.startPositionY as number, operationData.endPositionX as number, operationData.endPositionY as number, operationData.cornerRadius as number || undefined);
|
||||
gmInstance = gmInstance.drawRectangle(
|
||||
operationData.startPositionX as number,
|
||||
operationData.startPositionY as number,
|
||||
operationData.endPositionX as number,
|
||||
operationData.endPositionY as number,
|
||||
(operationData.cornerRadius as number) || undefined,
|
||||
);
|
||||
}
|
||||
} else if (operationData.operation === 'resize') {
|
||||
const resizeOption = operationData.resizeOption as string;
|
||||
@@ -1300,18 +1204,31 @@ export class EditImage implements INodeType {
|
||||
option = '%';
|
||||
}
|
||||
|
||||
gmInstance = gmInstance!.resize(operationData.width as number, operationData.height as number, option);
|
||||
gmInstance = gmInstance!.resize(
|
||||
operationData.width as number,
|
||||
operationData.height as number,
|
||||
option,
|
||||
);
|
||||
} else if (operationData.operation === 'rotate') {
|
||||
gmInstance = gmInstance!.rotate(operationData.backgroundColor as string, operationData.rotate as number);
|
||||
gmInstance = gmInstance!.rotate(
|
||||
operationData.backgroundColor as string,
|
||||
operationData.rotate as number,
|
||||
);
|
||||
} else if (operationData.operation === 'shear') {
|
||||
gmInstance = gmInstance!.shear(operationData.degreesX as number, operationData.degreesY as number);
|
||||
gmInstance = gmInstance!.shear(
|
||||
operationData.degreesX as number,
|
||||
operationData.degreesY as number,
|
||||
);
|
||||
} else if (operationData.operation === 'text') {
|
||||
// Split the text in multiple lines
|
||||
const lines: string[] = [];
|
||||
let currentLine = '';
|
||||
(operationData.text as string).split('\n').forEach((textLine: string) => {
|
||||
textLine.split(' ').forEach((textPart: string) => {
|
||||
if ((currentLine.length + textPart.length + 1) > (operationData.lineLength as number)) {
|
||||
if (
|
||||
currentLine.length + textPart.length + 1 >
|
||||
(operationData.lineLength as number)
|
||||
) {
|
||||
lines.push(currentLine.trim());
|
||||
currentLine = `${textPart} `;
|
||||
return;
|
||||
@@ -1335,10 +1252,14 @@ export class EditImage implements INodeType {
|
||||
gmInstance = gmInstance!
|
||||
.fill(operationData.fontColor as string)
|
||||
.fontSize(operationData.fontSize as number)
|
||||
.drawText(operationData.positionX as number, operationData.positionY as number, renderText);
|
||||
} else if (operationData.operation === 'transparent') {
|
||||
gmInstance = gmInstance!.transparent(operationData.color as string);
|
||||
}
|
||||
.drawText(
|
||||
operationData.positionX as number,
|
||||
operationData.positionY as number,
|
||||
renderText,
|
||||
);
|
||||
} else if (operationData.operation === 'transparent') {
|
||||
gmInstance = gmInstance!.transparent(operationData.color as string);
|
||||
}
|
||||
}
|
||||
|
||||
if (item.binary !== undefined) {
|
||||
@@ -1348,7 +1269,9 @@ export class EditImage implements INodeType {
|
||||
Object.assign(newItem.binary, item.binary);
|
||||
// Make a deep copy of the binary data we change
|
||||
if (newItem.binary![dataPropertyName as string]) {
|
||||
newItem.binary![dataPropertyName as string] = JSON.parse(JSON.stringify(newItem.binary![dataPropertyName as string]));
|
||||
newItem.binary![dataPropertyName as string] = JSON.parse(
|
||||
JSON.stringify(newItem.binary![dataPropertyName as string]),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1369,7 +1292,8 @@ export class EditImage implements INodeType {
|
||||
newItem.binary![dataPropertyName as string].mimeType = `image/${options.format}`;
|
||||
const fileName = newItem.binary![dataPropertyName as string].fileName;
|
||||
if (fileName && fileName.includes('.')) {
|
||||
newItem.binary![dataPropertyName as string].fileName = fileName.split('.').slice(0, -1).join('.') + '.' + options.format;
|
||||
newItem.binary![dataPropertyName as string].fileName =
|
||||
fileName.split('.').slice(0, -1).join('.') + '.' + options.format;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1377,10 +1301,10 @@ export class EditImage implements INodeType {
|
||||
newItem.binary![dataPropertyName as string].fileName = options.fileName as string;
|
||||
}
|
||||
|
||||
returnData.push(await (new Promise<INodeExecutionData>((resolve, reject) => {
|
||||
gmInstance
|
||||
.toBuffer(async (error: Error | null, buffer: Buffer) => {
|
||||
cleanupFunctions.forEach(async cleanup => await cleanup());
|
||||
returnData.push(
|
||||
await new Promise<INodeExecutionData>((resolve, reject) => {
|
||||
gmInstance.toBuffer(async (error: Error | null, buffer: Buffer) => {
|
||||
cleanupFunctions.forEach(async (cleanup) => await cleanup());
|
||||
|
||||
if (error) {
|
||||
return reject(error);
|
||||
@@ -1388,13 +1312,14 @@ export class EditImage implements INodeType {
|
||||
|
||||
const binaryData = await this.helpers.prepareBinaryData(Buffer.from(buffer));
|
||||
newItem.binary![dataPropertyName as string] = {
|
||||
...newItem.binary![dataPropertyName as string], ...binaryData,
|
||||
...newItem.binary![dataPropertyName as string],
|
||||
...binaryData,
|
||||
};
|
||||
|
||||
return resolve(newItem);
|
||||
});
|
||||
})));
|
||||
|
||||
}),
|
||||
);
|
||||
} catch (error) {
|
||||
if (this.continueOnFail()) {
|
||||
returnData.push({
|
||||
|
||||
Reference in New Issue
Block a user