mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-10 14:44:05 -08:00
⚡ Small improvements to Bannerbear-Node
This commit is contained in:
parent
adae987d46
commit
12b93a5b52
|
@ -148,23 +148,22 @@ export class Bannerbear implements INodeType {
|
||||||
}
|
}
|
||||||
responseData = await bannerbearApiRequest.call(this, 'POST', '/images', body);
|
responseData = await bannerbearApiRequest.call(this, 'POST', '/images', body);
|
||||||
if (additionalFields.waitForImage && responseData.status !== 'completed') {
|
if (additionalFields.waitForImage && responseData.status !== 'completed') {
|
||||||
let maxIntents = 2;
|
let maxTries = (additionalFields.waitForImageMaxTries as number) || 3;
|
||||||
|
|
||||||
const promise = (uid: string) => {
|
const promise = (uid: string) => {
|
||||||
let data: IDataObject = {};
|
let data: IDataObject = {};
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const timeout = setInterval(async () => {
|
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}`);
|
data = await bannerbearApiRequest.call(this, 'GET', `/images/${uid}`);
|
||||||
|
|
||||||
if (data.status === 'completed') {
|
if (data.status === 'completed') {
|
||||||
clearInterval(timeout);
|
clearInterval(timeout);
|
||||||
resolve(data);
|
resolve(data);
|
||||||
}
|
}
|
||||||
maxIntents--;
|
if (--maxTries === 0) {
|
||||||
|
clearInterval(timeout);
|
||||||
|
reject(new Error('Image did not finish processing after multiple tries.'));
|
||||||
|
}
|
||||||
}, 2000);
|
}, 2000);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -81,6 +81,33 @@ export const imageFields = [
|
||||||
default: '',
|
default: '',
|
||||||
description: 'Metadata that you need to store e.g. ID of a record in your DB',
|
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.<br />
|
||||||
|
If after three tries the images is not ready, an error will be thrown.<br />
|
||||||
|
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',
|
displayName: 'Webhook URL',
|
||||||
name: 'webhookUrl',
|
name: 'webhookUrl',
|
||||||
|
@ -88,14 +115,6 @@ export const imageFields = [
|
||||||
default: '',
|
default: '',
|
||||||
description: 'A url to POST the Image object to upon rendering completed',
|
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.</br>
|
|
||||||
If after two tries the images is not ready an error will be thrown`,
|
|
||||||
},
|
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue