tracker service ts
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import { listenToQueue } from './jobs/processTorrents';
|
import { listenToQueue } from './jobs/processTorrents';
|
||||||
import { repository } from "./repository/database_repository";
|
import { repository } from "./repository/database_repository";
|
||||||
import { getTrackers } from "./lib/trackerService.js";
|
import { getTrackers } from "./lib/trackerService";
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
await getTrackers();
|
await getTrackers();
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import {TorrentInfo} from "./interfaces/torrent_info";
|
|||||||
import {TorrentType} from "./enums/torrent_types";
|
import {TorrentType} from "./enums/torrent_types";
|
||||||
import {logger} from "./logger";
|
import {logger} from "./logger";
|
||||||
import {checkAndUpdateTorrent, createTorrentEntry} from "./torrentEntries.js";
|
import {checkAndUpdateTorrent, createTorrentEntry} from "./torrentEntries.js";
|
||||||
import {getTrackers} from "./trackerService.js";
|
import {getTrackers} from "./trackerService";
|
||||||
import {IngestedTorrentAttributes} from "../repository/interfaces/ingested_torrent_attributes";
|
import {IngestedTorrentAttributes} from "../repository/interfaces/ingested_torrent_attributes";
|
||||||
|
|
||||||
export async function processTorrentRecord(torrent: IngestedTorrentAttributes): Promise<void> {
|
export async function processTorrentRecord(torrent: IngestedTorrentAttributes): Promise<void> {
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
import axios from 'axios';
|
import axios, { AxiosResponse } from 'axios';
|
||||||
import {cacheTrackers} from "./cache.js";
|
import { cacheTrackers } from "./cache.js";
|
||||||
import { trackerConfig } from './config.js';
|
import { trackerConfig } from './config.js';
|
||||||
import {logger} from "./logger";
|
import { logger } from "./logger";
|
||||||
|
|
||||||
const downloadTrackers = async () => {
|
const downloadTrackers = async (): Promise<string[]> => {
|
||||||
const response = await axios.get(trackerConfig.TRACKERS_URL);
|
const response: AxiosResponse<string> = await axios.get(trackerConfig.TRACKERS_URL);
|
||||||
const trackersListText = 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");
|
||||||
// remove blank lines
|
// remove blank lines
|
||||||
@@ -14,6 +14,7 @@ const downloadTrackers = async () => {
|
|||||||
if (!trackerConfig.UDP_ENABLED) {
|
if (!trackerConfig.UDP_ENABLED) {
|
||||||
// remove any udp trackers
|
// 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`);
|
logger.info(`Trackers updated at ${Date.now()}: ${urlTrackers.length} trackers`);
|
||||||
@@ -21,6 +22,6 @@ const downloadTrackers = async () => {
|
|||||||
return urlTrackers;
|
return urlTrackers;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getTrackers = async () => {
|
export const getTrackers = async (): Promise<string[]> => {
|
||||||
return cacheTrackers(downloadTrackers);
|
return cacheTrackers(downloadTrackers);
|
||||||
};
|
};
|
||||||
Reference in New Issue
Block a user