From 8ada86714c149dd5fe14e447bcbfc14435fd6f31 Mon Sep 17 00:00:00 2001 From: jhqxxx <18280426169@163.com> Date: Fri, 6 Mar 2026 15:50:43 +0800 Subject: [PATCH] fix load_image_from_url blocking bug --- src/utils/audio_utils.rs | 15 --------------- src/utils/img_utils.rs | 21 ++------------------- tests/test_qwen3_5.rs | 2 +- 3 files changed, 3 insertions(+), 35 deletions(-) diff --git a/src/utils/audio_utils.rs b/src/utils/audio_utils.rs index 8851319..bc0680a 100644 --- a/src/utils/audio_utils.rs +++ b/src/utils/audio_utils.rs @@ -282,21 +282,6 @@ pub fn load_audio_from_url(url: &str) -> Result { }) } -// pub fn _load_audio_bytes_from_url(url: &str) -> Result> { -// tokio::task::block_in_place(|| { -// let client = reqwest::blocking::Client::new(); -// let response = client.get(url).send()?; -// if !response.status().is_success() { -// return Err(anyhow::anyhow!( -// "Failed to download file: {}", -// response.status() -// )); -// } -// let bytes = response.bytes()?.to_vec(); -// Ok(bytes) -// }) -// } - pub fn load_audio_bytes_from_url(url: &str) -> Result> { let url = url.to_string(); thread::spawn(move || { diff --git a/src/utils/img_utils.rs b/src/utils/img_utils.rs index d78cbf1..438b1c2 100644 --- a/src/utils/img_utils.rs +++ b/src/utils/img_utils.rs @@ -18,10 +18,10 @@ pub fn load_image_from_url(url: &str) -> Result { thread::spawn(move || { let rt = tokio::runtime::Runtime::new().unwrap(); rt.block_on(async { - let response = reqwest::blocking::get(url) + let response = reqwest::get(url).await .map_err(|e| anyhow!(format!("Failed to fetch image from url: {}", e)))?; let bytes = response - .bytes() + .bytes().await .map_err(|e| anyhow!(format!("Failed to get image bytes: {}", e)))?; let cursor = Cursor::new(bytes); @@ -36,23 +36,6 @@ pub fn load_image_from_url(url: &str) -> Result { .join() .unwrap() } -// pub fn _load_image_from_url(url: &str) -> Result { -// tokio::task::block_in_place(|| { -// let response = reqwest::blocking::get(url) -// .map_err(|e| anyhow!(format!("Failed to fetch image from url: {}", e)))?; -// let bytes = response -// .bytes() -// .map_err(|e| anyhow!(format!("Failed to get image bytes: {}", e)))?; - -// let cursor = Cursor::new(bytes); -// let img = ImageReader::new(cursor) -// .with_guessed_format() -// .map_err(|e| anyhow!(format!("Failed to read image format: {}", e)))? -// .decode() -// .map_err(|e| anyhow!(format!("Failed to decode image: {}", e)))?; -// Ok(img) -// }) -// } pub fn load_image_from_base64(base64_data: &str) -> Result { let image_data = general_purpose::STANDARD diff --git a/tests/test_qwen3_5.rs b/tests/test_qwen3_5.rs index 567899a..7e3b7f7 100644 --- a/tests/test_qwen3_5.rs +++ b/tests/test_qwen3_5.rs @@ -24,7 +24,7 @@ fn qwen3_5_generate() -> Result<()> { "type": "image", "image_url": { - "url": "file:///home/jhq/Downloads/gougou1.jpg" + "url": "https://www.lifeberrys.com/img/article/tourist-attraction-3-1644590220-lb.jpg" } }, {