mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
n8n-3867-progressively-apply-prettier-to-all (#3873)
* 🔨 formatting nodes with prettier
This commit is contained in:
@@ -1,6 +1,4 @@
|
||||
import {
|
||||
ITriggerFunctions,
|
||||
} from 'n8n-core';
|
||||
import { ITriggerFunctions } from 'n8n-core';
|
||||
|
||||
import {
|
||||
IDataObject,
|
||||
@@ -12,9 +10,7 @@ import {
|
||||
|
||||
import mqtt from 'mqtt';
|
||||
|
||||
import {
|
||||
IClientOptions, ISubscriptionMap,
|
||||
} from 'mqtt';
|
||||
import { IClientOptions, ISubscriptionMap } from 'mqtt';
|
||||
|
||||
export class MqttTrigger implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
@@ -41,7 +37,8 @@ export class MqttTrigger implements INodeType {
|
||||
name: 'topics',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description: 'Topics to subscribe to, multiple can be defined with comma. Wildcard characters are supported (+ - for single level and # - for multi level). By default all subscription used QoS=0. To set a different QoS, write the QoS desired after the topic preceded by a colom. For Example: topicA:1,topicB:2',
|
||||
description:
|
||||
'Topics to subscribe to, multiple can be defined with comma. Wildcard characters are supported (+ - for single level and # - for multi level). By default all subscription used QoS=0. To set a different QoS, write the QoS desired after the topic preceded by a colom. For Example: topicA:1,topicB:2',
|
||||
},
|
||||
{
|
||||
displayName: 'Options',
|
||||
@@ -70,7 +67,6 @@ export class MqttTrigger implements INodeType {
|
||||
};
|
||||
|
||||
async trigger(this: ITriggerFunctions): Promise<ITriggerResponse> {
|
||||
|
||||
const credentials = await this.getCredentials('mqtt');
|
||||
|
||||
const topics = (this.getNodeParameter('topics') as string).split(',');
|
||||
@@ -79,7 +75,7 @@ export class MqttTrigger implements INodeType {
|
||||
|
||||
for (const data of topics) {
|
||||
const [topic, qos] = data.split(':');
|
||||
topicsQoS[topic] = (qos) ? { qos: parseInt(qos, 10) } : { qos: 0 };
|
||||
topicsQoS[topic] = qos ? { qos: parseInt(qos, 10) } : { qos: 0 };
|
||||
}
|
||||
|
||||
const options = this.getNodeParameter('options') as IDataObject;
|
||||
@@ -88,11 +84,12 @@ export class MqttTrigger implements INodeType {
|
||||
throw new NodeOperationError(this.getNode(), 'Topics are mandatory!');
|
||||
}
|
||||
|
||||
const protocol = credentials.protocol as string || 'mqtt';
|
||||
const protocol = (credentials.protocol as string) || 'mqtt';
|
||||
const host = credentials.host as string;
|
||||
const brokerUrl = `${protocol}://${host}`;
|
||||
const port = credentials.port as number || 1883;
|
||||
const clientId = credentials.clientId as string || `mqttjs_${Math.random().toString(16).substr(2, 8)}`;
|
||||
const port = (credentials.port as number) || 1883;
|
||||
const clientId =
|
||||
(credentials.clientId as string) || `mqttjs_${Math.random().toString(16).substr(2, 8)}`;
|
||||
const clean = credentials.clean as boolean;
|
||||
const ssl = credentials.ssl as boolean;
|
||||
const ca = credentials.ca as string;
|
||||
@@ -110,13 +107,12 @@ export class MqttTrigger implements INodeType {
|
||||
};
|
||||
|
||||
if (credentials.username && credentials.password) {
|
||||
clientOptions.username = credentials.username as string;
|
||||
clientOptions.password = credentials.password as string;
|
||||
clientOptions.username = credentials.username as string;
|
||||
clientOptions.password = credentials.password as string;
|
||||
}
|
||||
|
||||
client = mqtt.connect(brokerUrl, clientOptions);
|
||||
}
|
||||
else {
|
||||
client = mqtt.connect(brokerUrl, clientOptions);
|
||||
} else {
|
||||
const clientOptions: IClientOptions = {
|
||||
port,
|
||||
clean,
|
||||
@@ -131,7 +127,7 @@ export class MqttTrigger implements INodeType {
|
||||
clientOptions.password = credentials.password as string;
|
||||
}
|
||||
|
||||
client = mqtt.connect(brokerUrl, clientOptions);
|
||||
client = mqtt.connect(brokerUrl, clientOptions);
|
||||
}
|
||||
|
||||
const self = this;
|
||||
@@ -143,7 +139,8 @@ export class MqttTrigger implements INodeType {
|
||||
if (err) {
|
||||
reject(err);
|
||||
}
|
||||
client.on('message', (topic: string, message: Buffer | string) => { // tslint:disable-line:no-any
|
||||
client.on('message', (topic: string, message: Buffer | string) => {
|
||||
// tslint:disable-line:no-any
|
||||
let result: IDataObject = {};
|
||||
|
||||
message = message.toString() as string;
|
||||
@@ -151,7 +148,7 @@ export class MqttTrigger implements INodeType {
|
||||
if (options.jsonParseBody) {
|
||||
try {
|
||||
message = JSON.parse(message.toString());
|
||||
} catch (err) { }
|
||||
} catch (err) {}
|
||||
}
|
||||
|
||||
result.message = message;
|
||||
|
||||
Reference in New Issue
Block a user