Files
OmniRoute/src/mitm/dataDir.ts
diegosouzapw 1f962a2167 fix(mitm): harden packaged runtime and privileged command execution
Compile MITM utilities as NodeNext ESM for prepublish builds, copy the
CommonJS MITM server into standalone artifacts, and resolve MITM data
paths without relying on Next.js aliases at runtime.

Replace shell-interpolated setup and elevated command flows with
argument-based spawn and execFile helpers for database setup, DNS edits,
certificate install flows, and Tailscale sudo execution. Also tighten
the Electron production CSP, update provider icon loading to use direct
@lobehub/icons imports with local fallbacks, and pin dependency
configuration to avoid unused peer installs and known audit findings.
2026-04-25 00:31:43 -03:00

42 lines
1.1 KiB
TypeScript

import os from "os";
import path from "path";
const APP_NAME = "omniroute";
function fallbackHomeDir(): string {
const envHome = process.env.HOME || process.env.USERPROFILE;
return typeof envHome === "string" && envHome.trim() ? path.resolve(envHome) : os.tmpdir();
}
function safeHomeDir(): string {
try {
return os.homedir();
} catch {
return fallbackHomeDir();
}
}
function normalizeConfiguredPath(dir: unknown): string | null {
if (typeof dir !== "string") return null;
const trimmed = dir.trim();
return trimmed ? path.resolve(trimmed) : null;
}
export function resolveMitmDataDir(): string {
const configured = normalizeConfiguredPath(process.env.DATA_DIR);
if (configured) return configured;
const homeDir = safeHomeDir();
if (process.platform === "win32") {
const appData = process.env.APPDATA || path.join(homeDir, "AppData", "Roaming");
return path.join(appData, APP_NAME);
}
const xdgConfigHome = normalizeConfiguredPath(process.env.XDG_CONFIG_HOME);
if (xdgConfigHome) {
return path.join(xdgConfigHome, APP_NAME);
}
return path.join(homeDir, `.${APP_NAME}`);
}