recycleactor commited on
Commit
dca8032
·
verified ·
1 Parent(s): 0364164

Upload 2 files

Browse files
Files changed (2) hide show
  1. src/api.rs +9 -3
  2. src/main.rs +6 -3
src/api.rs CHANGED
@@ -1,5 +1,5 @@
1
  use serde::{Serialize, Deserialize, de::DeserializeOwned};
2
- use std::{env, marker::Sized, time::Instant, sync::Arc};
3
  use std::time::{SystemTime, UNIX_EPOCH};
4
  use thiserror::Error;
5
  use serde_json::{json, value::from_value};
@@ -64,7 +64,12 @@ impl APIClient {
64
  match env::var("ARL") {
65
  Ok(arl) if !arl.trim().is_empty() => Self::new_with_arl(arl),
66
  _ => Self {
67
- client: Client::builder().no_proxy().build().unwrap(),
 
 
 
 
 
68
  license_token: String::new(),
69
  check_form: String::new(),
70
  renew_instant: None,
@@ -92,7 +97,8 @@ impl APIClient {
92
  jar.add_cookie_str(comeback, &url);
93
  let builder = builder
94
  .cookie_provider(Arc::new(jar))
95
- .timeout(std::time::Duration::from_secs(30));
 
96
 
97
  let renew_instant = if !license_token.is_empty() && !check_form.is_empty() {
98
  Some(Instant::now())
 
1
  use serde::{Serialize, Deserialize, de::DeserializeOwned};
2
+ use std::{env, marker::Sized, time::{Instant, Duration}, sync::Arc};
3
  use std::time::{SystemTime, UNIX_EPOCH};
4
  use thiserror::Error;
5
  use serde_json::{json, value::from_value};
 
64
  match env::var("ARL") {
65
  Ok(arl) if !arl.trim().is_empty() => Self::new_with_arl(arl),
66
  _ => Self {
67
+ client: Client::builder()
68
+ .no_proxy()
69
+ .connect_timeout(Duration::from_secs(5))
70
+ .timeout(Duration::from_secs(12))
71
+ .build()
72
+ .unwrap(),
73
  license_token: String::new(),
74
  check_form: String::new(),
75
  renew_instant: None,
 
97
  jar.add_cookie_str(comeback, &url);
98
  let builder = builder
99
  .cookie_provider(Arc::new(jar))
100
+ .connect_timeout(Duration::from_secs(5))
101
+ .timeout(Duration::from_secs(12));
102
 
103
  let renew_instant = if !license_token.is_empty() && !check_form.is_empty() {
104
  Some(Instant::now())
src/main.rs CHANGED
@@ -24,6 +24,7 @@ use reqwest::cookie::CookieStore;
24
  use reqwest::header::ACCEPT;
25
  use std::time::{SystemTime, UNIX_EPOCH};
26
  use tokio::sync::{Mutex, RwLock};
 
27
 
28
  type BoxErr = Box<dyn std::error::Error + Send + Sync + 'static>;
29
 
@@ -629,8 +630,7 @@ async fn stream(
629
  return (StatusCode::SERVICE_UNAVAILABLE, "arl required").into_response();
630
  }
631
 
632
- // До 3 попыток
633
- for attempt in 0..3u8 {
634
  if url.is_some() { break; }
635
 
636
  if attempt >= 1 {
@@ -650,7 +650,10 @@ async fn stream(
650
  continue;
651
  }
652
  }
653
- media_url_for_track(&mut c, q.id, &formats).await
 
 
 
654
  };
655
 
656
  match res {
 
24
  use reqwest::header::ACCEPT;
25
  use std::time::{SystemTime, UNIX_EPOCH};
26
  use tokio::sync::{Mutex, RwLock};
27
+ use tokio::time::{timeout, Duration};
28
 
29
  type BoxErr = Box<dyn std::error::Error + Send + Sync + 'static>;
30
 
 
630
  return (StatusCode::SERVICE_UNAVAILABLE, "arl required").into_response();
631
  }
632
 
633
+ for attempt in 0..2u8 {
 
634
  if url.is_some() { break; }
635
 
636
  if attempt >= 1 {
 
650
  continue;
651
  }
652
  }
653
+ match timeout(Duration::from_secs(12), media_url_for_track(&mut c, q.id, &formats)).await {
654
+ Ok(v) => v,
655
+ Err(_) => Err("timeout".to_string()),
656
+ }
657
  };
658
 
659
  match res {