forked from torrust/torrust-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroutes.rs
More file actions
34 lines (29 loc) · 1.22 KB
/
routes.rs
File metadata and controls
34 lines (29 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
use std::convert::Infallible;
use std::sync::Arc;
use warp::{Filter, Rejection};
use crate::http::{
handle_announce, handle_scrape, send_error, with_announce_request, with_auth_key, with_scrape_request, with_tracker,
};
use crate::tracker::tracker::TorrentTracker;
/// All routes
pub fn routes(tracker: Arc<TorrentTracker>) -> impl Filter<Extract = impl warp::Reply, Error = Infallible> + Clone {
announce(tracker.clone()).or(scrape(tracker)).recover(send_error)
}
/// GET /announce or /announce/<key>
fn announce(tracker: Arc<TorrentTracker>) -> impl Filter<Extract = impl warp::Reply, Error = Rejection> + Clone {
warp::path::path("announce")
.and(warp::filters::method::get())
.and(with_announce_request(tracker.config.on_reverse_proxy))
.and(with_auth_key())
.and(with_tracker(tracker))
.and_then(handle_announce)
}
/// GET /scrape/<key>
fn scrape(tracker: Arc<TorrentTracker>) -> impl Filter<Extract = impl warp::Reply, Error = Rejection> + Clone {
warp::path::path("scrape")
.and(warp::filters::method::get())
.and(with_scrape_request(tracker.config.on_reverse_proxy))
.and(with_auth_key())
.and(with_tracker(tracker))
.and_then(handle_scrape)
}