diff --git a/src-tauri/src/core/config.rs b/src-tauri/src/core/config.rs index 591516539..a066c730a 100644 --- a/src-tauri/src/core/config.rs +++ b/src-tauri/src/core/config.rs @@ -51,11 +51,7 @@ impl Default for UserConfig { threads: 1, theme: String::from('1'), update_interval: 0, - local_proxy: Some(LocalProxy { - ip: "".to_string(), - port: "".to_string(), - }), - + local_proxy: None, customize_style: CustomizeStyle::default(), } } @@ -81,7 +77,11 @@ impl UserConfig { } fn update_proxy(&mut self, ip: String, port: String) -> &mut UserConfig { - self.local_proxy = Some(LocalProxy { ip, port }); + if ip == "" && port == "" { + self.local_proxy = None; + } else { + self.local_proxy = Some(LocalProxy { ip, port }); + } self } diff --git a/src-tauri/src/core/scraper.rs b/src-tauri/src/core/scraper.rs index 2d9faf3fa..e167a4411 100644 --- a/src-tauri/src/core/scraper.rs +++ b/src-tauri/src/core/scraper.rs @@ -1,12 +1,12 @@ use reqwest::{self}; use scraper::{self, Selector}; use serde::Serialize; -use tokio::sync::{Mutex}; use std::sync::Arc; -use tokio::sync::mpsc::{channel}; +use tokio::sync::mpsc::channel; +use tokio::sync::Mutex; -use crate::feed; use crate::cmd; +use crate::feed; #[derive(Debug, Default, Serialize)] pub struct PageScraper { @@ -105,11 +105,13 @@ impl PageScraper { println!("start fetch image : {:?}", &url); let image_url = Self::get_first_image_or_og_image(&url).await; println!("end fetch image, we get image: {:?}", image_url); - tx_clone.send((url.clone().to_string(), image_url)).await.unwrap(); + tx_clone + .send((url.clone().to_string(), image_url)) + .await + .unwrap(); let mut counter = counter_clone.lock().await; *counter += 1; }); - } let _counter_clone = counter.clone(); @@ -120,7 +122,6 @@ impl PageScraper { println!("counter {:?} len {:?}", *counter, urls.len()); if *counter >= urls.len() { - print!("stop!!!!!!"); tokio::task::yield_now().await; return image_urls; @@ -135,7 +136,16 @@ impl PageScraper { mod tests { use uuid::Uuid; -use super::*; + use super::*; + #[tokio::test] + async fn test_get_best_image() { + let url = "https://post.smzdm.com/p/akkvmm3e/"; + let res = PageScraper::get_first_image_or_og_image(url) + .await + .unwrap_or("".to_string()); + + println!("res ==> {:?} ", res); + } #[tokio::test] async fn test_from_str() { @@ -152,7 +162,10 @@ use super::*; println!("articles: {:?}", articles); - let urls = articles.into_iter().map(|a| a.link ).collect::>(); + let urls = articles + .into_iter() + .map(|a| a.link) + .collect::>(); let res = PageScraper::get_first_images_or_og_images_async(urls, 5).await; println!("res: {:?}", res); diff --git a/src-tauri/src/feed/mod.rs b/src-tauri/src/feed/mod.rs index 5962a260a..a4d6721a2 100644 --- a/src-tauri/src/feed/mod.rs +++ b/src-tauri/src/feed/mod.rs @@ -1,4 +1,5 @@ use feed_rs::parser; +use log::info; use reqwest; use crate::core::config; @@ -9,26 +10,26 @@ pub mod folder; pub fn create_client() -> reqwest::Client { let user_config = config::get_user_config(); - let client = match user_config { - Some(user_config) => match user_config.local_proxy { - Some(proxy) => { - let mut scheme = String::from("socks5h://"); + let client_builder = reqwest::Client::builder(); - scheme.push_str(&proxy.ip.to_string()); - scheme.push_str(":"); - scheme.push_str(&proxy.port.to_string()); + if let Some(user_config) = user_config { + if let Some(proxy) = user_config.local_proxy { + info!("user_config.local_proxy {:?}", proxy); - reqwest::Client::builder() - .proxy(reqwest::Proxy::all(scheme).unwrap()) - .build() - .unwrap() - } - None => reqwest::Client::builder().build().unwrap(), - }, - None => reqwest::Client::builder().build().unwrap(), - }; + let mut scheme = String::from("socks5h://"); + + scheme.push_str(&proxy.ip.to_string()); + scheme.push_str(":"); + scheme.push_str(&proxy.port.to_string()); + + return client_builder + .proxy(reqwest::Proxy::all(scheme).unwrap()) + .build() + .unwrap(); + } + } - client + client_builder.build().unwrap() } /// request feed, parse Feeds