DC-004: fix remaining 3 ESLint warnings (require-await, max-depth)

This commit is contained in:
Hermes
2026-06-25 06:22:07 -07:00
parent 92bcafb4f1
commit a37e79a8fc
+35 -20
View File
@@ -30,7 +30,7 @@ const healthChecker = require('../health-checker');
const updateManager = require('../update-manager'); const updateManager = require('../update-manager');
const selfUpdater = require('../self-updater'); const selfUpdater = require('../self-updater');
const configureMiddleware = require('../middleware'); const configureMiddleware = require('../middleware');
const { validateStartupConfig, syncHealthCheckerServices } = require('../startup-validator'); const { syncHealthCheckerServices } = require('../startup-validator');
const { CSRF_HEADER_NAME } = require('../csrf-protection'); const { CSRF_HEADER_NAME } = require('../csrf-protection');
const { resolveServiceUrl } = require('../url-resolver'); const { resolveServiceUrl } = require('../url-resolver');
const metrics = require('../metrics'); const metrics = require('../metrics');
@@ -86,7 +86,7 @@ const { APP } = require('../constants');
/** /**
* Create and configure the Express application * Create and configure the Express application
*/ */
async function createApp() { function createApp() {
const app = express(); const app = express();
// Initialize logging // Initialize logging
@@ -161,7 +161,7 @@ async function createApp() {
return first === 100 && second >= 64 && second <= 127; return first === 100 && second >= 64 && second <= 127;
} }
async function getTailscaleStatus() { function getTailscaleStatus() {
// Stub for now - will be populated by context // Stub for now - will be populated by context
return null; return null;
} }
@@ -211,7 +211,7 @@ async function createApp() {
async function readConfig() { async function readConfig() {
const { readJsonFile } = require('../fs-helpers'); const { readJsonFile } = require('../fs-helpers');
return readJsonFile(config.CONFIG_FILE, {}); return await readJsonFile(config.CONFIG_FILE, {});
} }
async function saveConfig(updates) { async function saveConfig(updates) {
@@ -244,7 +244,9 @@ async function createApp() {
// Stub - will be implemented // Stub - will be implemented
} }
async function resyncHealthChecker() { // Forwards the promise from syncHealthCheckerServices — intentionally not
// `async` since there is no `await` inside. Callers use `.catch()` on it.
function resyncHealthChecker() {
return syncHealthCheckerServices({ return syncHealthCheckerServices({
log, log,
SERVICES_FILE: config.SERVICES_FILE, SERVICES_FILE: config.SERVICES_FILE,
@@ -629,10 +631,33 @@ async function createApp() {
res.status(statusCode).send(); res.status(statusCode).send();
}, 'probe')); }, 'probe'));
// Scan OS network interfaces and classify the first LAN + Tailscale IPv4
// addresses. Extracted to keep the route handler below ESLint's max-depth.
function detectInterfaceIps() {
const os = require('os');
const LAN_RANGE = /^(192\.168\.|10\.|172\.(1[6-9]|2[0-9]|3[0-1])\.)/;
const all = [];
let lan = null;
let tailscale = null;
const interfaces = os.networkInterfaces();
for (const [name, addrs] of Object.entries(interfaces)) {
for (const addr of addrs || []) {
if (addr.internal || addr.family !== 'IPv4') continue;
const { address: ip } = addr;
all.push({ name, ip });
if (!tailscale && ip.startsWith('100.')) {
tailscale = ip;
} else if (!lan && LAN_RANGE.test(ip)) {
lan = ip;
}
}
}
return { lan, tailscale, all };
}
// Network IPs endpoint // Network IPs endpoint
app.get('/api/v1/network/ips', (req, res) => { app.get('/api/v1/network/ips', (req, res) => {
try { try {
const os = require('os');
const envLan = process.env.HOST_LAN_IP; const envLan = process.env.HOST_LAN_IP;
const envTailscale = process.env.HOST_TAILSCALE_IP; const envTailscale = process.env.HOST_TAILSCALE_IP;
@@ -644,20 +669,10 @@ async function createApp() {
}; };
if (!envLan || !envTailscale) { if (!envLan || !envTailscale) {
const interfaces = os.networkInterfaces(); const detected = detectInterfaceIps();
for (const [name, addrs] of Object.entries(interfaces)) { if (!result.lan) result.lan = detected.lan;
for (const addr of addrs) { if (!result.tailscale) result.tailscale = detected.tailscale;
if (addr.internal || addr.family !== 'IPv4') continue; result.all = detected.all;
const ip = addr.address;
result.all.push({ name, ip });
if (!result.tailscale && ip.startsWith('100.')) {
result.tailscale = ip;
} else if (!result.lan && (ip.startsWith('192.168.') || ip.startsWith('10.') || ip.match(/^172\.(1[6-9]|2[0-9]|3[0-1])\./))) {
result.lan = ip;
}
}
}
} }
res.json(result); res.json(result);