n8n-nodes-mallabe-websites
Version:
n8n community node that allows the to get website status, thumbnail and icon using Mallabe Websites
153 lines • 6.83 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MallabeWebsites = void 0;
const GenericFunctions_1 = require("./GenericFunctions");
const CheckWebsiteStatusOperation_1 = require("./CheckWebsiteStatusOperation");
const GetWebsiteIconOperation_1 = require("./GetWebsiteIconOperation");
const GetWebsiteThumbnailOperation_1 = require("./GetWebsiteThumbnailOperation");
class MallabeWebsites {
constructor() {
this.description = {
displayName: 'Mallabe Websites',
name: 'mallabeWebsites',
icon: 'file:mallabe.svg',
group: ['transform'],
version: 1,
subtitle: '={{ $parameter["operation"] + ": " + $parameter["resource"] }}',
description: 'Mallabe Websites is a utility tool that allows the to get a website status & icon, and generate thumbnail.',
defaults: {
name: 'Mallabe Websites',
},
inputs: ['main'],
outputs: ['main'],
credentials: [
{
name: 'mallabeWebsitesApi',
required: true,
},
],
properties: [
{
displayName: 'Resource',
name: 'resource',
type: 'options',
noDataExpression: true,
options: [
{
name: 'Website',
value: 'website',
},
],
default: 'website',
required: true,
},
{
displayName: 'Operation',
name: 'operation',
type: 'options',
noDataExpression: true,
displayOptions: {
show: {
resource: ['website'],
},
},
options: [
{
name: 'Check Website Status',
value: 'checkWebsiteStatus',
description: 'Check if a website is alive and the time it took to respond',
action: 'Check website status',
},
{
name: 'Get Website Icon',
value: 'getWebsiteIcon',
description: 'Retrieve the favicon or icon of a website',
action: 'Get website icon',
},
{
name: 'Get Website Thumbnail',
value: 'getWebsiteThumbnail',
description: 'Generate a thumbnail image of a website',
action: 'Get website thumbnail',
},
],
default: 'checkWebsiteStatus',
},
...CheckWebsiteStatusOperation_1.checkWebsiteStatusFields,
...GetWebsiteIconOperation_1.getWebsiteIconFields,
...GetWebsiteThumbnailOperation_1.getWebsiteThumbnailFields,
],
};
}
async execute() {
const items = this.getInputData();
const returnData = [];
const length = items.length;
const qs = {};
let response;
let responseData;
let download;
for (let i = 0; i < length; i++) {
try {
const resource = this.getNodeParameter('resource', 0);
const operation = this.getNodeParameter('operation', 0);
if (resource === 'website') {
if (operation === 'checkWebsiteStatus') {
const website = this.getNodeParameter('website', i);
const method = this.getNodeParameter('method', i);
const timeout = this.getNodeParameter('timeout', i);
const webhookUrl = this.getNodeParameter('webhookUrl', i);
const body = { website, method, timeout, webhookUrl };
response = await GenericFunctions_1.mallabeWebsitesRequest.call(this, 'POST', '/v1/websites/status', body, qs);
}
else if (operation === 'getWebsiteThumbnail') {
const website = this.getNodeParameter('website', i);
const webhookUrl = this.getNodeParameter('webhookUrl', i);
download = this.getNodeParameter('download', i);
const body = { website, webhookUrl };
response = await GenericFunctions_1.mallabeWebsitesRequest.call(this, 'POST', '/v1/websites/thumbnail', body, qs);
}
else if (operation === 'getWebsiteIcon') {
const website = this.getNodeParameter('website', i);
const webhookUrl = this.getNodeParameter('webhookUrl', i);
download = this.getNodeParameter('download', i);
const body = { website, webhookUrl };
response = await GenericFunctions_1.mallabeWebsitesRequest.call(this, 'POST', '/v1/websites/icon', body, qs);
}
if (download) {
const output = this.getNodeParameter('output', i);
const buffer = (await GenericFunctions_1.mallabeWebsitesCdnRequest.call(this, response.data.url));
responseData = {
json: response,
binary: {
[output]: await this.helpers.prepareBinaryData(buffer),
},
};
}
else {
responseData = response;
}
}
if (Array.isArray(responseData)) {
returnData.push.apply(returnData, responseData);
}
else {
returnData.push(responseData);
}
}
catch (error) {
if (this.continueOnFail()) {
returnData.push({ error: error.message });
continue;
}
throw error;
}
}
if (download) {
return [returnData];
}
return [this.helpers.returnJsonArray(returnData)];
}
}
exports.MallabeWebsites = MallabeWebsites;
//# sourceMappingURL=MallabeWebsites.node.js.map