mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-12 21:53:00 -06:00
refactor(infra): flatten LAN route hint resolution
Amp-Thread-ID: https://ampcode.com/threads/T-019ff438-3b93-77b8-9828-1d3c586cb127
This commit is contained in:
@@ -186,41 +186,30 @@ async function resolveDefaultRouteHints(params: {
|
||||
runCommandWithTimeout: AdvertisedLanHostCommandRunner;
|
||||
timeoutMs: number;
|
||||
}): Promise<AdvertisedLanRouteHint[]> {
|
||||
let argv: string[];
|
||||
let parse: typeof parseWindowsDefaultRouteHints;
|
||||
if (params.platform === "win32") {
|
||||
const stdout = await runRouteHintCommand(
|
||||
params.runCommandWithTimeout,
|
||||
[
|
||||
"powershell.exe",
|
||||
"-NoProfile",
|
||||
"-ExecutionPolicy",
|
||||
"Bypass",
|
||||
"-Command",
|
||||
WINDOWS_DEFAULT_ROUTE_COMMAND,
|
||||
],
|
||||
params.timeoutMs,
|
||||
);
|
||||
return stdout ? parseWindowsDefaultRouteHints(stdout) : [];
|
||||
argv = [
|
||||
"powershell.exe",
|
||||
"-NoProfile",
|
||||
"-ExecutionPolicy",
|
||||
"Bypass",
|
||||
"-Command",
|
||||
WINDOWS_DEFAULT_ROUTE_COMMAND,
|
||||
];
|
||||
parse = parseWindowsDefaultRouteHints;
|
||||
} else if (params.platform === "darwin") {
|
||||
argv = ["route", "-n", "get", "default"];
|
||||
parse = parseMacOsDefaultRouteHints;
|
||||
} else if (params.platform === "linux") {
|
||||
argv = ["ip", "-4", "route", "show", "default"];
|
||||
parse = parseLinuxDefaultRouteHints;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (params.platform === "darwin") {
|
||||
const stdout = await runRouteHintCommand(
|
||||
params.runCommandWithTimeout,
|
||||
["route", "-n", "get", "default"],
|
||||
params.timeoutMs,
|
||||
);
|
||||
return stdout ? parseMacOsDefaultRouteHints(stdout) : [];
|
||||
}
|
||||
|
||||
if (params.platform === "linux") {
|
||||
const stdout = await runRouteHintCommand(
|
||||
params.runCommandWithTimeout,
|
||||
["ip", "-4", "route", "show", "default"],
|
||||
params.timeoutMs,
|
||||
);
|
||||
return stdout ? parseLinuxDefaultRouteHints(stdout) : [];
|
||||
}
|
||||
|
||||
return [];
|
||||
const stdout = await runRouteHintCommand(params.runCommandWithTimeout, argv, params.timeoutMs);
|
||||
return stdout ? parse(stdout) : [];
|
||||
}
|
||||
|
||||
export async function resolveAdvertisedLanHostCore(
|
||||
|
||||
Reference in New Issue
Block a user