mirror of
https://github.com/knightcrawler-stremio/knightcrawler.git
synced 2024-12-20 03:29:51 +00:00
tracker service ts
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { listenToQueue } from './jobs/processTorrents';
|
||||
import { repository } from "./repository/database_repository";
|
||||
import { getTrackers } from "./lib/trackerService.js";
|
||||
import { getTrackers } from "./lib/trackerService";
|
||||
|
||||
(async () => {
|
||||
await getTrackers();
|
||||
|
||||
@@ -2,7 +2,7 @@ import {TorrentInfo} from "./interfaces/torrent_info";
|
||||
import {TorrentType} from "./enums/torrent_types";
|
||||
import {logger} from "./logger";
|
||||
import {checkAndUpdateTorrent, createTorrentEntry} from "./torrentEntries.js";
|
||||
import {getTrackers} from "./trackerService.js";
|
||||
import {getTrackers} from "./trackerService";
|
||||
import {IngestedTorrentAttributes} from "../repository/interfaces/ingested_torrent_attributes";
|
||||
|
||||
export async function processTorrentRecord(torrent: IngestedTorrentAttributes): Promise<void> {
|
||||
|
||||
@@ -1,19 +1,20 @@
|
||||
import axios from 'axios';
|
||||
import {cacheTrackers} from "./cache.js";
|
||||
import axios, { AxiosResponse } from 'axios';
|
||||
import { cacheTrackers } from "./cache.js";
|
||||
import { trackerConfig } from './config.js';
|
||||
import {logger} from "./logger";
|
||||
import { logger } from "./logger";
|
||||
|
||||
const downloadTrackers = async () => {
|
||||
const response = await axios.get(trackerConfig.TRACKERS_URL);
|
||||
const trackersListText = response.data;
|
||||
const downloadTrackers = async (): Promise<string[]> => {
|
||||
const response: AxiosResponse<string> = await axios.get(trackerConfig.TRACKERS_URL);
|
||||
const trackersListText: string = response.data;
|
||||
// Trackers are separated by a newline character
|
||||
let urlTrackers = trackersListText.split("\n");
|
||||
// remove blank lines
|
||||
urlTrackers = urlTrackers.filter(line => line.trim() !== '');
|
||||
|
||||
|
||||
if (!trackerConfig.UDP_ENABLED) {
|
||||
// remove any udp trackers
|
||||
urlTrackers = urlTrackers.filter(line => !line.startsWith('udp://'));
|
||||
urlTrackers = urlTrackers.filter(line => !line.startsWith('udp://'));
|
||||
|
||||
}
|
||||
|
||||
logger.info(`Trackers updated at ${Date.now()}: ${urlTrackers.length} trackers`);
|
||||
@@ -21,6 +22,6 @@ const downloadTrackers = async () => {
|
||||
return urlTrackers;
|
||||
};
|
||||
|
||||
export const getTrackers = async () => {
|
||||
export const getTrackers = async (): Promise<string[]> => {
|
||||
return cacheTrackers(downloadTrackers);
|
||||
};
|
||||
Reference in New Issue
Block a user