[scraper] renames cache method

This commit is contained in:
TheBeastLT
2020-04-03 13:59:15 +02:00
parent 5b07692e57
commit 95505885f6
2 changed files with 6 additions and 5 deletions

View File

@@ -92,7 +92,7 @@ function cacheWrapResolvedUrl(id, method) {
return cacheWrap(memoryCache, `${RESOLVED_URL_KEY_PREFIX}:${id}`, method, { ttl: { RESOLVED_URL_TTL } }); return cacheWrap(memoryCache, `${RESOLVED_URL_KEY_PREFIX}:${id}`, method, { ttl: { RESOLVED_URL_TTL } });
} }
function cacheWrapProxy(id, method) { function cacheWrapOptions(id, method) {
return cacheWrap(memoryCache, `${PROXY_KEY_PREFIX}:${id}`, method, { ttl: { PROXY_TTL } }); return cacheWrap(memoryCache, `${PROXY_KEY_PREFIX}:${id}`, method, { ttl: { PROXY_TTL } });
} }
@@ -102,6 +102,6 @@ module.exports = {
cacheWrapMetadata, cacheWrapMetadata,
retrieveTorrentFiles, retrieveTorrentFiles,
cacheWrapResolvedUrl, cacheWrapResolvedUrl,
cacheWrapProxy cacheWrapOptions
}; };

View File

@@ -1,7 +1,7 @@
const { encode } = require('magnet-uri'); const { encode } = require('magnet-uri');
const RealDebridClient = require('real-debrid-api'); const RealDebridClient = require('real-debrid-api');
const namedQueue = require('named-queue'); const namedQueue = require('named-queue');
const { cacheWrapResolvedUrl, cacheWrapProxy } = require('../lib/cache'); const { cacheWrapResolvedUrl, cacheWrapOptions } = require('../lib/cache');
const { getRandomProxy, getRandomUserAgent } = require('../lib/request_helper'); const { getRandomProxy, getRandomUserAgent } = require('../lib/request_helper');
const unrestrictQueue = new namedQueue((task, callback) => task.method() const unrestrictQueue = new namedQueue((task, callback) => task.method()
@@ -22,7 +22,8 @@ async function resolve(ip, apiKey, infoHash, cachedFileIds, fileIndex) {
async function _unrestrict(ip, apiKey, infoHash, cachedFileIds, fileIndex) { async function _unrestrict(ip, apiKey, infoHash, cachedFileIds, fileIndex) {
console.log(`Unrestricting ${infoHash} [${fileIndex}]`); console.log(`Unrestricting ${infoHash} [${fileIndex}]`);
const RD = await getDefaultOptions(ip).then(options => new RealDebridClient(apiKey, options)); const options = await getDefaultOptions(ip);
const RD = new RealDebridClient(apiKey, options);
const torrentId = await _createOrFindTorrentId(RD, infoHash, cachedFileIds); const torrentId = await _createOrFindTorrentId(RD, infoHash, cachedFileIds);
if (torrentId) { if (torrentId) {
const info = await RD.torrents.info(torrentId); const info = await RD.torrents.info(torrentId);
@@ -74,7 +75,7 @@ function getDefaultOptions(ip) {
'User-Agent': getRandomUserAgent() 'User-Agent': getRandomUserAgent()
} }
}); });
return cacheWrapProxy(ip, generateOptions).catch(() => generateOptions()); return cacheWrapOptions(ip, generateOptions).catch(() => generateOptions());
} }
module.exports = { resolve }; module.exports = { resolve };