diff --git a/src/node/consumer/src/lib/models/configuration/tracker_config.ts b/src/node/consumer/src/lib/models/configuration/tracker_config.ts index 91ef3f1..79daa33 100644 --- a/src/node/consumer/src/lib/models/configuration/tracker_config.ts +++ b/src/node/consumer/src/lib/models/configuration/tracker_config.ts @@ -2,5 +2,6 @@ import {BooleanHelpers} from "@helpers/boolean_helpers"; export const trackerConfig = { TRACKERS_URL: process.env.TRACKERS_URL || 'https://ngosang.github.io/trackerslist/trackers_all.txt', + GITHUB_PAT: process.env.GITHUB_PAT, UDP_ENABLED: BooleanHelpers.parseBool(process.env.UDP_TRACKERS_ENABLED, false) }; diff --git a/src/node/consumer/src/lib/services/cache_service.ts b/src/node/consumer/src/lib/services/cache_service.ts index 0c1bbfc..17f7a78 100644 --- a/src/node/consumer/src/lib/services/cache_service.ts +++ b/src/node/consumer/src/lib/services/cache_service.ts @@ -51,7 +51,7 @@ export class CacheService implements ICacheService { } cacheTrackers(method: CacheMethod): Promise { - return this.cacheWrap(CacheType.Memory, `${TRACKERS_KEY_PREFIX}`, method, {ttl: TRACKERS_TTL}); + return this.cacheWrap(CacheType.MongoDb, `${TRACKERS_KEY_PREFIX}`, method, {ttl: TRACKERS_TTL}); } private initiateMemoryCache = (): MemoryCache => @@ -102,10 +102,15 @@ export class CacheService implements ICacheService { return method(); } + const expirationTime = new Date(Date.now() + options.ttl * 1000); + this.logger.debug(`Cache type: ${cacheType}`); this.logger.debug(`Cache key: ${key}`); this.logger.debug(`Cache options: ${JSON.stringify(options)}`); + this.logger.debug(`Cache item will expire at: ${expirationTime.toISOString()}`); - return cache.wrap(key, method, options.ttl); + // Memory Cache is Milliseconds, Mongo Cache converts to Seconds internally. + const ttl : number = cacheType === CacheType.Memory ? options.ttl * 1000 : options.ttl; + return cache.wrap(key, method, ttl); }; } diff --git a/src/node/consumer/src/lib/services/tracker_service.ts b/src/node/consumer/src/lib/services/tracker_service.ts index 26f57f9..8d20d8f 100644 --- a/src/node/consumer/src/lib/services/tracker_service.ts +++ b/src/node/consumer/src/lib/services/tracker_service.ts @@ -16,7 +16,13 @@ export class TrackerService implements ITrackerService { } private downloadTrackers = async (): Promise => { - const response: AxiosResponse = await axios.get(configurationService.trackerConfig.TRACKERS_URL); + const headers = {}; + + if (configurationService.trackerConfig.GITHUB_PAT) { + headers['Authorization'] = `Basic ${configurationService.trackerConfig.GITHUB_PAT}`; + } + + const response: AxiosResponse = await axios.get(configurationService.trackerConfig.TRACKERS_URL, { headers }); const trackersListText: string = response.data; // Trackers are separated by a newline character let urlTrackers = trackersListText.split("\n");