fix load_image_from_url blocking bug
This commit is contained in:
@@ -282,21 +282,6 @@ pub fn load_audio_from_url(url: &str) -> Result<PathBuf> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// pub fn _load_audio_bytes_from_url(url: &str) -> Result<Vec<u8>> {
|
|
||||||
// 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<Vec<u8>> {
|
pub fn load_audio_bytes_from_url(url: &str) -> Result<Vec<u8>> {
|
||||||
let url = url.to_string();
|
let url = url.to_string();
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
|
|||||||
+2
-19
@@ -18,10 +18,10 @@ pub fn load_image_from_url(url: &str) -> Result<DynamicImage> {
|
|||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
let rt = tokio::runtime::Runtime::new().unwrap();
|
let rt = tokio::runtime::Runtime::new().unwrap();
|
||||||
rt.block_on(async {
|
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)))?;
|
.map_err(|e| anyhow!(format!("Failed to fetch image from url: {}", e)))?;
|
||||||
let bytes = response
|
let bytes = response
|
||||||
.bytes()
|
.bytes().await
|
||||||
.map_err(|e| anyhow!(format!("Failed to get image bytes: {}", e)))?;
|
.map_err(|e| anyhow!(format!("Failed to get image bytes: {}", e)))?;
|
||||||
|
|
||||||
let cursor = Cursor::new(bytes);
|
let cursor = Cursor::new(bytes);
|
||||||
@@ -36,23 +36,6 @@ pub fn load_image_from_url(url: &str) -> Result<DynamicImage> {
|
|||||||
.join()
|
.join()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
// pub fn _load_image_from_url(url: &str) -> Result<DynamicImage> {
|
|
||||||
// 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<DynamicImage> {
|
pub fn load_image_from_base64(base64_data: &str) -> Result<DynamicImage> {
|
||||||
let image_data = general_purpose::STANDARD
|
let image_data = general_purpose::STANDARD
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ fn qwen3_5_generate() -> Result<()> {
|
|||||||
"type": "image",
|
"type": "image",
|
||||||
"image_url":
|
"image_url":
|
||||||
{
|
{
|
||||||
"url": "file:///home/jhq/Downloads/gougou1.jpg"
|
"url": "https://www.lifeberrys.com/img/article/tourist-attraction-3-1644590220-lb.jpg"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user