From 78974c19de99c85611b3629b1aa852264cab4607 Mon Sep 17 00:00:00 2001 From: SamTV12345 <40429738+samtv12345@users.noreply.github.com> Date: Mon, 30 Dec 2024 20:24:20 +0100 Subject: [PATCH] fix(file): Fixed idv3 tagging --- src/adapters/api/controllers/routes.rs | 9 +++--- .../api/models/podcast_episode_dto.rs | 11 ++----- src/adapters/persistence/dbconfig/db.rs | 6 ++-- src/adapters/ws/mod.rs | 2 +- src/adapters/ws/ws_handler.rs | 1 + src/auth_middleware.rs | 5 +--- src/constants/inner_constants.rs | 12 ++++---- src/controllers/controller_utils.rs | 6 +--- src/controllers/podcast_controller.rs | 29 ++++--------------- src/controllers/settings_controller.rs | 7 +++-- src/controllers/user_controller.rs | 7 ++--- src/gpodder/auth/authentication.rs | 5 +--- src/main.rs | 6 ++-- src/models/user.rs | 1 - src/service/download_service.rs | 12 ++++++++ src/service/rust_service.rs | 9 ++---- src/service/telegram_api.rs | 5 +--- src/service/user_management_service.rs | 8 ++--- 18 files changed, 53 insertions(+), 88 deletions(-) diff --git a/src/adapters/api/controllers/routes.rs b/src/adapters/api/controllers/routes.rs index 125a6ade..2022cd18 100644 --- a/src/adapters/api/controllers/routes.rs +++ b/src/adapters/api/controllers/routes.rs @@ -18,7 +18,10 @@ use utoipa::OpenApi; use utoipa_swagger_ui::SwaggerUi; pub fn global_routes() -> Scope { - let base_path = ENVIRONMENT_SERVICE.sub_directory.clone().unwrap_or("/".to_string()); + let base_path = ENVIRONMENT_SERVICE + .sub_directory + .clone() + .unwrap_or("/".to_string()); let openapi = ApiDoc::openapi(); let service = get_api_config(); @@ -38,9 +41,7 @@ pub fn global_routes() -> Scope { } pub fn get_gpodder_api() -> Scope { - if ENVIRONMENT_SERVICE - .gpodder_integration_enabled - { + if ENVIRONMENT_SERVICE.gpodder_integration_enabled { web::scope("/api/2") .service(login) .service(get_authenticated_gpodder()) diff --git a/src/adapters/api/models/podcast_episode_dto.rs b/src/adapters/api/models/podcast_episode_dto.rs index 6e5c55fb..d6c7d85e 100644 --- a/src/adapters/api/models/podcast_episode_dto.rs +++ b/src/adapters/api/models/podcast_episode_dto.rs @@ -47,17 +47,10 @@ impl From for PodcastEpisodeDto { } fn map_url(url: &str, status: &str, remote_url: &str) -> String { match url == DEFAULT_IMAGE_URL { - true => { - - ENVIRONMENT_SERVICE.server_url.clone().to_owned() + DEFAULT_IMAGE_URL - } + true => ENVIRONMENT_SERVICE.server_url.clone().to_owned() + DEFAULT_IMAGE_URL, false => { if status == "D" { - ENVIRONMENT_SERVICE - .server_url - .clone() - .to_owned() - + url + ENVIRONMENT_SERVICE.server_url.clone().to_owned() + url } else { remote_url.to_string() } diff --git a/src/adapters/persistence/dbconfig/db.rs b/src/adapters/persistence/dbconfig/db.rs index 6ecae108..aec72cf2 100644 --- a/src/adapters/persistence/dbconfig/db.rs +++ b/src/adapters/persistence/dbconfig/db.rs @@ -51,10 +51,8 @@ pub fn get_connection() -> r2d2::PooledConnection> { fn init_pool() -> DbPool { let conn = establish_connection(); match conn { - DBType::Postgresql(_) => { - init_postgres_db_pool(&ENVIRONMENT_SERVICE.database_url) - .expect("Failed to connect to database") - } + DBType::Postgresql(_) => init_postgres_db_pool(&ENVIRONMENT_SERVICE.database_url) + .expect("Failed to connect to database"), DBType::Sqlite(_) => init_sqlite_db_pool(&ENVIRONMENT_SERVICE.database_url) .expect("Failed to connect to database"), } diff --git a/src/adapters/ws/mod.rs b/src/adapters/ws/mod.rs index e92d5797..39e80e61 100644 --- a/src/adapters/ws/mod.rs +++ b/src/adapters/ws/mod.rs @@ -1 +1 @@ -pub mod ws_handler; \ No newline at end of file +pub mod ws_handler; diff --git a/src/adapters/ws/ws_handler.rs b/src/adapters/ws/ws_handler.rs index e69de29b..8b137891 100644 --- a/src/adapters/ws/ws_handler.rs +++ b/src/adapters/ws/ws_handler.rs @@ -0,0 +1 @@ + diff --git a/src/auth_middleware.rs b/src/auth_middleware.rs index a5420f24..c556e66d 100644 --- a/src/auth_middleware.rs +++ b/src/auth_middleware.rs @@ -230,10 +230,7 @@ where } fn handle_proxy_auth(&self, req: ServiceRequest) -> MyFuture { - let config = ENVIRONMENT_SERVICE - .reverse_proxy_config - .clone() - .unwrap(); + let config = ENVIRONMENT_SERVICE.reverse_proxy_config.clone().unwrap(); let header_val = req.headers().get(config.header_name); diff --git a/src/constants/inner_constants.rs b/src/constants/inner_constants.rs index c4615e80..804b898c 100644 --- a/src/constants/inner_constants.rs +++ b/src/constants/inner_constants.rs @@ -39,8 +39,8 @@ pub const TELEGRAM_BOT_TOKEN: &str = "TELEGRAM_BOT_TOKEN"; pub const TELEGRAM_BOT_CHAT_ID: &str = "TELEGRAM_BOT_CHAT_ID"; pub const TELEGRAM_API_ENABLED: &str = "TELEGRAM_API_ENABLED"; -use utoipa::ToSchema; use crate::service::logging_service::init_logging; +use utoipa::ToSchema; // User management roles #[derive(Serialize, Deserialize, Debug, PartialEq, ToSchema)] @@ -134,12 +134,10 @@ pub const DEFAULT_DEVICE: &str = "webview"; // static constants -pub static ENVIRONMENT_SERVICE: LazyLock = LazyLock::new - (|| { - init_logging(); - EnvironmentService::new() - }); - +pub static ENVIRONMENT_SERVICE: LazyLock = LazyLock::new(|| { + init_logging(); + EnvironmentService::new() +}); pub static DEFAULT_IMAGE_URL: &str = "ui/default.jpg"; pub static ITUNES: &str = "itunes"; diff --git a/src/controllers/controller_utils.rs b/src/controllers/controller_utils.rs index 46aca8ba..ec9c3816 100644 --- a/src/controllers/controller_utils.rs +++ b/src/controllers/controller_utils.rs @@ -7,15 +7,11 @@ pub fn unwrap_string(value: &Value) -> String { pub fn unwrap_string_audio(value: &Value) -> String { match value.to_string().is_empty() { - true => { - - ENVIRONMENT_SERVICE.server_url.clone().to_owned() + DEFAULT_IMAGE_URL - } + true => ENVIRONMENT_SERVICE.server_url.clone().to_owned() + DEFAULT_IMAGE_URL, false => value.to_string().replace('\"', ""), } } pub fn get_default_image() -> String { - ENVIRONMENT_SERVICE.server_url.clone().to_owned() + DEFAULT_IMAGE_URL } diff --git a/src/controllers/podcast_controller.rs b/src/controllers/podcast_controller.rs index a7fcf631..0b61c3e0 100644 --- a/src/controllers/podcast_controller.rs +++ b/src/controllers/podcast_controller.rs @@ -194,10 +194,7 @@ pub async fn find_podcast( Ok(HttpResponse::Ok().json(res)) } Ok(Podindex) => { - if !ENVIRONMENT_SERVICE - .get_config() - .podindex_configured - { + if !ENVIRONMENT_SERVICE.get_config().podindex_configured { return Ok(HttpResponse::BadRequest().json("Podindex is not configured")); } @@ -331,11 +328,7 @@ pub async fn import_podcasts_from_opml( thread::spawn(move || { let rt = Runtime::new().unwrap(); let rng = rand::thread_rng(); - rt.block_on(insert_outline( - outline.clone(), - moved_lobby, - rng.clone(), - )); + rt.block_on(insert_outline(outline.clone(), moved_lobby, rng.clone())); }); } }); @@ -360,10 +353,7 @@ pub async fn add_podcast_from_podindex( return Err(CustomError::Forbidden); } - if !ENVIRONMENT_SERVICE - .get_config() - .podindex_configured - { + if !ENVIRONMENT_SERVICE.get_config().podindex_configured { return Err(CustomError::BadRequest( "Podindex is not configured".to_string(), )); @@ -527,19 +517,10 @@ pub async fn update_active_podcast( } #[async_recursion(?Send)] -async fn insert_outline( - podcast: Outline, - lobby: Data, - mut rng: ThreadRng, -) { +async fn insert_outline(podcast: Outline, lobby: Data, mut rng: ThreadRng) { if !podcast.outlines.is_empty() { for outline_nested in podcast.clone().outlines { - insert_outline( - outline_nested, - lobby.clone(), - rng.clone(), - ) - .await; + insert_outline(outline_nested, lobby.clone(), rng.clone()).await; } return; } diff --git a/src/controllers/settings_controller.rs b/src/controllers/settings_controller.rs index aafc5c73..9cb1b249 100644 --- a/src/controllers/settings_controller.rs +++ b/src/controllers/settings_controller.rs @@ -155,8 +155,11 @@ fn add_podcasts( outline.add_attribute("type", "rss"); match type_of { Mode::Local => { - let mut local_url = format!("{}rss/{}", &*ENVIRONMENT_SERVICE.get_server_url(), - podcast.id); + let mut local_url = format!( + "{}rss/{}", + &*ENVIRONMENT_SERVICE.get_server_url(), + podcast.id + ); if let Some(req) = requester.as_ref() { if let Some(api_key) = req.api_key.as_ref() { diff --git a/src/controllers/user_controller.rs b/src/controllers/user_controller.rs index cc381b3f..5f112458 100644 --- a/src/controllers/user_controller.rs +++ b/src/controllers/user_controller.rs @@ -149,8 +149,7 @@ pub async fn update_user( } } - if old_username != &user_update.username && !ENVIRONMENT_SERVICE.oidc_configured - { + if old_username != &user_update.username && !ENVIRONMENT_SERVICE.oidc_configured { // Check if this username is already taken let new_username_res = User::find_by_username(&user_update.username); if new_username_res.is_ok() { @@ -269,9 +268,7 @@ pub async fn get_invite_link( return HttpResponse::Forbidden().body("You are not authorized to perform this action"); } - match UserManagementService::get_invite_link( - invite_id.into_inner(), - ) { + match UserManagementService::get_invite_link(invite_id.into_inner()) { Ok(invite) => HttpResponse::Ok().json(invite), Err(e) => HttpResponse::BadRequest().body(e.to_string()), } diff --git a/src/gpodder/auth/authentication.rs b/src/gpodder/auth/authentication.rs index d4e9b589..ee895b5f 100644 --- a/src/gpodder/auth/authentication.rs +++ b/src/gpodder/auth/authentication.rs @@ -30,10 +30,7 @@ pub async fn login( } } -fn handle_proxy_auth( - rq: HttpRequest, - username: String, -) -> Result { +fn handle_proxy_auth(rq: HttpRequest, username: String) -> Result { let config = ENVIRONMENT_SERVICE.reverse_proxy_config.clone().unwrap(); let opt_authorization = rq.headers().get(config.header_name); match opt_authorization { diff --git a/src/main.rs b/src/main.rs index 7061ec0e..3ce0200e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -130,9 +130,9 @@ pub static INDEX_HTML: OnceLock = OnceLock::new(); async fn index() -> actix_web::Result { let html = INDEX_HTML.get_or_init(|| { let dir = ENVIRONMENT_SERVICE.sub_directory.clone().unwrap() + "/ui/"; - let manifest_json_location = ENVIRONMENT_SERVICE.sub_directory.clone().unwrap() - +"/manifest.json"; - let found_files = std::fs::read_dir( "./static/assets/") + let manifest_json_location = + ENVIRONMENT_SERVICE.sub_directory.clone().unwrap() + "/manifest.json"; + let found_files = std::fs::read_dir("./static/assets/") .expect("Could not read directory") .map(|x| x.unwrap().file_name().into_string().unwrap()) .collect::>(); diff --git a/src/models/user.rs b/src/models/user.rs index 152fead8..6d808232 100644 --- a/src/models/user.rs +++ b/src/models/user.rs @@ -313,7 +313,6 @@ impl User { return false; } - if let Some(res) = ENVIRONMENT_SERVICE.api_key_admin.clone() { if !res.is_empty() && res == api_key_to_find { return true; diff --git a/src/service/download_service.rs b/src/service/download_service.rs index e36cfd78..7eae5f16 100644 --- a/src/service/download_service.rs +++ b/src/service/download_service.rs @@ -149,6 +149,18 @@ impl DownloadService { log::error!("Error updating metadata: {:?}", err); } } + FileFormat::Id3v2 => { + let result_of_update = Self::update_meta_data_mp3(paths, podcast_episode, podcast); + if let Some(err) = result_of_update.err() { + log::error!("Error updating metadata: {:?}", err); + } + } + FileFormat::WaveformAudio => { + let result_of_update = Self::update_meta_data_mp3(paths, podcast_episode, podcast); + if let Some(err) = result_of_update.err() { + log::error!("Error updating metadata: {:?}", err); + } + } _ => { log::error!("File format not supported: {:?}", detected_file); return Err(CustomError::Conflict( diff --git a/src/service/rust_service.rs b/src/service/rust_service.rs index 4ca3ea91..abae2803 100644 --- a/src/service/rust_service.rs +++ b/src/service/rust_service.rs @@ -267,13 +267,8 @@ impl PodcastService { .unwrap() .as_secs(); let mut headers = HeaderMap::new(); - let non_hashed_string = ENVIRONMENT_SERVICE - .podindex_api_key - .clone() - .to_owned() - + &*ENVIRONMENT_SERVICE - .podindex_api_secret - .clone() + let non_hashed_string = ENVIRONMENT_SERVICE.podindex_api_key.clone().to_owned() + + &*ENVIRONMENT_SERVICE.podindex_api_secret.clone() + &seconds.to_string(); let mut hasher = Sha1::new(); diff --git a/src/service/telegram_api.rs b/src/service/telegram_api.rs index 926fe8dc..fd4666f8 100644 --- a/src/service/telegram_api.rs +++ b/src/service/telegram_api.rs @@ -4,10 +4,7 @@ use crate::models::podcasts::Podcast; use frankenstein::{Api, ParseMode, SendMessageParams, TelegramApi}; pub fn send_new_episode_notification(podcast_episode: PodcastEpisode, podcast: Podcast) { - let telegram_config = ENVIRONMENT_SERVICE - .telegram_api - .clone() - .unwrap(); + let telegram_config = ENVIRONMENT_SERVICE.telegram_api.clone().unwrap(); let api = Api::new(&telegram_config.telegram_bot_token); let episode_text = format!( diff --git a/src/service/user_management_service.rs b/src/service/user_management_service.rs index ed97f699..2a0eef30 100644 --- a/src/service/user_management_service.rs +++ b/src/service/user_management_service.rs @@ -126,12 +126,12 @@ impl UserManagementService { } } - pub fn get_invite_link( - invite_id: String, - ) -> Result { + pub fn get_invite_link(invite_id: String) -> Result { let invite = Invite::find_invite(invite_id)?; match invite { - Some(invite) => Ok(ENVIRONMENT_SERVICE.server_url.to_string() + "ui/invite/" + &invite.id), + Some(invite) => { + Ok(ENVIRONMENT_SERVICE.server_url.to_string() + "ui/invite/" + &invite.id) + } None => Err(CustomError::NotFound), } }