Quality fixes

This commit is contained in:
Sefinek committed 2025-01-18 04:48:11 +01:00
1 parent 590fd37831
commit f6774898b5
1 file changed
+13 -9
+13 -9
View File
@@ -2,12 +2,12 @@ const os = require('node:os');
const axios = require('./axios.js'); const axios = require('./axios.js');
const isLocalIP = require('./isLocalIP.js'); const isLocalIP = require('./isLocalIP.js');
let ipAddressList = []; const ipAddressList = new Set();
const fetchIPv4Address = async () => { const fetchIPv4Address = async () => {
try { try {
const { data } = await axios.get('https://api.sefinek.net/api/v2/ip'); const { data } = await axios.get('https://api.sefinek.net/api/v2/ip');
if (data?.success && data?.message) ipAddressList.push(data.message); if (data?.success && data?.message) ipAddressList.add(data.message);
} catch (err) { } catch (err) {
console.warn('Error fetching IPv4 address:', err.message); console.warn('Error fetching IPv4 address:', err.message);
} }
@@ -16,16 +16,18 @@ const fetchIPv4Address = async () => {
const fetchIPv6Address = () => { const fetchIPv6Address = () => {
const networkInterfaces = os.networkInterfaces(); const networkInterfaces = os.networkInterfaces();
for (const interfaces of Object.values(networkInterfaces)) { Object.values(networkInterfaces).forEach(interfaces => {
for (const details of interfaces) { interfaces.forEach(details => {
const ip = details.address; const ip = details.address;
if (!details.internal && ip && !isLocalIP(ip)) ipAddressList.push(ip); if (!details.internal && ip && !isLocalIP(ip)) {
} ipAddressList.add(ip);
} }
});
});
}; };
const fetchIPAddress = async () => { const fetchIPAddress = async () => {
ipAddressList = []; ipAddressList.clear();
await fetchIPv4Address(); await fetchIPv4Address();
fetchIPv6Address(); fetchIPv6Address();
}; };
@@ -33,6 +35,8 @@ const fetchIPAddress = async () => {
(async () => { (async () => {
await fetchIPAddress(); await fetchIPAddress();
setInterval(fetchIPAddress, 25 * 1000); setInterval(fetchIPAddress, 25 * 1000);
// console.debug(ipAddressList);
})(); })();
module.exports = () => [...ipAddressList]; module.exports = () => Array.from(ipAddressList);