From b95a7e8ee8075cf9207baae67d587230c7573652 Mon Sep 17 00:00:00 2001 From: ricardo Date: Tue, 5 May 2020 19:36:12 -0400 Subject: [PATCH 1/2] :zap: improvements --- .../nodes/Bannerbear/Bannerbear.node.ts | 43 ++++++++++++++++++- .../nodes/Bannerbear/ImageDescription.ts | 16 ++++++- 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/packages/nodes-base/nodes/Bannerbear/Bannerbear.node.ts b/packages/nodes-base/nodes/Bannerbear/Bannerbear.node.ts index 8c0069c4a..d5e6f44fd 100644 --- a/packages/nodes-base/nodes/Bannerbear/Bannerbear.node.ts +++ b/packages/nodes-base/nodes/Bannerbear/Bannerbear.node.ts @@ -76,7 +76,7 @@ export class Bannerbear implements INodeType { methods = { loadOptions: { - // Get all the available escalation policies to display them to user so that he can + // Get all the available templates to display them to user so that he can // select them easily async getTemplates(this: ILoadOptionsFunctions): Promise { const returnData: INodePropertyOptions[] = []; @@ -91,6 +91,23 @@ export class Bannerbear implements INodeType { } return returnData; }, + + // Get all the available modifications to display them to user so that he can + // select them easily + async getModificationNames(this: ILoadOptionsFunctions): Promise { + const templateId = this.getCurrentNodeParameter('templateId'); + const returnData: INodePropertyOptions[] = []; + const { available_modifications } = await bannerbearApiRequest.call(this, 'GET', `/templates/${templateId}`); + for (const modification of available_modifications) { + const modificationName = modification.name; + const modificationId = modification.name; + returnData.push({ + name: modificationName, + value: modificationId, + }); + } + return returnData; + }, }, }; @@ -130,6 +147,30 @@ export class Bannerbear implements INodeType { } } responseData = await bannerbearApiRequest.call(this, 'POST', '/images', body); + if (additionalFields.waitForImage && responseData.status !== 'completed') { + let maxIntents = 2; + const promise = (uid: string) => { + let data: IDataObject = {}; + return new Promise((resolve, reject) => { + const timeout = setInterval(async () => { + if (!maxIntents) { + clearInterval(timeout); + reject(new Error('Image did not finish procesing after 2 intents')); + } + + data = await bannerbearApiRequest.call(this, 'GET', `/images/${uid}`); + + if (data.status === 'completed') { + clearInterval(timeout); + resolve(data); + } + maxIntents--; + }, 2000); + }); + }; + + responseData = await promise(responseData.uid); + } } //https://developers.bannerbear.com/#get-a-specific-image if (operation === 'get') { diff --git a/packages/nodes-base/nodes/Bannerbear/ImageDescription.ts b/packages/nodes-base/nodes/Bannerbear/ImageDescription.ts index a387f57f9..00cc1f644 100644 --- a/packages/nodes-base/nodes/Bannerbear/ImageDescription.ts +++ b/packages/nodes-base/nodes/Bannerbear/ImageDescription.ts @@ -88,6 +88,14 @@ export const imageFields = [ default: '', description: 'A url to POST the Image object to upon rendering completed', }, + { + displayName: 'Wait for Image', + name: 'waitForImage', + type: 'boolean', + default: false, + description: `Wait for the image to be proccesed before returning.
+ If after two tries the images is not ready an error will be thrown`, + }, ], }, { @@ -117,7 +125,13 @@ export const imageFields = [ { displayName: 'Name', name: 'name', - type: 'string', + type: 'options', + typeOptions: { + loadOptionsMethod: 'getModificationNames', + loadOptionsDependsOn: [ + 'templateId', + ], + }, default: '', description: 'The name of the item you want to change', }, From 12b93a5b52097eb1c6eeee4085357e536c284f79 Mon Sep 17 00:00:00 2001 From: Jan Oberhauser Date: Thu, 7 May 2020 00:44:39 +0200 Subject: [PATCH 2/2] :zap: Small improvements to Bannerbear-Node --- .../nodes/Bannerbear/Bannerbear.node.ts | 13 ++++--- .../nodes/Bannerbear/ImageDescription.ts | 35 ++++++++++++++----- 2 files changed, 33 insertions(+), 15 deletions(-) diff --git a/packages/nodes-base/nodes/Bannerbear/Bannerbear.node.ts b/packages/nodes-base/nodes/Bannerbear/Bannerbear.node.ts index d5e6f44fd..ea1ac2028 100644 --- a/packages/nodes-base/nodes/Bannerbear/Bannerbear.node.ts +++ b/packages/nodes-base/nodes/Bannerbear/Bannerbear.node.ts @@ -148,23 +148,22 @@ export class Bannerbear implements INodeType { } responseData = await bannerbearApiRequest.call(this, 'POST', '/images', body); if (additionalFields.waitForImage && responseData.status !== 'completed') { - let maxIntents = 2; + let maxTries = (additionalFields.waitForImageMaxTries as number) || 3; + const promise = (uid: string) => { let data: IDataObject = {}; return new Promise((resolve, reject) => { const timeout = setInterval(async () => { - if (!maxIntents) { - clearInterval(timeout); - reject(new Error('Image did not finish procesing after 2 intents')); - } - data = await bannerbearApiRequest.call(this, 'GET', `/images/${uid}`); if (data.status === 'completed') { clearInterval(timeout); resolve(data); } - maxIntents--; + if (--maxTries === 0) { + clearInterval(timeout); + reject(new Error('Image did not finish processing after multiple tries.')); + } }, 2000); }); }; diff --git a/packages/nodes-base/nodes/Bannerbear/ImageDescription.ts b/packages/nodes-base/nodes/Bannerbear/ImageDescription.ts index 00cc1f644..223368d92 100644 --- a/packages/nodes-base/nodes/Bannerbear/ImageDescription.ts +++ b/packages/nodes-base/nodes/Bannerbear/ImageDescription.ts @@ -81,6 +81,33 @@ export const imageFields = [ default: '', description: 'Metadata that you need to store e.g. ID of a record in your DB', }, + { + displayName: 'Wait for Image', + name: 'waitForImage', + type: 'boolean', + default: false, + description: `Wait for the image to be proccesed before returning.
+ If after three tries the images is not ready, an error will be thrown.
+ Number of tries can be increased by setting "Wait Max Tries".`, + }, + { + displayName: 'Wait Max Tries', + name: 'waitForImageMaxTries', + type: 'number', + typeOptions: { + minValue: 1, + maxValue: 10, + }, + displayOptions: { + show: { + waitForImage: [ + true, + ], + }, + }, + default: 3, + description: `How often it should check if the image is available before it fails.`, + }, { displayName: 'Webhook URL', name: 'webhookUrl', @@ -88,14 +115,6 @@ export const imageFields = [ default: '', description: 'A url to POST the Image object to upon rendering completed', }, - { - displayName: 'Wait for Image', - name: 'waitForImage', - type: 'boolean', - default: false, - description: `Wait for the image to be proccesed before returning.
- If after two tries the images is not ready an error will be thrown`, - }, ], }, {