diff --git a/backend/src/model/config/api_proxy.rs b/backend/src/model/config/api_proxy.rs index 510e643c0..3f7ba7f0e 100644 --- a/backend/src/model/config/api_proxy.rs +++ b/backend/src/model/config/api_proxy.rs @@ -187,7 +187,7 @@ impl ApiProxyConfig { .flat_map(|target_user| &target_user.credentials) .find(|credential| credential.username == username) .cloned(); - if result.is_none() && username != "test" { + if result.is_none() && (username != "test" || username != "api") { debug!("Could not find any user {username}"); } result diff --git a/backend/src/model/config/input.rs b/backend/src/model/config/input.rs index ad5178ff2..7ef6ebdb2 100644 --- a/backend/src/model/config/input.rs +++ b/backend/src/model/config/input.rs @@ -1,8 +1,12 @@ +use shared::utils::get_credentials_from_url_str; +use log::debug; +use shared::info_err; use shared::error::{TuliproxError, TuliproxErrorKind}; use crate::model::{macros, EpgConfig}; use shared::utils::{get_base_url_from_str, get_credentials_from_url}; use std::collections::{HashMap}; use url::Url; +use shared::check_input_credentials; use shared::model::{ConfigInputAliasDto, ConfigInputDto, ConfigInputOptionsDto, InputFetchMethod, InputType}; use crate::utils; @@ -112,7 +116,9 @@ pub struct ConfigInput { impl ConfigInput { pub fn prepare(&mut self) -> Result<(), TuliproxError> { - self.prepare_batch() + self.prepare_batch()?; + check_input_credentials!(self, self.input_type, false); + Ok(()) } pub fn get_user_info(&self) -> Option { diff --git a/backend/src/processing/parser/xmltv.rs b/backend/src/processing/parser/xmltv.rs index 9eb1e3e53..c40443215 100644 --- a/backend/src/processing/parser/xmltv.rs +++ b/backend/src/processing/parser/xmltv.rs @@ -547,7 +547,6 @@ mod tests { } use rphonetic::{Encoder, Metaphone}; - use shared::error::TuliproxError; use shared::model::{EpgNamePrefix, EpgSmartMatchConfigDto}; #[test] diff --git a/shared/src/model/config/input.rs b/shared/src/model/config/input.rs index d1c649868..8796883a9 100644 --- a/shared/src/model/config/input.rs +++ b/shared/src/model/config/input.rs @@ -2,33 +2,12 @@ use std::collections::{HashMap, HashSet}; use std::fmt::Display; use std::str::FromStr; use enum_iterator::Sequence; -use crate::{create_tuliprox_error_result, handle_tuliprox_error_result_list, info_err}; +use crate::{check_input_credentials, create_tuliprox_error_result, handle_tuliprox_error_result_list, info_err}; use crate::error::{TuliproxError, TuliproxErrorKind}; use crate::model::{EpgConfigDto}; use crate::utils::{default_as_true, get_base_url_from_str, get_credentials_from_url_str, get_trimmed_string, sanitize_sensitive_info}; use log::debug; -macro_rules! check_input_credentials { - ($this:ident, $input_type:expr) => { - match $input_type { - InputType::M3u | InputType::M3uBatch => { - if $this.username.is_some() || $this.password.is_some() { - debug!("for input type m3u: username and password are ignored"); - } - if $this.username.is_none() && $this.password.is_none() { - let (username, password) = get_credentials_from_url_str(&$this.url); - $this.username = username; - $this.password = password; - } - } - InputType::Xtream | InputType::XtreamBatch => { - if $this.username.is_none() || $this.password.is_none() { - return Err(info_err!("for input type xtream: username and password are mandatory".to_string())); - } - } - } - }; -} #[derive(Debug, Copy, Clone, serde::Serialize, serde::Deserialize, Sequence, PartialEq, Eq, Default)] @@ -162,7 +141,7 @@ impl ConfigInputAliasDto { } self.username = get_trimmed_string(&self.username); self.password = get_trimmed_string(&self.password); - check_input_credentials!(self, input_type); + check_input_credentials!(self, input_type, true); Ok(()) } @@ -215,7 +194,7 @@ impl ConfigInputDto { self.username = get_trimmed_string(&self.username); self.password = get_trimmed_string(&self.password); - check_input_credentials!(self, self.input_type); + check_input_credentials!(self, self.input_type, true); self.persist = get_trimmed_string(&self.persist); if let Some(epg) = self.epg.as_mut() { diff --git a/shared/src/model/config/macros.rs b/shared/src/model/config/macros.rs new file mode 100644 index 000000000..b0cf59907 --- /dev/null +++ b/shared/src/model/config/macros.rs @@ -0,0 +1,34 @@ +#[macro_export] +macro_rules! check_input_credentials { + ($this:ident, $input_type:expr, $definition:expr ) => { + match $input_type { + InputType::M3u | InputType::M3uBatch => { + if $this.username.is_some() || $this.password.is_some() { + debug!("for input type m3u: username and password are ignored"); + } + if $this.username.is_none() && $this.password.is_none() { + let (username, password) = get_credentials_from_url_str(&$this.url); + $this.username = username; + $this.password = password; + } + } + InputType::Xtream => { + if $this.username.is_none() || $this.password.is_none() { + return Err(info_err!("for input type xtream: username and password are mandatory".to_string())); + } + } + InputType::XtreamBatch => { + if $definition { + if $this.url.trim().is_empty() { + return Err(info_err!("for input type xtream-batch: url is mandatory".to_string())); + } + } else if $this.username.is_none() || $this.password.is_none() { + return Err(info_err!("for input type xtream-batch: username and password are mandatory".to_string())); + } + } + + } + }; +} + +pub use check_input_credentials; \ No newline at end of file diff --git a/shared/src/model/config/mod.rs b/shared/src/model/config/mod.rs index 7566a3249..104438972 100644 --- a/shared/src/model/config/mod.rs +++ b/shared/src/model/config/mod.rs @@ -24,6 +24,7 @@ mod api_user; mod api; mod epg_smart_match; mod pattern_template; +pub mod macros; pub use base::*; pub use api::*;