Refactor VPN proxy client implementation
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
function proxyHostFromHeader(hostHeader: unknown) {
|
||||
const raw = String(hostHeader || "").trim();
|
||||
if (!raw) return "";
|
||||
if (raw.startsWith("[")) {
|
||||
const end = raw.indexOf("]");
|
||||
return end > 0 ? raw.slice(1, end) : "";
|
||||
}
|
||||
return raw.split(":")[0];
|
||||
}
|
||||
|
||||
export function buildSharedProxyInfo({
|
||||
appMode,
|
||||
proxyPort,
|
||||
running,
|
||||
hostHeader,
|
||||
sharedProxyHost,
|
||||
}: {
|
||||
appMode: unknown;
|
||||
proxyPort: unknown;
|
||||
running: unknown;
|
||||
hostHeader: unknown;
|
||||
sharedProxyHost: unknown;
|
||||
}) {
|
||||
const host = String(sharedProxyHost || "").trim() || proxyHostFromHeader(hostHeader);
|
||||
const port = Number.parseInt(String(proxyPort), 10);
|
||||
const available =
|
||||
appMode === "gateway" &&
|
||||
Boolean(running) &&
|
||||
host &&
|
||||
Number.isInteger(port) &&
|
||||
port > 0 &&
|
||||
port <= 65535;
|
||||
|
||||
const proxy = available
|
||||
? {
|
||||
host,
|
||||
port,
|
||||
protocol: "socks5",
|
||||
httpUrl: `http://${host}:${port}`,
|
||||
socksUrl: `socks5://${host}:${port}`,
|
||||
}
|
||||
: null;
|
||||
|
||||
return {
|
||||
success: true,
|
||||
available,
|
||||
mode: appMode,
|
||||
proxy,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user