diff --git a/src/ipdb.rs b/src/ipdb.rs index c0d231f..88199c2 100644 --- a/src/ipdb.rs +++ b/src/ipdb.rs @@ -32,7 +32,7 @@ impl DbType { } } - async fn db_path(&self) -> color_eyre::Result { + async fn db_path(self) -> color_eyre::Result { let mut cache_path = get_cache_path().await.wrap_err("failed to get cache path")?; match self { @@ -42,7 +42,7 @@ impl DbType { Ok(cache_path) } - async fn etag_path(&self) -> color_eyre::Result { + async fn etag_path(self) -> color_eyre::Result { let mut db_path = self.db_path().await.wrap_err_with(move || { format!("failed to get {} database path", self.name()) })?; @@ -51,13 +51,13 @@ impl DbType { } async fn save_db( - &self, + self, mut response: reqwest::Response, #[cfg(feature = "tui")] tx: tokio::sync::mpsc::UnboundedSender, ) -> color_eyre::Result<()> { #[cfg(feature = "tui")] drop(tx.send(Event::App(AppEvent::IpDbTotal( - *self, + self, response.content_length(), )))); @@ -73,18 +73,17 @@ impl DbType { format!("failed to write to file {}", db_path.display()) })?; #[cfg(feature = "tui")] - drop(tx.send(Event::App(AppEvent::IpDbDownloaded( - *self, - chunk.len(), - )))); + drop( + tx.send(Event::App(AppEvent::IpDbDownloaded( + self, + chunk.len(), + ))), + ); } Ok(()) } - async fn save_etag( - &self, - etag: impl AsRef<[u8]>, - ) -> color_eyre::Result<()> { + async fn save_etag(self, etag: impl AsRef<[u8]>) -> color_eyre::Result<()> { let path = self.etag_path().await?; tokio::fs::write(&path, etag).await.wrap_err_with(move || { format!("failed to write to file {}", path.display()) @@ -92,7 +91,7 @@ impl DbType { } async fn read_etag( - &self, + self, ) -> color_eyre::Result> { let path = self.etag_path().await?; match tokio::fs::read_to_string(&path).await { @@ -104,7 +103,7 @@ impl DbType { } } - async fn remove_etag(&self) -> color_eyre::Result<()> { + async fn remove_etag(self) -> color_eyre::Result<()> { let path = self.etag_path().await?; match tokio::fs::remove_file(&path).await { Ok(()) => Ok(()), diff --git a/src/scraper.rs b/src/scraper.rs index 5468076..7436bd3 100644 --- a/src/scraper.rs +++ b/src/scraper.rs @@ -123,15 +123,13 @@ pub async fn scrape_all( let proxies = Arc::new(tokio::sync::Mutex::new(HashSet::new())); let mut join_set = tokio::task::JoinSet::new(); - for (proto, sources) in &config.scraping.sources { + for (&proto, sources) in &config.scraping.sources { #[cfg(feature = "tui")] - drop( - tx.send(Event::App(AppEvent::SourcesTotal(*proto, sources.len()))), - ); + drop(tx.send(Event::App(AppEvent::SourcesTotal(proto, sources.len())))); + for source in sources.iter().cloned() { let config = Arc::clone(&config); let http_client = http_client.clone(); - let proto_copy = *proto; let proxies = Arc::clone(&proxies); let token = token.clone(); #[cfg(feature = "tui")] @@ -142,7 +140,7 @@ pub async fn scrape_all( res = scrape_one( config, http_client, - proto_copy, + proto, proxies, source, #[cfg(feature = "tui")]