mirror of
https://github.com/knightcrawler-stremio/knightcrawler.git
synced 2024-12-20 03:29:51 +00:00
[addon] updates to use https proxy agent
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
const UserAgent = require('user-agents');
|
||||
const HttpsProxyAgent = require('https-proxy-agent');
|
||||
|
||||
const PROXY_HOSTS = process.env.PROXY_HOSTS && process.env.PROXY_HOSTS.split(',');
|
||||
const PROXY_PORT = 89;
|
||||
const PROXY_USERNAME = process.env.PROXY_USERNAME;
|
||||
const PROXY_PASSWORD = process.env.PROXY_PASSWORD;
|
||||
const userAgent = new UserAgent();
|
||||
@@ -13,12 +15,16 @@ function getRandomProxy() {
|
||||
if (PROXY_HOSTS && PROXY_HOSTS.length && PROXY_USERNAME && PROXY_PASSWORD) {
|
||||
const proxyHost = PROXY_HOSTS[Math.floor(Math.random() * PROXY_HOSTS.length)];
|
||||
console.log(`Using ${proxyHost} proxy`);
|
||||
return `http://${PROXY_USERNAME}:${PROXY_PASSWORD}@${proxyHost}`;
|
||||
return `https://${PROXY_USERNAME}:${PROXY_PASSWORD}@${proxyHost}:${PROXY_PORT}`;
|
||||
}
|
||||
console.warn('No proxy configured!');
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function getProxyAgent(proxy) {
|
||||
return new HttpsProxyAgent(proxy);
|
||||
}
|
||||
|
||||
function blacklistProxy(proxy) {
|
||||
const proxyHost = proxy.replace(/.*@/, '');
|
||||
console.warn(`Blacklisting ${proxyHost}`);
|
||||
@@ -27,4 +33,4 @@ function blacklistProxy(proxy) {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { getRandomUserAgent, getRandomProxy, blacklistProxy };
|
||||
module.exports = { getRandomUserAgent, getRandomProxy, getProxyAgent, blacklistProxy };
|
||||
Reference in New Issue
Block a user