use custom rate limit key generator due to cf changes
This commit is contained in:
@@ -39,12 +39,12 @@ async function _getInstantAvailable(hashes, apiKey, retries = 3, maxChunkSize =
|
|||||||
const RD = new RealDebridClient(apiKey, getDefaultOptions());
|
const RD = new RealDebridClient(apiKey, getDefaultOptions());
|
||||||
const hashBatches = chunkArray(missingHashes, maxChunkSize)
|
const hashBatches = chunkArray(missingHashes, maxChunkSize)
|
||||||
return Promise.all(hashBatches.map(batch => RD.torrents.instantAvailability(batch)
|
return Promise.all(hashBatches.map(batch => RD.torrents.instantAvailability(batch)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if (typeof response !== 'object') {
|
if (typeof response !== 'object') {
|
||||||
return Promise.reject(new Error('RD returned non JSON response: ' + response));
|
return Promise.reject(new Error('RD returned non JSON response: ' + response));
|
||||||
}
|
}
|
||||||
return processAvailabilityResults(response);
|
return processAvailabilityResults(response);
|
||||||
})))
|
})))
|
||||||
.then(results => results.reduce((all, result) => Object.assign(all, result), {}))
|
.then(results => results.reduce((all, result) => Object.assign(all, result), {}))
|
||||||
.then(results => cacheAvailabilityResults(results))
|
.then(results => cacheAvailabilityResults(results))
|
||||||
.then(results => Object.assign(cachedResults, results))
|
.then(results => Object.assign(cachedResults, results))
|
||||||
@@ -53,7 +53,7 @@ async function _getInstantAvailable(hashes, apiKey, retries = 3, maxChunkSize =
|
|||||||
return Promise.reject(BadTokenError);
|
return Promise.reject(BadTokenError);
|
||||||
}
|
}
|
||||||
if (!error && maxChunkSize !== 1) {
|
if (!error && maxChunkSize !== 1) {
|
||||||
// sometimes RD dues to large response size respond with empty body. Reduce chunk size to reduce body
|
// sometimes due to large response size RD responds with an empty body. Reduce chunk size to reduce body
|
||||||
console.log(`Reducing chunk size for availability request: ${hashes[0]}`);
|
console.log(`Reducing chunk size for availability request: ${hashes[0]}`);
|
||||||
return _getInstantAvailable(hashes, apiKey, retries - 1, Math.ceil(maxChunkSize / 10));
|
return _getInstantAvailable(hashes, apiKey, retries - 1, Math.ceil(maxChunkSize / 10));
|
||||||
}
|
}
|
||||||
|
|||||||
816
addon/package-lock.json
generated
816
addon/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -15,7 +15,7 @@
|
|||||||
"cache-manager": "^3.4.4",
|
"cache-manager": "^3.4.4",
|
||||||
"cache-manager-mongodb": "^0.3.0",
|
"cache-manager-mongodb": "^0.3.0",
|
||||||
"debrid-link-api": "^1.0.0",
|
"debrid-link-api": "^1.0.0",
|
||||||
"express-rate-limit": "^5.1.1",
|
"express-rate-limit": "^5.5.1",
|
||||||
"https-proxy-agent": "^5.0.0",
|
"https-proxy-agent": "^5.0.0",
|
||||||
"magnet-uri": "^6.2.0",
|
"magnet-uri": "^6.2.0",
|
||||||
"named-queue": "^2.2.1",
|
"named-queue": "^2.2.1",
|
||||||
|
|||||||
@@ -12,7 +12,8 @@ const router = getRouter({ ...addonInterface, manifest: manifest() });
|
|||||||
const limiter = rateLimit({
|
const limiter = rateLimit({
|
||||||
windowMs: 60 * 60 * 1000, // 1 hours
|
windowMs: 60 * 60 * 1000, // 1 hours
|
||||||
max: 300, // limit each IP to 300 requests per windowMs
|
max: 300, // limit each IP to 300 requests per windowMs
|
||||||
headers: false
|
headers: false,
|
||||||
|
keyGenerator: (req) => requestIp.getClientIp(req)
|
||||||
});
|
});
|
||||||
|
|
||||||
router.use(limiter);
|
router.use(limiter);
|
||||||
|
|||||||
Reference in New Issue
Block a user