From 716ef061167a73ada962a04064d3d1276ddc956f Mon Sep 17 00:00:00 2001 From: monosans Date: Mon, 4 Aug 2025 16:27:19 +0300 Subject: [PATCH] fix: enhance URL handling in scrape_one function for better source fetching --- src/scraper.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/scraper.rs b/src/scraper.rs index d563bf7..64c52db 100644 --- a/src/scraper.rs +++ b/src/scraper.rs @@ -9,7 +9,7 @@ use crate::{ http, parsers::PROXY_REGEX, proxy::{Proxy, ProxyType}, - utils::{is_http_url, pretty_error}, + utils::pretty_error, }; async fn scrape_one( @@ -20,8 +20,20 @@ async fn scrape_one( source: &str, #[cfg(feature = "tui")] tx: tokio::sync::mpsc::UnboundedSender, ) -> color_eyre::Result<()> { - let text_result = if is_http_url(source) { - http::fetch_text(http_client, source).await + let text_result = if let Ok(u) = url::Url::parse(source) { + match u.scheme() { + "http" | "https" => http::fetch_text(http_client, source).await, + _ => match u.to_file_path() { + Ok(path) => tokio::fs::read_to_string(path).await, + Err(()) => { + tokio::fs::read_to_string( + source.strip_prefix("file://").unwrap_or(source), + ) + .await + } + } + .map_err(Into::into), + } } else { tokio::fs::read_to_string( source.strip_prefix("file://").unwrap_or(source),