Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed podcast episode not containing podcast image. #530

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/constants/inner_constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,5 @@ pub const DEFAULT_DEVICE: &str = "webview";
// static constants

pub static ENVIRONMENT_SERVICE: OnceLock<EnvironmentService> = OnceLock::new();

pub static DEFAULT_IMAGE_URL: &str = "ui/default.jpg";
6 changes: 3 additions & 3 deletions src/controllers/controller_utils.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::constants::inner_constants::ENVIRONMENT_SERVICE;
use crate::constants::inner_constants::{DEFAULT_IMAGE_URL, ENVIRONMENT_SERVICE};
use serde_json::Value;

pub fn unwrap_string(value: &Value) -> String {
Expand All @@ -10,7 +10,7 @@ pub fn unwrap_string_audio(value: &Value) -> String {
true => {
let env = ENVIRONMENT_SERVICE.get().unwrap();

env.server_url.clone().to_owned() + "ui/default.jpg"
env.server_url.clone().to_owned() + DEFAULT_IMAGE_URL
}
false => value.to_string().replace('\"', ""),
}
Expand All @@ -19,5 +19,5 @@ pub fn unwrap_string_audio(value: &Value) -> String {
pub fn get_default_image() -> String {
let env = ENVIRONMENT_SERVICE.get().unwrap();

env.server_url.clone().to_owned() + "ui/default.jpg"
env.server_url.clone().to_owned() + DEFAULT_IMAGE_URL
}
6 changes: 2 additions & 4 deletions src/controllers/podcast_controller.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use crate::constants::inner_constants::{
PodcastType, BASIC_AUTH, COMMON_USER_AGENT, ENVIRONMENT_SERVICE, OIDC_AUTH,
};
use crate::constants::inner_constants::{PodcastType, BASIC_AUTH, COMMON_USER_AGENT, ENVIRONMENT_SERVICE, OIDC_AUTH, DEFAULT_IMAGE_URL};
use crate::models::dto_models::PodcastFavorUpdateModel;
use crate::models::misc_models::{PodcastAddModel, PodcastInsertModel};
use crate::models::opml_model::OpmlModel;
Expand Down Expand Up @@ -652,7 +650,7 @@ async fn insert_outline(
None => {
log::info!(
"No image found for podcast. Downloading from {}",
environment.server_url.clone().to_owned() + "ui/default.jpg"
environment.server_url.clone().to_owned() + DEFAULT_IMAGE_URL
);
environment.server_url.clone().to_owned() + "ui/default.jpg"
}
Expand Down
8 changes: 4 additions & 4 deletions src/controllers/podcast_episode_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@
)?;
let mapped_podcasts = res
.into_iter()
.map(|podcast| {
let mapped_podcast_episode = MappingService::map_podcastepisode_to_dto(&podcast.0);
.map(|mut podcast| {
let mapped_podcast_episode = MappingService::map_podcastepisode_to_dto(&mut podcast.0);

Check failure on line 65 in src/controllers/podcast_episode_controller.rs

View workflow job for this annotation

GitHub Actions / Rust lint

the function `MappingService::map_podcastepisode_to_dto` doesn't need a mutable reference
PodcastEpisodeWithHistory {
podcast_episode: mapped_podcast_episode,
podcast_history_item: podcast.1,
Expand Down Expand Up @@ -117,9 +117,9 @@
.data
.iter()
.map(|podcast_episode| {
let (podcast_episode, podcast, history, favorite) = podcast_episode.clone();
let (mut podcast_episode, podcast, history, favorite) = podcast_episode.clone();
let mapped_podcast_episode =
MappingService::map_podcastepisode_to_dto(&podcast_episode);
MappingService::map_podcastepisode_to_dto(&mut podcast_episode);

Check failure on line 122 in src/controllers/podcast_episode_controller.rs

View workflow job for this annotation

GitHub Actions / Rust lint

the function `MappingService::map_podcastepisode_to_dto` doesn't need a mutable reference

TimeLinePodcastEpisode {
podcast_episode: mapped_podcast_episode,
Expand Down
16 changes: 13 additions & 3 deletions src/models/podcast_episode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use diesel::{
};
use rss::{Guid, Item};
use utoipa::ToSchema;
use crate::constants::inner_constants::DEFAULT_IMAGE_URL;

#[derive(
Queryable,
Expand Down Expand Up @@ -169,9 +170,18 @@ impl PodcastEpisode {
None => {}
}

let inserted_image_url = match optional_image {
Some(image_url_podcast_episode) => image_url_podcast_episode,
None => podcast.original_image_url,
let inserted_image_url: String = match optional_image {
Some(c)=>{
c
}
None=>match podcast.image_url.is_empty() {
true=>{
DEFAULT_IMAGE_URL.to_string()
}
false=>{
podcast.image_url
}
}
};

let guid_to_insert = Guid {
Expand Down
25 changes: 19 additions & 6 deletions src/service/download_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ use std::io;
use std::io::Read;

use crate::config::dbconfig::establish_connection;
use crate::constants::inner_constants::{PODCAST_FILENAME, PODCAST_IMAGENAME};
use crate::constants::inner_constants::{DEFAULT_IMAGE_URL, PODCAST_FILENAME, PODCAST_IMAGENAME};
use crate::dbconfig::DBType;
use crate::get_default_image;
use crate::models::file_path::{FilenameBuilder, FilenameBuilderReturn};
use crate::models::settings::Setting;
use crate::service::podcast_episode_service::PodcastEpisodeService;
Expand Down Expand Up @@ -53,11 +54,23 @@ impl DownloadService {
.send()
.unwrap();

let mut image_response = client
.get(podcast_episode.image_url.clone())
.headers(header_map)
.send()
.unwrap();
let mut image_response;
match podcast_episode.image_url == DEFAULT_IMAGE_URL {
true=>{
image_response = client
.get(get_default_image())
.headers(header_map)
.send()
.unwrap();
}
false=>{
image_response = client
.get(podcast_episode.image_url.clone())
.headers(header_map)
.send()
.unwrap();
}
}

let paths = match settings_in_db.use_existing_filename {
true => FilenameBuilder::default()
Expand Down
18 changes: 15 additions & 3 deletions src/service/mapping_service.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::constants::inner_constants::ENVIRONMENT_SERVICE;
use crate::constants::inner_constants::{DEFAULT_IMAGE_URL, ENVIRONMENT_SERVICE};
use crate::models::favorites::Favorite;
use crate::models::podcast_dto::PodcastDto;
use crate::models::podcast_episode::PodcastEpisode;
Expand Down Expand Up @@ -65,6 +65,7 @@ impl MappingService {
}

pub fn map_podcastepisode_to_dto(podcast_episode: &PodcastEpisode) -> PodcastEpisode {

PodcastEpisode {
id: podcast_episode.id,
podcast_id: podcast_episode.podcast_id,
Expand All @@ -73,10 +74,10 @@ impl MappingService {
description: podcast_episode.description.clone(),
url: podcast_episode.url.clone(),
date_of_recording: podcast_episode.date_of_recording.clone(),
image_url: podcast_episode.image_url.clone(),
image_url: Self::map_image_url(&podcast_episode.image_url.clone()),
total_time: podcast_episode.total_time,
local_url: podcast_episode.local_url.clone(),
local_image_url: podcast_episode.local_image_url.clone(),
local_image_url: Self::map_image_url(&podcast_episode.local_image_url),
status: podcast_episode.status.clone(),
download_time: podcast_episode.download_time,
guid: podcast_episode.guid.clone(),
Expand All @@ -85,4 +86,15 @@ impl MappingService {
file_image_path: None,
}
}

fn map_image_url(image_url: &str) -> String{
match image_url == DEFAULT_IMAGE_URL {
true => {
let env = ENVIRONMENT_SERVICE.get().unwrap();

env.server_url.clone().to_owned() + DEFAULT_IMAGE_URL
}
false => image_url.to_string(),
}
}
}
12 changes: 5 additions & 7 deletions src/service/podcast_episode_service.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use crate::constants::inner_constants::{
PodcastType, COMMON_USER_AGENT, ENVIRONMENT_SERVICE, TELEGRAM_API_ENABLED,
};
use crate::constants::inner_constants::{PodcastType, COMMON_USER_AGENT, ENVIRONMENT_SERVICE, TELEGRAM_API_ENABLED, DEFAULT_IMAGE_URL};
use crate::models::messages::BroadcastMessage;
use crate::models::podcast_episode::PodcastEpisode;
use crate::models::podcasts::Podcast;
Expand Down Expand Up @@ -49,9 +47,9 @@
match PodcastEpisode::check_if_downloaded(&podcast_episode.url, conn) {
Ok(true) => {}
Ok(false) => {
let podcast_inserted =
let mut podcast_inserted =
Self::perform_download(&podcast_episode_cloned, podcast_cloned, conn)?;
let mapped_dto = MappingService::map_podcastepisode_to_dto(&podcast_inserted);
let mapped_dto = MappingService::map_podcastepisode_to_dto(&mut podcast_inserted);

Check failure on line 52 in src/service/podcast_episode_service.rs

View workflow job for this annotation

GitHub Actions / Rust lint

the function `MappingService::map_podcastepisode_to_dto` doesn't need a mutable reference
if let Some(lobby) = lobby {
lobby.do_send(BroadcastMessage {
message: format!(
Expand Down Expand Up @@ -230,7 +228,7 @@
conn,
podcast.clone(),
item.clone(),
Some("ui/default.jpg".parse().unwrap()),
Some(DEFAULT_IMAGE_URL.to_string()),
duration_episode,
);
podcast_inserted.push(inserted_episode);
Expand All @@ -252,7 +250,7 @@
}
None => {
let env = ENVIRONMENT_SERVICE.get().unwrap();
let url = env.server_url.clone().to_owned() + "ui/default.jpg";
let url = env.server_url.clone().to_owned() + DEFAULT_IMAGE_URL;
Podcast::update_original_image_url(&url, podcast.id, conn)?;
}
}
Expand Down
Loading