diff --git a/ffplayout-engine/src/rpc/server.rs b/ffplayout-engine/src/rpc/server.rs index de31e1ad..e79ce71c 100644 --- a/ffplayout-engine/src/rpc/server.rs +++ b/ffplayout-engine/src/rpc/server.rs @@ -18,20 +18,47 @@ use ffplayout_lib::utils::{ PlayoutConfig, PlayoutStatus, ProcessControl, }; -#[derive(Default, Deserialize, Clone)] +#[derive(Default, Deserialize, Clone, Debug)] struct TextFilter { text: Option, + #[serde(default, deserialize_with = "deserialize_number_or_string")] x: Option, + #[serde(default, deserialize_with = "deserialize_number_or_string")] y: Option, + #[serde(default, deserialize_with = "deserialize_number_or_string")] fontsize: Option, + #[serde(default, deserialize_with = "deserialize_number_or_string")] line_spacing: Option, fontcolor: Option, + #[serde(default, deserialize_with = "deserialize_number_or_string")] alpha: Option, + #[serde(default, deserialize_with = "deserialize_number_or_string")] r#box: Option, boxcolor: Option, + #[serde(default, deserialize_with = "deserialize_number_or_string")] boxborderw: Option, } +fn deserialize_number_or_string<'de, D>(deserializer: D) -> Result, D::Error> +where + D: serde::Deserializer<'de>, +{ + let value: Value = Deserialize::deserialize(deserializer)?; + match value { + Value::Number(num) => { + if let Some(number) = num.as_i64() { + Ok(Some(number.to_string())) + } else if let Some(number) = num.as_f64() { + Ok(Some(number.to_string())) + } else { + Err(serde::de::Error::custom("Invalid number format")) + } + } + Value::String(string) => Ok(Some(string)), + _ => Err(serde::de::Error::custom("Invalid value type")), + } +} + impl fmt::Display for TextFilter { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let escaped_text = self