pict-rs/src/config/file.rs

147 lines
3.7 KiB
Rust
Raw Normal View History

2022-03-28 00:10:06 +00:00
use crate::{
config::primitives::{AudioCodec, ImageFormat, LogFormat, Store, Targets, VideoCodec},
2022-03-28 00:10:06 +00:00
serde_str::Serde,
};
use once_cell::sync::OnceCell;
2022-03-29 01:47:46 +00:00
use std::{collections::BTreeSet, net::SocketAddr, path::PathBuf};
2022-03-28 00:10:06 +00:00
use url::Url;
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
2022-03-28 04:27:07 +00:00
#[serde(rename_all = "snake_case")]
2022-03-28 00:10:06 +00:00
pub(crate) struct ConfigFile {
pub(crate) server: Server,
pub(crate) tracing: Tracing,
2022-03-28 04:27:07 +00:00
pub(crate) old_db: OldDb,
2022-03-28 00:10:06 +00:00
pub(crate) media: Media,
pub(crate) repo: Repo,
pub(crate) store: Store,
}
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
2022-03-28 04:27:07 +00:00
#[serde(rename_all = "snake_case")]
2022-03-28 00:10:06 +00:00
#[serde(tag = "type")]
pub(crate) enum Repo {
Sled(Sled),
}
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
2022-03-28 04:27:07 +00:00
#[serde(rename_all = "snake_case")]
2022-03-28 00:10:06 +00:00
pub(crate) struct Server {
pub(crate) address: SocketAddr,
pub(crate) worker_id: String,
2022-03-28 00:10:06 +00:00
#[serde(skip_serializing_if = "Option::is_none")]
pub(crate) api_key: Option<String>,
}
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
2022-03-28 04:27:07 +00:00
#[serde(rename_all = "snake_case")]
2022-03-28 00:10:06 +00:00
pub(crate) struct Tracing {
2022-03-28 04:27:07 +00:00
pub(crate) logging: Logging,
2022-03-28 00:10:06 +00:00
2022-03-28 04:27:07 +00:00
pub(crate) console: Console,
2022-03-28 00:10:06 +00:00
2022-03-28 04:27:07 +00:00
pub(crate) opentelemetry: OpenTelemetry,
2022-03-28 00:10:06 +00:00
}
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
2022-03-28 04:27:07 +00:00
#[serde(rename_all = "snake_case")]
2022-03-28 00:10:06 +00:00
pub(crate) struct Logging {
pub(crate) format: LogFormat,
pub(crate) targets: Serde<Targets>,
}
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
2022-03-28 04:27:07 +00:00
#[serde(rename_all = "snake_case")]
2022-03-28 00:10:06 +00:00
pub(crate) struct OpenTelemetry {
2022-03-28 04:27:07 +00:00
#[serde(skip_serializing_if = "Option::is_none")]
pub(crate) url: Option<Url>,
2022-03-28 00:10:06 +00:00
pub(crate) service_name: String,
pub(crate) targets: Serde<Targets>,
}
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
2022-03-28 04:27:07 +00:00
#[serde(rename_all = "snake_case")]
2022-03-28 00:10:06 +00:00
pub(crate) struct Console {
2022-03-28 04:27:07 +00:00
#[serde(skip_serializing_if = "Option::is_none")]
pub(crate) address: Option<SocketAddr>,
2022-03-28 00:10:06 +00:00
pub(crate) buffer_capacity: usize,
}
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
2022-03-28 04:27:07 +00:00
#[serde(rename_all = "snake_case")]
2022-03-28 00:10:06 +00:00
pub(crate) struct OldDb {
pub(crate) path: PathBuf,
}
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
2022-03-28 04:27:07 +00:00
#[serde(rename_all = "snake_case")]
2022-03-28 00:10:06 +00:00
pub(crate) struct Media {
#[serde(skip_serializing_if = "Option::is_none")]
pub(crate) preprocess_steps: Option<String>,
2022-03-28 00:10:06 +00:00
pub(crate) max_width: usize,
pub(crate) max_height: usize,
pub(crate) max_area: usize,
pub(crate) max_file_size: usize,
2022-09-25 22:36:07 +00:00
pub(crate) max_frame_count: usize,
2022-03-28 00:10:06 +00:00
pub(crate) enable_silent_video: bool,
2022-09-25 22:36:07 +00:00
pub(crate) enable_full_video: bool,
pub(crate) video_codec: VideoCodec,
pub(crate) audio_codec: Option<AudioCodec>,
2022-03-29 01:47:46 +00:00
pub(crate) filters: BTreeSet<String>,
2022-03-28 00:10:06 +00:00
#[serde(skip_serializing_if = "Option::is_none")]
pub(crate) format: Option<ImageFormat>,
pub(crate) skip_validate_imports: bool,
pub(crate) cache_duration: i64,
2022-03-28 00:10:06 +00:00
}
impl Media {
pub(crate) fn preprocess_steps(&self) -> Option<&[(String, String)]> {
static PREPROCESS_STEPS: OnceCell<Vec<(String, String)>> = OnceCell::new();
if let Some(steps) = &self.preprocess_steps {
let steps = PREPROCESS_STEPS
.get_or_try_init(|| {
serde_urlencoded::from_str(steps) as Result<Vec<(String, String)>, _>
})
.expect("Invalid preprocess_steps configuration")
.as_slice();
Some(steps)
} else {
None
}
}
}
2022-03-28 00:10:06 +00:00
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
2022-03-28 04:27:07 +00:00
#[serde(rename_all = "snake_case")]
2022-03-28 00:10:06 +00:00
pub(crate) struct Sled {
pub(crate) path: PathBuf,
pub(crate) cache_capacity: u64,
}