fix(bikegear): support sticky Webshare residential sessions
This commit is contained in:
parent
aef5000539
commit
57b174bb3c
@ -42,7 +42,7 @@ function getProxyUrl() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const protocol = String(process.env.BIKEGEAR_PROXY_PROTOCOL || "http").replace(/:$/, "");
|
const protocol = String(process.env.BIKEGEAR_PROXY_PROTOCOL || "http").replace(/:$/, "");
|
||||||
const username = process.env.BIKEGEAR_PROXY_USERNAME || "";
|
const username = buildWebshareUsername(process.env.BIKEGEAR_PROXY_USERNAME || "");
|
||||||
const password = process.env.BIKEGEAR_PROXY_PASSWORD || "";
|
const password = process.env.BIKEGEAR_PROXY_PASSWORD || "";
|
||||||
const auth = username
|
const auth = username
|
||||||
? `${encodeURIComponent(username)}:${encodeURIComponent(password)}@`
|
? `${encodeURIComponent(username)}:${encodeURIComponent(password)}@`
|
||||||
@ -51,6 +51,24 @@ function getProxyUrl() {
|
|||||||
return `${protocol}://${auth}${host}:${port}`;
|
return `${protocol}://${auth}${host}:${port}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function buildWebshareUsername(baseUsername) {
|
||||||
|
const username = String(baseUsername || "").trim();
|
||||||
|
if (!username) return "";
|
||||||
|
|
||||||
|
const country = String(process.env.BIKEGEAR_PROXY_COUNTRY || "").trim().toLowerCase();
|
||||||
|
const sessionId = String(process.env.BIKEGEAR_PROXY_SESSION_ID || "").trim();
|
||||||
|
if (!country && !sessionId) return username;
|
||||||
|
|
||||||
|
const countryPart = country && !new RegExp(`-${country}(?:-|$)`, "i").test(username)
|
||||||
|
? `-${country}`
|
||||||
|
: "";
|
||||||
|
const sessionPart = sessionId && !new RegExp(`-${sessionId}$`).test(username)
|
||||||
|
? `-${sessionId}`
|
||||||
|
: "";
|
||||||
|
|
||||||
|
return `${username}${countryPart}${sessionPart}`;
|
||||||
|
}
|
||||||
|
|
||||||
function maskProxyUrl(proxyUrl) {
|
function maskProxyUrl(proxyUrl) {
|
||||||
if (!proxyUrl) return "none";
|
if (!proxyUrl) return "none";
|
||||||
try {
|
try {
|
||||||
|
|||||||
@ -13,6 +13,8 @@
|
|||||||
* BIKEGEAR_PROXY_PORT=80
|
* BIKEGEAR_PROXY_PORT=80
|
||||||
* BIKEGEAR_PROXY_USERNAME=...
|
* BIKEGEAR_PROXY_USERNAME=...
|
||||||
* BIKEGEAR_PROXY_PASSWORD=...
|
* BIKEGEAR_PROXY_PASSWORD=...
|
||||||
|
* BIKEGEAR_PROXY_COUNTRY=gb
|
||||||
|
* BIKEGEAR_PROXY_SESSION_ID=1001
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const axios = require("axios");
|
const axios = require("axios");
|
||||||
@ -49,7 +51,7 @@ function getProxyUrl() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const protocol = String(process.env.BIKEGEAR_PROXY_PROTOCOL || "http").replace(/:$/, "");
|
const protocol = String(process.env.BIKEGEAR_PROXY_PROTOCOL || "http").replace(/:$/, "");
|
||||||
const username = process.env.BIKEGEAR_PROXY_USERNAME || "";
|
const username = buildWebshareUsername(process.env.BIKEGEAR_PROXY_USERNAME || "");
|
||||||
const password = process.env.BIKEGEAR_PROXY_PASSWORD || "";
|
const password = process.env.BIKEGEAR_PROXY_PASSWORD || "";
|
||||||
const auth = username
|
const auth = username
|
||||||
? `${encodeURIComponent(username)}:${encodeURIComponent(password)}@`
|
? `${encodeURIComponent(username)}:${encodeURIComponent(password)}@`
|
||||||
@ -58,6 +60,24 @@ function getProxyUrl() {
|
|||||||
return `${protocol}://${auth}${host}:${port}`;
|
return `${protocol}://${auth}${host}:${port}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function buildWebshareUsername(baseUsername) {
|
||||||
|
const username = String(baseUsername || "").trim();
|
||||||
|
if (!username) return "";
|
||||||
|
|
||||||
|
const country = String(process.env.BIKEGEAR_PROXY_COUNTRY || "").trim().toLowerCase();
|
||||||
|
const sessionId = String(process.env.BIKEGEAR_PROXY_SESSION_ID || "").trim();
|
||||||
|
if (!country && !sessionId) return username;
|
||||||
|
|
||||||
|
const countryPart = country && !new RegExp(`-${country}(?:-|$)`, "i").test(username)
|
||||||
|
? `-${country}`
|
||||||
|
: "";
|
||||||
|
const sessionPart = sessionId && !new RegExp(`-${sessionId}$`).test(username)
|
||||||
|
? `-${sessionId}`
|
||||||
|
: "";
|
||||||
|
|
||||||
|
return `${username}${countryPart}${sessionPart}`;
|
||||||
|
}
|
||||||
|
|
||||||
function maskProxyUrl(proxyUrl) {
|
function maskProxyUrl(proxyUrl) {
|
||||||
try {
|
try {
|
||||||
const u = new URL(proxyUrl);
|
const u = new URL(proxyUrl);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user