diff --git a/src/constants/inner_constants.rs b/src/constants/inner_constants.rs index c94d7735..f09ab57d 100644 --- a/src/constants/inner_constants.rs +++ b/src/constants/inner_constants.rs @@ -130,4 +130,8 @@ pub const CSS: &str = "css"; pub const JS: &str = "javascript"; -pub const MAX_FILE_TREE_DEPTH:i32 = 4; \ No newline at end of file +pub const MAX_FILE_TREE_DEPTH:i32 = 4; + + +pub const COMMON_USER_AGENT: &str = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 \ +(KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36"; \ No newline at end of file diff --git a/src/controllers/podcast_controller.rs b/src/controllers/podcast_controller.rs index c14d0f9c..5502c7d2 100644 --- a/src/controllers/podcast_controller.rs +++ b/src/controllers/podcast_controller.rs @@ -26,7 +26,7 @@ use std::thread; use actix_web::dev::PeerAddr; use actix_web::http::{Method}; use tokio::task::spawn_blocking; -use crate::constants::inner_constants::{PodcastType}; +use crate::constants::inner_constants::{COMMON_USER_AGENT, PodcastType}; use crate::models::user::User; use crate::mutex::LockResultExt; @@ -295,6 +295,7 @@ pub async fn add_podcast_by_feed( } let client = AsyncClientBuilder::new().build().unwrap(); let mut header_map = HeaderMap::new(); + header_map.insert("User-Agent", COMMON_USER_AGENT.parse().unwrap()); add_basic_auth_headers_conditionally(rss_feed.clone().rss_feed_url, &mut header_map); let result = client.get(rss_feed.clone().rss_feed_url) .headers(header_map) @@ -302,8 +303,9 @@ pub async fn add_podcast_by_feed( .await .map_err(map_reqwest_error)?; - let bytes = result.bytes().await.unwrap(); - let channel = Channel::read_from(&*bytes).unwrap(); + let bytes = result.text().await.unwrap(); + println!("{}", bytes); + let channel = Channel::read_from(bytes.as_bytes()).unwrap(); let num = rand::thread_rng().gen_range(100..10000000); let res; diff --git a/src/service/podcast_episode_service.rs b/src/service/podcast_episode_service.rs index d346abb1..749f52b7 100644 --- a/src/service/podcast_episode_service.rs +++ b/src/service/podcast_episode_service.rs @@ -1,6 +1,6 @@ use std::io::Error; use std::sync::{Arc, Mutex}; -use crate::constants::inner_constants::{PodcastType, TELEGRAM_API_ENABLED}; +use crate::constants::inner_constants::{COMMON_USER_AGENT, PodcastType, TELEGRAM_API_ENABLED}; use crate::models::podcast_episode::PodcastEpisode; use crate::models::podcasts::Podcast; use crate::models::messages::BroadcastMessage; @@ -477,7 +477,7 @@ impl PodcastEpisodeService { })).build().unwrap(); let mut header_map = HeaderMap::new(); header_map.append(ACCEPT, "application/rss+xml,application/xml".parse().unwrap()); - header_map.append("User-Agent", "PostmanRuntime/7.32.2".parse().unwrap()); + header_map.append("User-Agent", COMMON_USER_AGENT.parse().unwrap()); let result = client .get(podcast.clone().rssfeed) .headers(header_map) diff --git a/src/service/rust_service.rs b/src/service/rust_service.rs index 594645e5..c286b003 100644 --- a/src/service/rust_service.rs +++ b/src/service/rust_service.rs @@ -1,6 +1,6 @@ use std::sync::{MutexGuard}; -use crate::constants::inner_constants::{PodcastType, ITUNES_URL}; +use crate::constants::inner_constants::{PodcastType, ITUNES_URL, COMMON_USER_AGENT}; use crate::models::podcast_dto::PodcastDto; use crate::models::podcasts::Podcast; @@ -271,7 +271,7 @@ impl PodcastService { let hashed_auth_key = format!("{:x}", hasher.finalize()); - headers.insert("User-Agent", HeaderValue::from_str("Podfetch").unwrap()); + headers.insert("User-Agent", HeaderValue::from_str(COMMON_USER_AGENT).unwrap()); headers.insert( "X-Auth-Key", HeaderValue::from_str(&self.environment_service.podindex_api_key.clone()).unwrap(),