Skip to content

Commit

Permalink
Fixed request when getting the podcast feed and feed provider require…
Browse files Browse the repository at this point in the history
…s User Agent. (#324)
  • Loading branch information
SamTV12345 authored Sep 17, 2023
1 parent cfe4e2d commit 0e14ff5
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
6 changes: 5 additions & 1 deletion src/constants/inner_constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,8 @@ pub const CSS: &str = "css";
pub const JS: &str = "javascript";


pub const MAX_FILE_TREE_DEPTH:i32 = 4;
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";
8 changes: 5 additions & 3 deletions src/controllers/podcast_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -295,15 +295,17 @@ 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)
.send()
.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;
Expand Down
4 changes: 2 additions & 2 deletions src/service/podcast_episode_service.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/service/rust_service.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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(),
Expand Down

0 comments on commit 0e14ff5

Please sign in to comment.