@@ -7,16 +7,13 @@ import cors from 'cors'
77import mongoose from 'mongoose'
88import nodemailer from 'nodemailer'
99import ratelimit from 'express-rate-limit'
10+ import Tracker from 'bittorrent-tracker'
1011import * as Sentry from '@sentry/node'
1112import * as Tracing from '@sentry/tracing'
1213import config from '../../config'
1314import validateConfig from './utils/validateConfig'
14- import handleAnnounce from './middleware/announce '
15+ import createTrackerRoute from './tracker/routes '
1516import auth from './middleware/auth'
16- import {
17- createUserTrackerRoutes ,
18- createOtherTrackerRoutes ,
19- } from './routes/tracker'
2017import {
2118 register ,
2219 login ,
@@ -173,15 +170,15 @@ validateConfig(config).then(() => {
173170 } )
174171 app . use ( limiter )
175172
176- // custom logic implementing user tracking, ratio control etc
177- app . use ( '/sq/*/announce' , handleAnnounce )
178-
179- // proxy and manipulate tracker routes
180- const userTrackerRoutes = createUserTrackerRoutes ( )
181- const otherTrackerRoutes = createOtherTrackerRoutes ( )
182- app . use ( '/sq/*/announce' , userTrackerRoutes )
183- app . use ( '/sq/*/scrape ' , userTrackerRoutes )
184- app . use ( '/stats ' , otherTrackerRoutes )
173+ const tracker = new Tracker . Server ( {
174+ http : false ,
175+ udp : false ,
176+ ws : false ,
177+ trustProxy : true ,
178+ } )
179+ const onTrackerRequest = tracker . _onRequest . bind ( tracker )
180+ app . get ( '/sq/*/announce ' , createTrackerRoute ( 'announce' , onTrackerRequest ) )
181+ app . get ( '/sq/*/scrape ' , createTrackerRoute ( 'scrape' , onTrackerRequest ) )
185182
186183 app . use ( bodyParser . json ( { limit : '5mb' } ) )
187184 app . use ( cookieParser ( ) )
@@ -200,7 +197,7 @@ validateConfig(config).then(() => {
200197 app . post ( '/verify-email' , verifyUserEmail )
201198
202199 // rss feed (auth handled in cookies)
203- app . get ( '/rss' , rssFeed )
200+ app . get ( '/rss' , rssFeed ( tracker ) )
204201
205202 // torrent file download (can download without auth, will not be able to announce)
206203 app . get ( '/torrent/download/:infoHash/:userId' , downloadTorrent )
@@ -216,7 +213,7 @@ validateConfig(config).then(() => {
216213 app . get ( '/account/get-role' , getUserRole )
217214 app . get ( '/account/get-verified' , getUserVerifiedEmailStatus )
218215 app . post ( '/account/buy' , buyItems )
219- app . get ( '/user/:username' , fetchUser )
216+ app . get ( '/user/:username' , fetchUser ( tracker ) )
220217 app . post ( '/user/ban/:username' , banUser )
221218 app . post ( '/user/unban/:username' , unbanUser )
222219 app . get ( '/account/totp/generate' , generateTotpSecret )
@@ -225,15 +222,15 @@ validateConfig(config).then(() => {
225222
226223 // torrent routes
227224 app . post ( '/torrent/upload' , uploadTorrent )
228- app . get ( '/torrent/info/:infoHash' , fetchTorrent )
225+ app . get ( '/torrent/info/:infoHash' , fetchTorrent ( tracker ) )
229226 app . delete ( '/torrent/delete/:infoHash' , deleteTorrent )
230227 app . post ( '/torrent/comment/:infoHash' , addCommentTorrent )
231228 app . post ( '/torrent/vote/:infoHash/:vote' , addVote )
232229 app . post ( '/torrent/unvote/:infoHash/:vote' , removeVote )
233230 app . post ( '/torrent/report/:infoHash' , createReport )
234231 app . post ( '/torrent/toggle-freeleech/:infoHash' , toggleFreeleech )
235- app . get ( '/torrents/latest' , listLatest )
236- app . get ( '/torrents/search' , searchTorrents )
232+ app . get ( '/torrents/latest' , listLatest ( tracker ) )
233+ app . get ( '/torrents/search' , searchTorrents ( tracker ) )
237234
238235 // announcement routes
239236 app . post ( '/announcements/new' , createAnnouncement )
@@ -249,7 +246,7 @@ validateConfig(config).then(() => {
249246 app . get ( '/reports/page/:page' , getReports )
250247 app . post ( '/reports/resolve/:reportId' , setReportResolved )
251248 app . get ( '/reports/:reportId' , fetchReport )
252- app . get ( '/admin/stats' , getStats )
249+ app . get ( '/admin/stats' , getStats ( tracker ) )
253250
254251 // request routes
255252 app . post ( '/requests/new' , createRequest )
0 commit comments