1- use  reqwest:: StatusCode ; 
21use  serde:: Deserialize ; 
32
4- use  super :: Mirror ; 
3+ use  super :: { Mirror ,   Ratelimiter } ; 
54
65#[ derive( Deserialize ) ]  
76pub  struct  Nerinyan ; 
@@ -16,43 +15,28 @@ impl Mirror for Nerinyan {
1615        "https://api.nerinyan.moe/d" 
1716    } 
1817
19-     async  fn  get_file ( & self ,  id :  i32 )  -> Result < Vec < u8 > ,  String >  { 
18+     async  fn  get_file ( & self ,  id :  i32 ,  rate_limit :  & Ratelimiter )  -> Result < Vec < u8 > ,  String >  { 
19+         rate_limit. wait_if_needed ( ) . await ; 
20+ 
2021        let  client = reqwest:: Client :: new ( ) ; 
2122        let  response = client
2223            . get ( format ! ( "{}/{}" ,  self . get_base_url( ) ,  id) ) 
23-             . header ( "User-Agent" ,  "shockpast/osu-collector-cli : 1.0.0 " ) 
24+             . header ( "User-Agent" ,  "shockpast/ecstasy : 1.1.2 " ) 
2425            . send ( ) 
2526            . await 
2627            . unwrap ( ) ; 
2728
29+         rate_limit. update_rate_limit ( response. headers ( ) ) . await ; 
30+ 
2831        let  content_type = response
2932            . headers ( ) 
3033            . get ( reqwest:: header:: CONTENT_TYPE ) 
3134            . and_then ( |v| v. to_str ( ) . ok ( ) ) 
3235            . map ( |s| s. to_string ( ) ) 
3336            . unwrap_or_default ( ) ; 
34-         let  status_code = response. status ( ) ; 
3537
3638        let  bytes = response. bytes ( ) . await . map_err ( |e| e. to_string ( ) ) ?; 
3739
38-         if  status_code. is_client_error ( )  { 
39-             match  status_code { 
40-                 StatusCode :: FORBIDDEN  => { 
41-                     return  Err ( format ! ( "{} possibly banned us." ,  self . get_name( ) ) ) ; 
42-                 } 
43-                 _ => todo ! ( ) , 
44-             } ; 
45-         } 
46- 
47-         if  status_code. is_server_error ( )  { 
48-             match  status_code { 
49-                 StatusCode :: BAD_GATEWAY  => { 
50-                     panic ! ( "{} is down, consider using other mirror." ,  self . get_name( ) ) ; 
51-                 } 
52-                 _ => todo ! ( ) , 
53-             } ; 
54-         } 
55- 
5640        if  content_type. contains ( "application/json" )  { 
5741            if  let  Ok ( json)  = serde_json:: from_slice :: < serde_json:: Value > ( & bytes)  { 
5842                return  Err ( json. to_string ( ) ) ; 
0 commit comments