45 lines
936 B
JavaScript
45 lines
936 B
JavaScript
function proxyHostFromHeader(hostHeader) {
|
|
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,
|
|
}) {
|
|
const host = String(sharedProxyHost || "").trim() || proxyHostFromHeader(hostHeader);
|
|
const port = Number.parseInt(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,
|
|
};
|
|
}
|