mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-19 11:01:15 +00:00
⚡ Add full continue-on-fail support to all nodes (#1996)
* Update Compression node * Update Crypto node * Update DateTime node * Update EditImage node * Update EmailSend node * Update ExecuteWorkflow node * Update FTP node * Update Function node * Update FunctionItem node * Update ExecuteCommand node * Update OpenWeatherMap node * Update ReadBinaryFile node * Update ReadPdf node * Update RssFeedRead node & add URL validation * Update SpreadsheetFile node * Update Switch node * Update WriteBinaryFile node * Update Xml node * Update ActiveCampaign node * Update Airtable node * Update ApiTemplateIo node * Update Asana node * Update AwsLambda node * Update AwsSns node * Update AwsComprehend node * Update AwsRekognition node * Update AwsS3 node * Fix Error item * Update AwsSes node * Update AwsSqs node * Update Amqp node * Update Bitly node * Update Box node * Update Brandfetch node * Update CircleCi node * Update Clearbit node * Update ClickUp node * Update Cockpit node * Update CoinGecko node * Update Contentful node * Update ConvertKit node * Update Cortex node * Update CustomerIo node * Update DeepL node * Update Demio node * Update Disqus node * Update Drift node * Update Dropbox node * Update GetResponse node * Refactor & Update Ghost node * Update Github node * Update Gitlab node * Update GoogleAnalytics node * Update GoogleBooks node * Update GoogleCalendar node * Update GoogleDrive node * Update Gmail node * Update GoogleSheets node * Update GoogleSlides node * Update GoogleTasks node * Update Gotify node * Update GraphQL node * Update HackerNews node * Update Harvest node * Update HtmlExtract node * Update Hubspot node * Update Hunter node * Update Intercom node * Update Kafka node * Refactor & update Line node * Update LinkedIn node * Update Mailchimp node * Update Mandrill node * Update Matrix node * Update Mautic node * Update Medium node * Update MessageBird node * Update Mindee node * Update Mocean node * Update MondayCom node * Update MicrosoftExcel node * Update MicrosoftOneDrive node * Update MicrosoftOutlook node * Update Affinity node * Update Chargebee node * Update Discourse node * Update Freshdesk node * Update YouTube node * Update InvoiceNinja node * Update MailerLite node * Update Mailgun node * Update Mailjet node * Update Mattermost node * Update Nasa node * Update NextCloud node * Update OpenThesaurus node * Update Orbit node * Update PagerDuty node * Update PayPal node * Update Peekalink node * Update Phantombuster node * Update PostHog node * Update ProfitWell node * Refactor & Update Pushbullet node * Update QuickBooks node * Update Raindrop node * Update Reddit node * Update Rocketchat node * Update S3 node * Update Salesforce node * Update SendGrid node * Update SentryIo node * Update Shopify node * Update Signl4 node * Update Slack node * Update Spontit node * Update Spotify node * Update Storyblok node * Refactor & Update Strapi node * Refactor & Update Strava node * Update Taiga node * Refactor & update Tapfiliate node * Update Telegram node * Update TheHive node * Update Todoist node * Update TravisCi node * Update Trello node * Update Twilio node * Update Twist node * Update Twitter node * Update Uplead node * Update UProc node * Update Vero node * Update Webflow node * Update Wekan node * Update Wordpress node * Update Xero node * Update Yourls node * Update Zendesk node * Update ZohoCrm node * Refactor & Update Zoom node * Update Zulip node * Update Clockify node * Update MongoDb node * Update MySql node * Update MicrosoftTeams node * Update Stackby node * Refactor Discourse node * Support corner-case in Github node update * Support corner-case in Gitlab node update * Refactor & Update GoogleContacts node * Refactor Mindee node * Update Coda node * Lint fixes * Update Beeminder node * Update Google Firebase RealtimeDatabase node * Update HelpScout node * Update Mailcheck node * Update Paddle node * Update Pipedrive node * Update Pushover node * Update Segment node * Refactor & Update Vonage node * Added new conditions to warnings on execute batch cmd * Added keep only properties flag * Fixed code for keep only props * Added dependencies for image editing Co-authored-by: dali <servfrdali@yahoo.fr>
This commit is contained in:
@@ -957,292 +957,302 @@ export class EditImage implements INodeType {
|
||||
let item: INodeExecutionData;
|
||||
|
||||
for (let itemIndex = 0; itemIndex < length; itemIndex++) {
|
||||
item = items[itemIndex];
|
||||
|
||||
try {
|
||||
|
||||
item = items[itemIndex];
|
||||
|
||||
|
||||
const operation = this.getNodeParameter('operation', itemIndex) as string;
|
||||
const dataPropertyName = this.getNodeParameter('dataPropertyName', itemIndex) as string;
|
||||
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> = [];
|
||||
const cleanupFunctions: Array<() => void> = [];
|
||||
|
||||
let gmInstance: gm.State;
|
||||
let gmInstance: gm.State;
|
||||
|
||||
const requiredOperationParameters: {
|
||||
[key: string]: string[],
|
||||
} = {
|
||||
blur: [
|
||||
'blur',
|
||||
'sigma',
|
||||
],
|
||||
border: [
|
||||
'borderColor',
|
||||
'borderWidth',
|
||||
'borderHeight',
|
||||
],
|
||||
create: [
|
||||
'backgroundColor',
|
||||
'height',
|
||||
'width',
|
||||
],
|
||||
crop: [
|
||||
'height',
|
||||
'positionX',
|
||||
'positionY',
|
||||
'width',
|
||||
],
|
||||
composite: [
|
||||
'dataPropertyNameComposite',
|
||||
'positionX',
|
||||
'positionY',
|
||||
],
|
||||
draw: [
|
||||
'color',
|
||||
'cornerRadius',
|
||||
'endPositionX',
|
||||
'endPositionY',
|
||||
'primitive',
|
||||
'startPositionX',
|
||||
'startPositionY',
|
||||
],
|
||||
information: [],
|
||||
resize: [
|
||||
'height',
|
||||
'resizeOption',
|
||||
'width',
|
||||
],
|
||||
rotate: [
|
||||
'backgroundColor',
|
||||
'rotate',
|
||||
],
|
||||
shear: [
|
||||
'degreesX',
|
||||
'degreesY',
|
||||
],
|
||||
text: [
|
||||
'font',
|
||||
'fontColor',
|
||||
'fontSize',
|
||||
'lineLength',
|
||||
'positionX',
|
||||
'positionY',
|
||||
'text',
|
||||
],
|
||||
};
|
||||
const requiredOperationParameters: {
|
||||
[key: string]: string[],
|
||||
} = {
|
||||
blur: [
|
||||
'blur',
|
||||
'sigma',
|
||||
],
|
||||
border: [
|
||||
'borderColor',
|
||||
'borderWidth',
|
||||
'borderHeight',
|
||||
],
|
||||
create: [
|
||||
'backgroundColor',
|
||||
'height',
|
||||
'width',
|
||||
],
|
||||
crop: [
|
||||
'height',
|
||||
'positionX',
|
||||
'positionY',
|
||||
'width',
|
||||
],
|
||||
composite: [
|
||||
'dataPropertyNameComposite',
|
||||
'positionX',
|
||||
'positionY',
|
||||
],
|
||||
draw: [
|
||||
'color',
|
||||
'cornerRadius',
|
||||
'endPositionX',
|
||||
'endPositionY',
|
||||
'primitive',
|
||||
'startPositionX',
|
||||
'startPositionY',
|
||||
],
|
||||
information: [],
|
||||
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;
|
||||
operations = operationsData.operations as IDataObject[];
|
||||
} else {
|
||||
// Operation parameters have to first get collected
|
||||
const operationParameters: IDataObject = {};
|
||||
requiredOperationParameters[operation].forEach(parameterName => {
|
||||
try {
|
||||
operationParameters[parameterName] = this.getNodeParameter(parameterName, itemIndex);
|
||||
} catch (error) {}
|
||||
});
|
||||
|
||||
operations = [
|
||||
{
|
||||
operation,
|
||||
...operationParameters,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
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.');
|
||||
}
|
||||
|
||||
if (item.binary[dataPropertyName as string] === undefined) {
|
||||
throw new NodeOperationError(this.getNode(), `Item does not contain any binary data with the name "${dataPropertyName}".`);
|
||||
}
|
||||
|
||||
gmInstance = gm(Buffer.from(item.binary![dataPropertyName as string].data, BINARY_ENCODING));
|
||||
gmInstance = gmInstance.background('transparent');
|
||||
}
|
||||
|
||||
if (operation === 'information') {
|
||||
// Just return the information
|
||||
const imageData = await new Promise<IDataObject>((resolve, reject) => {
|
||||
gmInstance = gmInstance.identify((error, imageData) => {
|
||||
if (error) {
|
||||
reject(error);
|
||||
return;
|
||||
}
|
||||
resolve(imageData as unknown as IDataObject);
|
||||
let operations: IDataObject[] = [];
|
||||
if (operation === 'multiStep') {
|
||||
// Operation parameters are already in the correct format
|
||||
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 => {
|
||||
try {
|
||||
operationParameters[parameterName] = this.getNodeParameter(parameterName, itemIndex);
|
||||
} catch (error) {}
|
||||
});
|
||||
});
|
||||
|
||||
item.json = imageData;
|
||||
returnData.push(item);
|
||||
}
|
||||
operations = [
|
||||
{
|
||||
operation,
|
||||
...operationParameters,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
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);
|
||||
} else if (operationData.operation === 'border') {
|
||||
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 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}".`);
|
||||
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.');
|
||||
}
|
||||
|
||||
const { fd, path, cleanup } = await file();
|
||||
cleanupFunctions.push(cleanup);
|
||||
await fsWriteFileAsync(fd, Buffer.from(item.binary![operationData.dataPropertyNameComposite as string].data, BINARY_ENCODING));
|
||||
|
||||
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')).geometry(geometryString).composite(path);
|
||||
} else {
|
||||
gmInstance = gmInstance!.geometry(geometryString).composite(path);
|
||||
if (item.binary[dataPropertyName as string] === undefined) {
|
||||
throw new NodeOperationError(this.getNode(), `Item does not contain any binary data with the name "${dataPropertyName}".`);
|
||||
}
|
||||
|
||||
if (operations.length !== i + 1) {
|
||||
// If there are other operations after the current one create a new gm instance
|
||||
// because else things do get messed up
|
||||
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';
|
||||
}
|
||||
} else if (operationData.operation === 'crop') {
|
||||
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);
|
||||
gmInstance = gm(Buffer.from(item.binary![dataPropertyName as string].data, BINARY_ENCODING));
|
||||
gmInstance = gmInstance.background('transparent');
|
||||
}
|
||||
|
||||
if (operationData.primitive === 'line') {
|
||||
gmInstance = gmInstance.drawLine(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);
|
||||
}
|
||||
} else if (operationData.operation === 'resize') {
|
||||
const resizeOption = operationData.resizeOption as string;
|
||||
|
||||
// By default use "maximumArea"
|
||||
let option: gm.ResizeOption = '@';
|
||||
if (resizeOption === 'ignoreAspectRatio') {
|
||||
option = '!';
|
||||
} else if (resizeOption === 'minimumArea') {
|
||||
option = '^';
|
||||
} else if (resizeOption === 'onlyIfSmaller') {
|
||||
option = '<';
|
||||
} else if (resizeOption === 'onlyIfLarger') {
|
||||
option = '>';
|
||||
} else if (resizeOption === 'percent') {
|
||||
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);
|
||||
} else if (operationData.operation === 'shear') {
|
||||
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)) {
|
||||
lines.push(currentLine.trim());
|
||||
currentLine = `${textPart} `;
|
||||
if (operation === 'information') {
|
||||
// Just return the information
|
||||
const imageData = await new Promise<IDataObject>((resolve, reject) => {
|
||||
gmInstance = gmInstance.identify((error, imageData) => {
|
||||
if (error) {
|
||||
reject(error);
|
||||
return;
|
||||
}
|
||||
currentLine += `${textPart} `;
|
||||
resolve(imageData as unknown as IDataObject);
|
||||
});
|
||||
|
||||
lines.push(currentLine.trim());
|
||||
currentLine = '';
|
||||
});
|
||||
|
||||
// Combine the lines to a single string
|
||||
const renderText = lines.join('\n');
|
||||
|
||||
const font = options.font || operationData.font;
|
||||
|
||||
if (font && font !== 'default') {
|
||||
gmInstance = gmInstance!.font(font as string);
|
||||
}
|
||||
|
||||
gmInstance = gmInstance!
|
||||
.fill(operationData.fontColor as string)
|
||||
.fontSize(operationData.fontSize as number)
|
||||
.drawText(operationData.positionX as number, operationData.positionY as number, renderText);
|
||||
item.json = imageData;
|
||||
returnData.push(item);
|
||||
}
|
||||
}
|
||||
|
||||
const newItem: INodeExecutionData = {
|
||||
json: item.json,
|
||||
binary: {},
|
||||
};
|
||||
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);
|
||||
} else if (operationData.operation === 'border') {
|
||||
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;
|
||||
|
||||
if (item.binary !== undefined) {
|
||||
// Create a shallow copy of the binary data so that the old
|
||||
// data references which do not get changed still stay behind
|
||||
// but the incoming data does not get changed.
|
||||
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]));
|
||||
}
|
||||
}
|
||||
const geometryString = (positionX >= 0 ? '+' : '') + positionX + (positionY >= 0 ? '+' : '') + positionY;
|
||||
|
||||
if (newItem.binary![dataPropertyName as string] === undefined) {
|
||||
newItem.binary![dataPropertyName as string] = {
|
||||
data: '',
|
||||
mimeType: '',
|
||||
};
|
||||
}
|
||||
|
||||
if (options.quality !== undefined) {
|
||||
gmInstance = gmInstance!.quality(options.quality as number);
|
||||
}
|
||||
|
||||
if (options.format !== undefined) {
|
||||
gmInstance = gmInstance!.setFormat(options.format as string);
|
||||
newItem.binary![dataPropertyName as string].fileExtension = options.format as string;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
if (options.fileName !== undefined) {
|
||||
newItem.binary![dataPropertyName as string].fileName = options.fileName as string;
|
||||
}
|
||||
|
||||
returnData.push(await (new Promise<INodeExecutionData>((resolve, reject) => {
|
||||
gmInstance
|
||||
.toBuffer((error: Error | null, buffer: Buffer) => {
|
||||
cleanupFunctions.forEach(async cleanup => await cleanup());
|
||||
|
||||
if (error) {
|
||||
return reject(error);
|
||||
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}".`);
|
||||
}
|
||||
|
||||
newItem.binary![dataPropertyName as string].data = buffer.toString(BINARY_ENCODING);
|
||||
const { fd, path, cleanup } = await file();
|
||||
cleanupFunctions.push(cleanup);
|
||||
await fsWriteFileAsync(fd, Buffer.from(item.binary![operationData.dataPropertyNameComposite as string].data, BINARY_ENCODING));
|
||||
|
||||
return resolve(newItem);
|
||||
});
|
||||
})));
|
||||
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')).geometry(geometryString).composite(path);
|
||||
} else {
|
||||
gmInstance = gmInstance!.geometry(geometryString).composite(path);
|
||||
}
|
||||
|
||||
if (operations.length !== i + 1) {
|
||||
// If there are other operations after the current one create a new gm instance
|
||||
// because else things do get messed up
|
||||
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';
|
||||
}
|
||||
} else if (operationData.operation === 'crop') {
|
||||
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);
|
||||
} 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);
|
||||
}
|
||||
} else if (operationData.operation === 'resize') {
|
||||
const resizeOption = operationData.resizeOption as string;
|
||||
|
||||
// By default use "maximumArea"
|
||||
let option: gm.ResizeOption = '@';
|
||||
if (resizeOption === 'ignoreAspectRatio') {
|
||||
option = '!';
|
||||
} else if (resizeOption === 'minimumArea') {
|
||||
option = '^';
|
||||
} else if (resizeOption === 'onlyIfSmaller') {
|
||||
option = '<';
|
||||
} else if (resizeOption === 'onlyIfLarger') {
|
||||
option = '>';
|
||||
} else if (resizeOption === 'percent') {
|
||||
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);
|
||||
} else if (operationData.operation === 'shear') {
|
||||
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)) {
|
||||
lines.push(currentLine.trim());
|
||||
currentLine = `${textPart} `;
|
||||
return;
|
||||
}
|
||||
currentLine += `${textPart} `;
|
||||
});
|
||||
|
||||
lines.push(currentLine.trim());
|
||||
currentLine = '';
|
||||
});
|
||||
|
||||
// Combine the lines to a single string
|
||||
const renderText = lines.join('\n');
|
||||
|
||||
const font = options.font || operationData.font;
|
||||
|
||||
if (font && font !== 'default') {
|
||||
gmInstance = gmInstance!.font(font as string);
|
||||
}
|
||||
|
||||
gmInstance = gmInstance!
|
||||
.fill(operationData.fontColor as string)
|
||||
.fontSize(operationData.fontSize as number)
|
||||
.drawText(operationData.positionX as number, operationData.positionY as number, renderText);
|
||||
}
|
||||
}
|
||||
|
||||
const newItem: INodeExecutionData = {
|
||||
json: item.json,
|
||||
binary: {},
|
||||
};
|
||||
|
||||
if (item.binary !== undefined) {
|
||||
// Create a shallow copy of the binary data so that the old
|
||||
// data references which do not get changed still stay behind
|
||||
// but the incoming data does not get changed.
|
||||
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]));
|
||||
}
|
||||
}
|
||||
|
||||
if (newItem.binary![dataPropertyName as string] === undefined) {
|
||||
newItem.binary![dataPropertyName as string] = {
|
||||
data: '',
|
||||
mimeType: '',
|
||||
};
|
||||
}
|
||||
|
||||
if (options.quality !== undefined) {
|
||||
gmInstance = gmInstance!.quality(options.quality as number);
|
||||
}
|
||||
|
||||
if (options.format !== undefined) {
|
||||
gmInstance = gmInstance!.setFormat(options.format as string);
|
||||
newItem.binary![dataPropertyName as string].fileExtension = options.format as string;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
if (options.fileName !== undefined) {
|
||||
newItem.binary![dataPropertyName as string].fileName = options.fileName as string;
|
||||
}
|
||||
|
||||
returnData.push(await (new Promise<INodeExecutionData>((resolve, reject) => {
|
||||
gmInstance
|
||||
.toBuffer((error: Error | null, buffer: Buffer) => {
|
||||
cleanupFunctions.forEach(async cleanup => await cleanup());
|
||||
|
||||
if (error) {
|
||||
return reject(error);
|
||||
}
|
||||
|
||||
newItem.binary![dataPropertyName as string].data = buffer.toString(BINARY_ENCODING);
|
||||
|
||||
return resolve(newItem);
|
||||
});
|
||||
})));
|
||||
|
||||
} catch (error) {
|
||||
if (this.continueOnFail()) {
|
||||
returnData.push({json:{ error: error.message }});
|
||||
continue;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
return this.prepareOutputData(returnData);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user