mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-14 00:24:07 -08:00
🔀 Merge branch 'RicardoE105-feature/bannerbear-extended'
This commit is contained in:
commit
602998e40f
|
@ -76,7 +76,7 @@ export class Bannerbear implements INodeType {
|
||||||
|
|
||||||
methods = {
|
methods = {
|
||||||
loadOptions: {
|
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
|
// select them easily
|
||||||
async getTemplates(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
async getTemplates(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||||
const returnData: INodePropertyOptions[] = [];
|
const returnData: INodePropertyOptions[] = [];
|
||||||
|
@ -91,6 +91,23 @@ export class Bannerbear implements INodeType {
|
||||||
}
|
}
|
||||||
return returnData;
|
return returnData;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// Get all the available modifications to display them to user so that he can
|
||||||
|
// select them easily
|
||||||
|
async getModificationNames(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||||
|
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,29 @@ 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') {
|
||||||
|
let maxTries = (additionalFields.waitForImageMaxTries as number) || 3;
|
||||||
|
|
||||||
|
const promise = (uid: string) => {
|
||||||
|
let data: IDataObject = {};
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const timeout = setInterval(async () => {
|
||||||
|
data = await bannerbearApiRequest.call(this, 'GET', `/images/${uid}`);
|
||||||
|
|
||||||
|
if (data.status === 'completed') {
|
||||||
|
clearInterval(timeout);
|
||||||
|
resolve(data);
|
||||||
|
}
|
||||||
|
if (--maxTries === 0) {
|
||||||
|
clearInterval(timeout);
|
||||||
|
reject(new Error('Image did not finish processing after multiple tries.'));
|
||||||
|
}
|
||||||
|
}, 2000);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
responseData = await promise(responseData.uid);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//https://developers.bannerbear.com/#get-a-specific-image
|
//https://developers.bannerbear.com/#get-a-specific-image
|
||||||
if (operation === 'get') {
|
if (operation === 'get') {
|
||||||
|
|
|
@ -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',
|
||||||
|
@ -117,7 +144,13 @@ export const imageFields = [
|
||||||
{
|
{
|
||||||
displayName: 'Name',
|
displayName: 'Name',
|
||||||
name: 'name',
|
name: 'name',
|
||||||
type: 'string',
|
type: 'options',
|
||||||
|
typeOptions: {
|
||||||
|
loadOptionsMethod: 'getModificationNames',
|
||||||
|
loadOptionsDependsOn: [
|
||||||
|
'templateId',
|
||||||
|
],
|
||||||
|
},
|
||||||
default: '',
|
default: '',
|
||||||
description: 'The name of the item you want to change',
|
description: 'The name of the item you want to change',
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue