mirror of
https://github.com/n8n-io/n8n.git
synced 2025-02-21 02:56:40 -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);
|
||||
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);
|
||||
});
|
||||
};
|
||||
|
|
|
@ -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.<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',
|
||||
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.</br>
|
||||
If after two tries the images is not ready an error will be thrown`,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue