mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-27 21:07:01 -06:00
f535b2a3ec
Co-authored-by: Rohit <rohitjavvadi2@gmail.com>
19 lines
644 B
TypeScript
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;
|
|
}
|