mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-08-07 14:41:09 +08:00
add ping and fix uptime
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
const tcpp = require('tcp-ping');
|
||||
const Ping = require("./ping-lite");
|
||||
|
||||
exports.tcping = function (hostname, port) {
|
||||
return new Promise((resolve, reject) => {
|
||||
@@ -20,3 +21,19 @@ exports.tcping = function (hostname, port) {
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
exports.ping = function (hostname) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const ping = new Ping(hostname);
|
||||
|
||||
ping.send(function(err, ms) {
|
||||
if (err) {
|
||||
reject(err)
|
||||
} else if (ms === null) {
|
||||
reject(new Error("timeout"))
|
||||
} else {
|
||||
resolve(Math.round(ms))
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user