Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
pchpub authored Aug 14, 2022
1 parent 8bb8cf4 commit 1c8813f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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("")
Expand Down Expand Up @@ -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<SendData>, Receiver<SendData>) = async_channel::unbounded();
let (s, r): (Sender<SendData>, Receiver<SendData>) = async_channel::bounded(30);
let bilisender = Arc::new(s);
let anti_speedtest_redis_cfg = Config::from_url(&config.redis);
let handle = Handle::current();
Expand Down
12 changes: 10 additions & 2 deletions src/mods/get_bili_res.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Sender<SendData>>)>().unwrap();
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 1c8813f

Please sign in to comment.