Files
openclaw/extensions/voice-call/src/proxy-ip.ts
2026-07-05 06:10:36 -07:00

19 lines
644 B
TypeScript

// Voice Call plugin module normalizes proxy IP representations.
export function normalizeProxyIp(value: string | undefined): string | undefined {
const trimmed = value?.trim();
if (!trimmed) {
return undefined;
}
const unwrapped =
trimmed.startsWith("[") && trimmed.endsWith("]") ? trimmed.slice(1, -1) : trimmed;
const normalized = unwrapped.toLowerCase();
const mappedIpv4Prefix = "::ffff:";
if (normalized.startsWith(mappedIpv4Prefix)) {
const mappedIpv4 = normalized.slice(mappedIpv4Prefix.length);
if (/^\d{1,3}(?:\.\d{1,3}){3}$/.test(mappedIpv4)) {
return mappedIpv4;
}
}
return normalized;
}