From 1ad82e513e0aba0e60f1b5008c3b09eeec694635 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=B4=80=E1=B4=8D=E1=B4=9B=E1=B4=8F=E1=B4=80=E1=B4=87?= =?UTF-8?q?=CA=80?= Date: Thu, 25 Apr 2024 22:56:47 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E9=A3=8E=E6=8E=A7?= =?UTF-8?q?=E5=88=A4=E6=96=AD=E9=94=99=E8=AF=AF=EF=BC=8C=E4=BB=A5=E5=8F=8A?= =?UTF-8?q?=E5=8F=AF=E8=83=BD=E7=9A=84=E9=98=BB=E5=A1=9E=E9=97=AE=E9=A2=98?= =?UTF-8?q?=20(#77)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: 尝试修复风控判断错误,以及可能的阻塞问题 * fix: 继续修复 --- Cargo.lock | 49 ++++++++++++++++++++++++------------------ Cargo.toml | 2 +- src/bilibili/client.rs | 2 ++ src/core/command.rs | 9 ++++---- 4 files changed, 36 insertions(+), 26 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8966ccd..cec8f82 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -393,6 +393,12 @@ version = "0.21.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" +[[package]] +name = "base64" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9475866fec1451be56a3c2400fd081ff546538961565ccb5b7142cbd22bc7a51" + [[package]] name = "base64ct" version = "1.6.0" @@ -1513,15 +1519,6 @@ version = "2.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3" -[[package]] -name = "itertools" -version = "0.10.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" -dependencies = [ - "either", -] - [[package]] name = "itertools" version = "0.12.1" @@ -2098,7 +2095,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "19de2de2a00075bf566bee3bd4db014b11587e84184d3f7a791bc17f1a8e9e48" dependencies = [ "anyhow", - "itertools 0.10.5", + "itertools", "proc-macro2", "quote", "syn 2.0.58", @@ -2270,12 +2267,12 @@ dependencies = [ [[package]] name = "reqwest" -version = "0.12.2" +version = "0.12.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d66674f2b6fb864665eea7a3c1ac4e3dfacd2fda83cf6f935a612e01b0e3338" +checksum = "566cafdd92868e0939d3fb961bd0dc25fcfaaed179291093b3d43e6b3150ea10" dependencies = [ "async-compression", - "base64", + "base64 0.22.0", "bytes", "cookie 0.17.0", "cookie_store", @@ -2297,7 +2294,7 @@ dependencies = [ "percent-encoding", "pin-project-lite", "rustls 0.22.3", - "rustls-pemfile", + "rustls-pemfile 2.1.2", "rustls-pki-types", "serde", "serde_json", @@ -2461,7 +2458,17 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1c74cae0a4cf6ccbbf5f359f08efdf8ee7e1dc532573bf0db71968cb56b1448c" dependencies = [ - "base64", + "base64 0.21.7", +] + +[[package]] +name = "rustls-pemfile" +version = "2.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29993a25686778eb88d4189742cd713c9bce943bc54251a33509dc63cbacf73d" +dependencies = [ + "base64 0.22.0", + "rustls-pki-types", ] [[package]] @@ -2858,7 +2865,7 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ce81b7bd7c4493975347ef60d8c7e8b742d4694f4c49f93e0a12ea263938176c" dependencies = [ - "itertools 0.12.1", + "itertools", "nom", "unicode_categories", ] @@ -2907,7 +2914,7 @@ dependencies = [ "percent-encoding", "rust_decimal", "rustls 0.21.10", - "rustls-pemfile", + "rustls-pemfile 1.0.4", "serde", "serde_json", "sha2", @@ -2969,7 +2976,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1ed31390216d20e538e447a7a9b959e06ed9fc51c37b514b46eb758016ecd418" dependencies = [ "atoi", - "base64", + "base64 0.21.7", "bigdecimal", "bitflags 2.5.0", "byteorder", @@ -3016,7 +3023,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7c824eb80b894f926f89a0b9da0c7f435d27cdd35b8c655b114e58223918577e" dependencies = [ "atoi", - "base64", + "base64 0.21.7", "bigdecimal", "bitflags 2.5.0", "byteorder", @@ -3887,9 +3894,9 @@ dependencies = [ [[package]] name = "winreg" -version = "0.50.0" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "524e57b2c537c0f9b1e69f1965311ec12182b4122e45035b1508cd24d2adadb1" +checksum = "a277a57398d4bfa075df44f501a17cfdf8542d224f0d36095a2adc7aee4ef0a5" dependencies = [ "cfg-if", "windows-sys 0.48.0", diff --git a/Cargo.toml b/Cargo.toml index d22c70f..9360933 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,7 +25,7 @@ prost = "0.12.4" quick-xml = { version = "0.31.0", features = ["async-tokio"] } rand = "0.8.5" regex = "1.10.3" -reqwest = { version = "0.12.0", features = [ +reqwest = { version = "0.12.4", features = [ "json", "stream", "cookies", diff --git a/src/bilibili/client.rs b/src/bilibili/client.rs index cb80152..b62355d 100644 --- a/src/bilibili/client.rs +++ b/src/bilibili/client.rs @@ -28,6 +28,8 @@ impl Client { reqwest::Client::builder() .default_headers(headers) .gzip(true) + .connect_timeout(std::time::Duration::from_secs(10)) + .read_timeout(std::time::Duration::from_secs(30)) .build() .unwrap(), ) diff --git a/src/core/command.rs b/src/core/command.rs index 3e5d608..308b2e4 100644 --- a/src/core/command.rs +++ b/src/core/command.rs @@ -293,8 +293,8 @@ pub async fn download_video_pages( ), }); if let Err(e) = results.into_iter().nth(4).unwrap() { - if let Ok(e) = e.downcast::() { - return Err(e.into()); + if e.downcast_ref::().is_some() { + return Err(e); } } let mut video_active_model: video::ActiveModel = video_model.into(); @@ -335,6 +335,7 @@ pub async fn dispatch_download_page( } Err(e) => { if e.downcast_ref::().is_some() { + should_error = true; is_break = true; break; } @@ -472,8 +473,8 @@ pub async fn download_page( }); // 查看下载视频的状态,该状态会影响上层是否 break if let Err(e) = results.into_iter().nth(1).unwrap() { - if let Ok(e) = e.downcast::() { - return Err(e.into()); + if let Ok(BiliError::RiskControlOccurred) = e.downcast::() { + bail!(DownloadAbortError()); } } let mut page_active_model: page::ActiveModel = page_model.into();