From b0f424502e015c478f7330a6497f8fb9178a2d46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E4=BD=B3=E6=B4=9B?= <73123406+pchpub@users.noreply.github.com> Date: Tue, 4 Oct 2022 17:43:10 +0800 Subject: [PATCH 1/2] change: use tokio::spawn --- src/mods/get_bili_res.rs | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/mods/get_bili_res.rs b/src/mods/get_bili_res.rs index 1c59a893..132ed8ad 100644 --- a/src/mods/get_bili_res.rs +++ b/src/mods/get_bili_res.rs @@ -16,7 +16,6 @@ use pcre2::bytes::Regex; use qstring::QString; use serde_json::{self, json}; use std::sync::Arc; -use std::thread::spawn; pub async fn get_playurl( req: &HttpRequest, @@ -392,7 +391,7 @@ pub async fn get_playurl( data_type: SesourceType::PlayUrl, health_type: HealthType::Offline, }); - spawn(move || { + tokio::spawn(async move { //println!("[Debug] bilisender_cl.len:{}", bilisender_cl.len()); match bilisender_cl.try_send(senddata) { Ok(_) => (), @@ -498,7 +497,7 @@ pub async fn get_playurl( data_type: SesourceType::PlayUrl, health_type: HealthType::Offline, }); - spawn(move || { + tokio::spawn(async move { //println!("[Debug] bilisender_cl.len:{}", bilisender_cl.len()); match bilisender_cl.try_send(senddata) { Ok(_) => (), @@ -565,7 +564,7 @@ pub async fn get_playurl( data_type: SesourceType::PlayUrl, health_type: HealthType::Online, }); - spawn(move || { + tokio::spawn(async move { //println!("[Debug] bilisender_cl.len:{}", bilisender_cl.len()); match bilisender_cl.try_send(senddata) { Ok(_) => (), @@ -592,7 +591,7 @@ pub async fn get_playurl( data_type: SesourceType::PlayUrl, health_type: HealthType::Online, }); - spawn(move || { + tokio::spawn(async move { //println!("[Debug] bilisender_cl.len:{}", bilisender_cl.len()); match bilisender_cl.try_send(senddata) { Ok(_) => (), @@ -618,7 +617,7 @@ pub async fn get_playurl( area_num, is_app, }); - spawn(move || { + tokio::spawn(async move { //println!("[Debug] bilisender_cl.len:{}", bilisender_cl.len()); match bilisender_cl.try_send(senddata) { Ok(_) => (), @@ -961,7 +960,7 @@ pub async fn get_search(req: &HttpRequest, is_app: bool, is_th: bool) -> HttpRes data_type: SesourceType::PlayUrl, health_type: HealthType::Offline, }); - spawn(move || { + tokio::spawn(async move { //println!("[Debug] bilisender_cl.len:{}", bilisender_cl.len()); match bilisender_cl.try_send(senddata) { Ok(_) => (), @@ -1037,7 +1036,7 @@ pub async fn get_search(req: &HttpRequest, is_app: bool, is_th: bool) -> HttpRes data_type: SesourceType::PlayUrl, health_type: HealthType::Offline, }); - spawn(move || { + tokio::spawn(async move { //println!("[Debug] bilisender_cl.len:{}", bilisender_cl.len()); match bilisender_cl.try_send(senddata) { Ok(_) => (), @@ -1132,7 +1131,7 @@ pub async fn get_search(req: &HttpRequest, is_app: bool, is_th: bool) -> HttpRes data_type: SesourceType::Search, health_type: HealthType::Online, }); - spawn(move || { + tokio::spawn(async move { //println!("[Debug] bilisender_cl.len:{}", bilisender_cl.len()); match bilisender_cl.try_send(senddata) { Ok(_) => (), @@ -1159,7 +1158,7 @@ pub async fn get_search(req: &HttpRequest, is_app: bool, is_th: bool) -> HttpRes data_type: SesourceType::Search, health_type: HealthType::Online, }); - spawn(move || { + tokio::spawn(async move { //println!("[Debug] bilisender_cl.len:{}", bilisender_cl.len()); match bilisender_cl.try_send(senddata) { Ok(_) => (), @@ -1318,7 +1317,7 @@ pub async fn get_season(req: &HttpRequest, _is_app: bool, _is_th: bool) -> HttpR health_type: HealthType::Offline, area_num: 4, }); - spawn(move || { + tokio::spawn(async move { //println!("[Debug] bilisender_cl.len:{}", bilisender_cl.len()); match bilisender_cl.try_send(senddata) { Ok(_) => (), @@ -1468,7 +1467,7 @@ pub async fn get_season(req: &HttpRequest, _is_app: bool, _is_th: bool) -> HttpR data_type: SesourceType::PlayUrl, health_type: HealthType::Online, }); - spawn(move || { + tokio::spawn(async move { //println!("[Debug] bilisender_cl.len:{}", bilisender_cl.len()); match bilisender_cl.try_send(senddata) { Ok(_) => (), @@ -1495,7 +1494,7 @@ pub async fn get_season(req: &HttpRequest, _is_app: bool, _is_th: bool) -> HttpR data_type: SesourceType::PlayUrl, health_type: HealthType::Online, }); - spawn(move || { + tokio::spawn(async move { //println!("[Debug] bilisender_cl.len:{}", bilisender_cl.len()); match bilisender_cl.try_send(senddata) { Ok(_) => (), From bb0b04a58dd18b62863bce8e4fa3cc243fb4bc88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E4=BD=B3=E6=B4=9B?= <73123406+pchpub@users.noreply.github.com> Date: Wed, 5 Oct 2022 08:03:45 +0800 Subject: [PATCH 2/2] fix bug --- src/mods/tools.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/mods/tools.rs b/src/mods/tools.rs index a9f2a790..51e57f9c 100644 --- a/src/mods/tools.rs +++ b/src/mods/tools.rs @@ -341,7 +341,17 @@ pub async fn redir_playurl_request(req: &HttpRequest, is_app: bool, is_th: bool) _ => 2, }; if config.area_cache_open { - if let Ok(value) = get_ep_area(pool, query.get("ep_id").unwrap(), &area_num).await { + let ep_id = if let Some(value) = query.get("ep_id") { + value + }else{ + let return_data = + match get_playurl(req, is_app, is_th, query_string, query, area_num).await { + Ok(value) => value, + Err(value) => value, + }; + return build_response(return_data); + }; + if let Ok(value) = get_ep_area(pool, ep_id, &area_num).await { match value { GetEpAreaType::NoCurrentAreaData(key, redis_value) => { match get_playurl(req, is_app, is_th, query_string, query, area_num).await {