Merge branch 'motion_stream'

This commit is contained in:
QuantumEntangledAndy committed 2022-11-28 10:17:08 +07:00
commit 2114af085d
17 files changed
+708 -41

No files matched your search

+51
View File
@@ -10,6 +10,7 @@ lazy_static! {
static ref RE_STREAM_SRC: Regex =
Regex::new(r"^(mainStream|subStream|externStream|both|all)$").unwrap();
static ref RE_TLS_CLIENT_AUTH: Regex = Regex::new(r"^(none|request|require)$").unwrap();
static ref RE_PAUSE_MODE: Regex = Regex::new(r"^(black|still|test|none)$").unwrap();
}
#[derive(Debug, Deserialize, Validate, Clone)]
@@ -77,6 +78,10 @@ pub(crate) struct CameraConfig {
#[validate]
#[serde(default = "default_mqtt")]
pub(crate) mqtt: Option<MqttConfig>,
#[validate]
#[serde(default = "default_pause")]
pub(crate) pause: PauseConfig,
}
#[derive(Debug, Deserialize, Validate, Clone)]
@@ -89,6 +94,7 @@ pub(crate) struct UserConfig {
pub(crate) pass: String,
}
#[derive(Debug, Deserialize, Clone, Validate)]
#[validate(schema(function = "validate_mqtt_config", skip_on_field_errors = true))]
pub(crate) struct MqttConfig {
@@ -119,6 +125,26 @@ fn validate_mqtt_config(config: &MqttConfig) -> Result<(), ValidationError> {
fn default_mqtt() -> Option<MqttConfig> {
None
#[derive(Debug, Deserialize, Validate, Clone)]
pub(crate) struct PauseConfig {
#[serde(default = "default_on_motion")]
pub(crate) on_motion: bool,
#[serde(default = "default_on_disconnect")]
pub(crate) on_disconnect: bool,
#[serde(default = "default_motion_timeout", alias = "timeout")]
pub(crate) motion_timeout: f64,
#[serde(default = "default_pause_mode")]
#[validate(regex(
path = "RE_PAUSE_MODE",
message = "Incorrect pause mode",
code = "mode"
))]
pub(crate) mode: String,
}
fn default_bind_addr() -> String {
@@ -145,6 +171,31 @@ fn default_channel_id() -> u8 {
0
}
fn default_motion_timeout() -> f64 {
1.
}
fn default_on_disconnect() -> bool {
false
}
fn default_on_motion() -> bool {
false
}
fn default_pause_mode() -> String {
"none".to_string()
}
fn default_pause() -> PauseConfig {
PauseConfig {
on_motion: default_on_motion(),
on_disconnect: default_on_disconnect(),
motion_timeout: default_motion_timeout(),
mode: default_pause_mode(),
}
}
pub(crate) static RESERVED_NAMES: &[&str] = &["anyone", "anonymous"];
fn validate_username(name: &str) -> Result<(), ValidationError> {
if name.trim().is_empty() {