diff --git a/src/main.rs b/src/main.rs index 6ab77aca..3577d9fc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -34,7 +34,7 @@ async fn hello() -> impl Responder { async fn web_default(req: HttpRequest) -> impl Responder { let path = format!("{}",req.path()); if path.len() >= 7 && &path[..7] == "/donate" { - //println!("{}",&path[7..]); + println!("{}",&path[7..]); HttpResponse::Found() .insert_header(("Location", format!("https://{}{}?{}",req.headers().get("Host").unwrap().to_str().unwrap(),&path[7..],req.query_string()))) .body("") @@ -141,7 +141,7 @@ async fn main() -> std::io::Result<()> { let woker_num = config.woker_num; let port = config.port.clone(); - let (s, r): (Sender, Receiver) = async_channel::unbounded(); + let (s, r): (Sender, Receiver) = async_channel::bounded(30); let bilisender = Arc::new(s); let anti_speedtest_redis_cfg = Config::from_url(&config.redis); let handle = Handle::current(); diff --git a/src/mods/get_bili_res.rs b/src/mods/get_bili_res.rs index 6b05dba5..8d35c63f 100644 --- a/src/mods/get_bili_res.rs +++ b/src/mods/get_bili_res.rs @@ -7,13 +7,13 @@ use async_channel::Sender; use chrono::prelude::*; use curl::easy::{Easy, List}; use deadpool_redis::Pool; -use futures::executor::block_on; use md5; use qstring::QString; use serde_json::{self, json}; use std::io::Read; use std::sync::Arc; use std::thread::spawn; +use async_channel::TrySendError; pub async fn get_playurl(req: &HttpRequest, is_app: bool, is_th: bool) -> impl Responder{ let (pool, config,bilisender) = req.app_data::<(Pool, BiliConfig,Arc>)>().unwrap(); @@ -375,7 +375,15 @@ pub async fn get_playurl(req: &HttpRequest, is_app: bool, is_th: bool) -> impl R user_agent, }; spawn(move|| { - block_on(bilisender_cl.send(senddata)).unwrap(); + match bilisender_cl.try_send(senddata) { + Ok(_) => (), + Err(TrySendError::Full(_)) => { + println!("[Error] channel is full"); + }, + Err(TrySendError::Closed(_)) => { + println!("[Error] channel is closed"); + }, + }; }); response_body = redis_get_data; }