[addon] refreshes and blacklists failed proxies

This commit is contained in:
TheBeastLT
2020-06-06 16:18:41 +02:00
parent 0361dc8096
commit 6496d7785e
3 changed files with 31 additions and 11 deletions

View File

@@ -68,5 +68,9 @@ function cacheUserAgent(id, method) {
return cacheWrap(remoteCache, `${USER_AGENT_KEY_PREFIX}:${id}`, method, { ttl: USER_AGENT_TTL });
}
module.exports = { cacheWrapStream, cacheWrapResolvedUrl, cacheWrapProxy, cacheUserAgent };
function uncacheProxy(id) {
return remoteCache.del(`${PROXY_KEY_PREFIX}:${id}`);
}
module.exports = { cacheWrapStream, cacheWrapResolvedUrl, cacheWrapProxy, cacheUserAgent, uncacheProxy };

View File

@@ -17,4 +17,12 @@ function getRandomProxy() {
return undefined;
}
module.exports = { getRandomUserAgent, getRandomProxy };
function blacklistProxy(proxy) {
const proxyHost = proxy.replace(/.*@/, '');
console.warn(`Blacklisting ${proxyHost}`);
if (PROXY_HOSTS && PROXY_HOSTS.indexOf(proxyHost) > -1) {
PROXY_HOSTS.splice(PROXY_HOSTS.indexOf(proxyHost), 1);
}
}
module.exports = { getRandomUserAgent, getRandomProxy, blacklistProxy };