tracker service ts

This commit is contained in:
iPromKnight
2024-02-05 05:06:46 +00:00
committed by iPromKnight
parent 9e9e928c80
commit 9d918abef3
3 changed files with 12 additions and 11 deletions

View File

@@ -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();

View File

@@ -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> {

View File

@@ -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);
};