Merge remote-tracking branch 'origin/1.19.X'

# Conflicts:
#	package-lock.json
#	package.json
#	src/util-frontend.js
This commit is contained in:
Louis Lam 2023-01-17 21:17:04 +08:00
commit c47b6c5995
45 changed files with 624 additions and 2624 deletions

View file

@ -105,7 +105,7 @@ exports.pingAsync = function (hostname, ipv6 = false) {
ping.promise.probe(hostname, {
v6: ipv6,
min_reply: 1,
timeout: 10,
deadline: 10,
}).then((res) => {
// If ping failed, it will set field to unknown
if (res.alive) {
@ -137,7 +137,7 @@ exports.mqttAsync = function (hostname, topic, okMessage, options = {}) {
const { port, username, password, interval = 20 } = options;
// Adds MQTT protocol to the hostname if not already present
if (!/^(?:http|mqtt)s?:\/\//.test(hostname)) {
if (!/^(?:http|mqtt|ws)s?:\/\//.test(hostname)) {
hostname = "mqtt://" + hostname;
}
@ -147,10 +147,11 @@ exports.mqttAsync = function (hostname, topic, okMessage, options = {}) {
reject(new Error("Timeout"));
}, interval * 1000 * 0.8);
log.debug("mqtt", "MQTT connecting");
const mqttUrl = `${hostname}:${port}`;
let client = mqtt.connect(hostname, {
port,
log.debug("mqtt", `MQTT connecting to ${mqttUrl}`);
let client = mqtt.connect(mqttUrl, {
username,
password
});
@ -282,18 +283,23 @@ exports.postgresQuery = function (connectionString, query) {
const client = new Client({ connectionString });
client.connect();
return client.query(query)
.then(res => {
resolve(res);
})
.catch(err => {
client.connect((err) => {
if (err) {
reject(err);
})
.finally(() => {
client.end();
});
} else {
// Connected here
client.query(query, (err, res) => {
if (err) {
reject(err);
} else {
resolve(res);
}
client.end();
});
}
});
});
};