@@ -8,10 +8,10 @@ use axum::response::{Json, Response};
88use serde:: { de, Deserialize , Deserializer } ;
99
1010use super :: responses:: {
11- response_auth_key , response_failed_to_delete_key , response_failed_to_generate_key , response_failed_to_reload_keys ,
12- response_failed_to_reload_whitelist , response_failed_to_remove_torrent_from_whitelist , response_failed_to_whitelist_torrent ,
13- response_invalid_auth_key_param , response_invalid_info_hash_param , response_ok , response_stats , response_torrent_info ,
14- response_torrent_list , response_torrent_not_known ,
11+ auth_key_response , failed_to_delete_key_response , failed_to_generate_key_response , failed_to_reload_keys_response ,
12+ failed_to_reload_whitelist_response , failed_to_remove_torrent_from_whitelist_response , failed_to_whitelist_torrent_response ,
13+ invalid_auth_key_param_response , invalid_info_hash_param_response , ok_response , stats_response , torrent_info_response ,
14+ torrent_list_response , torrent_not_known_response ,
1515} ;
1616use crate :: apis:: resources:: auth_key:: AuthKey ;
1717use crate :: apis:: resources:: stats:: Stats ;
@@ -23,18 +23,18 @@ use crate::tracker::services::torrent::{get_torrent_info, get_torrents, Paginati
2323use crate :: tracker:: Tracker ;
2424
2525pub async fn get_stats_handler ( State ( tracker) : State < Arc < Tracker > > ) -> Json < Stats > {
26- response_stats ( get_metrics ( tracker. clone ( ) ) . await )
26+ stats_response ( get_metrics ( tracker. clone ( ) ) . await )
2727}
2828
2929#[ derive( Deserialize ) ]
3030pub struct InfoHashParam ( String ) ;
3131
3232pub async fn get_torrent_handler ( State ( tracker) : State < Arc < Tracker > > , Path ( info_hash) : Path < InfoHashParam > ) -> Response {
3333 match InfoHash :: from_str ( & info_hash. 0 ) {
34- Err ( _) => response_invalid_info_hash_param ( & info_hash. 0 ) ,
34+ Err ( _) => invalid_info_hash_param_response ( & info_hash. 0 ) ,
3535 Ok ( info_hash) => match get_torrent_info ( tracker. clone ( ) , & info_hash) . await {
36- Some ( info) => response_torrent_info ( info) ,
37- None => response_torrent_not_known ( ) ,
36+ Some ( info) => torrent_info_response ( info) ,
37+ None => torrent_not_known_response ( ) ,
3838 } ,
3939 }
4040}
@@ -50,7 +50,7 @@ pub async fn get_torrents_handler(
5050 State ( tracker) : State < Arc < Tracker > > ,
5151 pagination : Query < PaginationParams > ,
5252) -> Json < Vec < ListItem > > {
53- response_torrent_list (
53+ torrent_list_response (
5454 & get_torrents (
5555 tracker. clone ( ) ,
5656 & Pagination :: new_with_options ( pagination. 0 . offset , pagination. 0 . limit ) ,
@@ -64,10 +64,10 @@ pub async fn add_torrent_to_whitelist_handler(
6464 Path ( info_hash) : Path < InfoHashParam > ,
6565) -> Response {
6666 match InfoHash :: from_str ( & info_hash. 0 ) {
67- Err ( _) => response_invalid_info_hash_param ( & info_hash. 0 ) ,
67+ Err ( _) => invalid_info_hash_param_response ( & info_hash. 0 ) ,
6868 Ok ( info_hash) => match tracker. add_torrent_to_whitelist ( & info_hash) . await {
69- Ok ( ..) => response_ok ( ) ,
70- Err ( ..) => response_failed_to_whitelist_torrent ( ) ,
69+ Ok ( ..) => ok_response ( ) ,
70+ Err ( ..) => failed_to_whitelist_torrent_response ( ) ,
7171 } ,
7272 }
7373}
@@ -77,26 +77,26 @@ pub async fn remove_torrent_from_whitelist_handler(
7777 Path ( info_hash) : Path < InfoHashParam > ,
7878) -> Response {
7979 match InfoHash :: from_str ( & info_hash. 0 ) {
80- Err ( _) => response_invalid_info_hash_param ( & info_hash. 0 ) ,
80+ Err ( _) => invalid_info_hash_param_response ( & info_hash. 0 ) ,
8181 Ok ( info_hash) => match tracker. remove_torrent_from_whitelist ( & info_hash) . await {
82- Ok ( ..) => response_ok ( ) ,
83- Err ( ..) => response_failed_to_remove_torrent_from_whitelist ( ) ,
82+ Ok ( ..) => ok_response ( ) ,
83+ Err ( ..) => failed_to_remove_torrent_from_whitelist_response ( ) ,
8484 } ,
8585 }
8686}
8787
8888pub async fn reload_whitelist_handler ( State ( tracker) : State < Arc < Tracker > > ) -> Response {
8989 match tracker. load_whitelist ( ) . await {
90- Ok ( ..) => response_ok ( ) ,
91- Err ( ..) => response_failed_to_reload_whitelist ( ) ,
90+ Ok ( ..) => ok_response ( ) ,
91+ Err ( ..) => failed_to_reload_whitelist_response ( ) ,
9292 }
9393}
9494
9595pub async fn generate_auth_key_handler ( State ( tracker) : State < Arc < Tracker > > , Path ( seconds_valid_or_key) : Path < u64 > ) -> Response {
9696 let seconds_valid = seconds_valid_or_key;
9797 match tracker. generate_auth_key ( Duration :: from_secs ( seconds_valid) ) . await {
98- Ok ( auth_key) => response_auth_key ( & AuthKey :: from ( auth_key) ) ,
99- Err ( _) => response_failed_to_generate_key ( ) ,
98+ Ok ( auth_key) => auth_key_response ( & AuthKey :: from ( auth_key) ) ,
99+ Err ( _) => failed_to_generate_key_response ( ) ,
100100 }
101101}
102102
@@ -108,18 +108,18 @@ pub async fn delete_auth_key_handler(
108108 Path ( seconds_valid_or_key) : Path < KeyIdParam > ,
109109) -> Response {
110110 match KeyId :: from_str ( & seconds_valid_or_key. 0 ) {
111- Err ( _) => response_invalid_auth_key_param ( & seconds_valid_or_key. 0 ) ,
111+ Err ( _) => invalid_auth_key_param_response ( & seconds_valid_or_key. 0 ) ,
112112 Ok ( key_id) => match tracker. remove_auth_key ( & key_id. to_string ( ) ) . await {
113- Ok ( _) => response_ok ( ) ,
114- Err ( _) => response_failed_to_delete_key ( ) ,
113+ Ok ( _) => ok_response ( ) ,
114+ Err ( _) => failed_to_delete_key_response ( ) ,
115115 } ,
116116 }
117117}
118118
119119pub async fn reload_keys_handler ( State ( tracker) : State < Arc < Tracker > > ) -> Response {
120120 match tracker. load_keys ( ) . await {
121- Ok ( ..) => response_ok ( ) ,
122- Err ( ..) => response_failed_to_reload_keys ( ) ,
121+ Ok ( ..) => ok_response ( ) ,
122+ Err ( ..) => failed_to_reload_keys_response ( ) ,
123123 }
124124}
125125
0 commit comments