mirror of
https://github.com/knightcrawler-stremio/knightcrawler.git
synced 2024-12-20 03:29:51 +00:00
Fix Trackers TTL
Also introduces the ability to reuse your PAT token. If its set, it'll be used on tracker calls.
This commit is contained in:
@@ -2,5 +2,6 @@ import {BooleanHelpers} from "@helpers/boolean_helpers";
|
|||||||
|
|
||||||
export const trackerConfig = {
|
export const trackerConfig = {
|
||||||
TRACKERS_URL: process.env.TRACKERS_URL || 'https://ngosang.github.io/trackerslist/trackers_all.txt',
|
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)
|
UDP_ENABLED: BooleanHelpers.parseBool(process.env.UDP_TRACKERS_ENABLED, false)
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ export class CacheService implements ICacheService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cacheTrackers(method: CacheMethod): Promise<CacheMethod> {
|
cacheTrackers(method: CacheMethod): Promise<CacheMethod> {
|
||||||
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 =>
|
private initiateMemoryCache = (): MemoryCache =>
|
||||||
@@ -102,10 +102,15 @@ export class CacheService implements ICacheService {
|
|||||||
return method();
|
return method();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const expirationTime = new Date(Date.now() + options.ttl * 1000);
|
||||||
|
|
||||||
this.logger.debug(`Cache type: ${cacheType}`);
|
this.logger.debug(`Cache type: ${cacheType}`);
|
||||||
this.logger.debug(`Cache key: ${key}`);
|
this.logger.debug(`Cache key: ${key}`);
|
||||||
this.logger.debug(`Cache options: ${JSON.stringify(options)}`);
|
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);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,13 @@ export class TrackerService implements ITrackerService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private downloadTrackers = async (): Promise<string[]> => {
|
private downloadTrackers = async (): Promise<string[]> => {
|
||||||
const response: AxiosResponse<string> = await axios.get(configurationService.trackerConfig.TRACKERS_URL);
|
const headers = {};
|
||||||
|
|
||||||
|
if (configurationService.trackerConfig.GITHUB_PAT) {
|
||||||
|
headers['Authorization'] = `Basic ${configurationService.trackerConfig.GITHUB_PAT}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
const response: AxiosResponse<string> = await axios.get(configurationService.trackerConfig.TRACKERS_URL, { headers });
|
||||||
const trackersListText: string = response.data;
|
const trackersListText: string = response.data;
|
||||||
// Trackers are separated by a newline character
|
// Trackers are separated by a newline character
|
||||||
let urlTrackers = trackersListText.split("\n");
|
let urlTrackers = trackersListText.split("\n");
|
||||||
|
|||||||
Reference in New Issue
Block a user