2022-03-28 00:10:06 +00:00
|
|
|
use crate::{
|
2022-10-01 00:38:11 +00:00
|
|
|
config::primitives::{LogFormat, Targets, VideoCodec},
|
2022-03-28 00:10:06 +00:00
|
|
|
serde_str::Serde,
|
|
|
|
};
|
|
|
|
use std::{net::SocketAddr, path::PathBuf};
|
|
|
|
|
2022-03-28 04:27:07 +00:00
|
|
|
#[derive(Clone, Debug, Default, serde::Serialize)]
|
|
|
|
#[serde(rename_all = "snake_case")]
|
2022-03-28 00:10:06 +00:00
|
|
|
pub(crate) struct Defaults {
|
|
|
|
server: ServerDefaults,
|
|
|
|
tracing: TracingDefaults,
|
|
|
|
old_db: OldDbDefaults,
|
|
|
|
media: MediaDefaults,
|
|
|
|
repo: RepoDefaults,
|
|
|
|
store: StoreDefaults,
|
|
|
|
}
|
|
|
|
|
2022-03-28 04:27:07 +00:00
|
|
|
#[derive(Clone, Debug, serde::Serialize)]
|
|
|
|
#[serde(rename_all = "snake_case")]
|
2022-03-28 00:10:06 +00:00
|
|
|
struct ServerDefaults {
|
|
|
|
address: SocketAddr,
|
2022-03-29 17:51:16 +00:00
|
|
|
worker_id: String,
|
2023-06-23 16:20:20 +00:00
|
|
|
client_pool_size: usize,
|
2022-03-28 00:10:06 +00:00
|
|
|
}
|
|
|
|
|
2022-03-28 04:27:07 +00:00
|
|
|
#[derive(Clone, Debug, Default, serde::Serialize)]
|
|
|
|
#[serde(rename_all = "snake_case")]
|
2022-03-28 00:10:06 +00:00
|
|
|
struct TracingDefaults {
|
|
|
|
logging: LoggingDefaults,
|
|
|
|
|
|
|
|
console: ConsoleDefaults,
|
2022-03-28 04:27:07 +00:00
|
|
|
|
|
|
|
opentelemetry: OpenTelemetryDefaults,
|
2022-03-28 00:10:06 +00:00
|
|
|
}
|
|
|
|
|
2022-03-28 04:27:07 +00:00
|
|
|
#[derive(Clone, Debug, serde::Serialize)]
|
|
|
|
#[serde(rename_all = "snake_case")]
|
2022-03-28 00:10:06 +00:00
|
|
|
struct LoggingDefaults {
|
|
|
|
format: LogFormat,
|
|
|
|
targets: Serde<Targets>,
|
|
|
|
}
|
|
|
|
|
2022-03-28 04:27:07 +00:00
|
|
|
#[derive(Clone, Debug, serde::Serialize)]
|
|
|
|
#[serde(rename_all = "snake_case")]
|
2022-03-28 00:10:06 +00:00
|
|
|
struct ConsoleDefaults {
|
|
|
|
buffer_capacity: usize,
|
|
|
|
}
|
|
|
|
|
2022-03-28 04:27:07 +00:00
|
|
|
#[derive(Clone, Debug, serde::Serialize)]
|
|
|
|
#[serde(rename_all = "snake_case")]
|
|
|
|
struct OpenTelemetryDefaults {
|
|
|
|
service_name: String,
|
|
|
|
targets: Serde<Targets>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Debug, serde::Serialize)]
|
|
|
|
#[serde(rename_all = "snake_case")]
|
2022-03-28 00:10:06 +00:00
|
|
|
struct OldDbDefaults {
|
|
|
|
path: PathBuf,
|
|
|
|
}
|
|
|
|
|
2022-03-28 04:27:07 +00:00
|
|
|
#[derive(Clone, Debug, serde::Serialize)]
|
|
|
|
#[serde(rename_all = "snake_case")]
|
2022-03-28 00:10:06 +00:00
|
|
|
struct MediaDefaults {
|
|
|
|
max_width: usize,
|
|
|
|
max_height: usize,
|
|
|
|
max_area: usize,
|
|
|
|
max_file_size: usize,
|
2022-09-25 22:36:07 +00:00
|
|
|
max_frame_count: usize,
|
2023-02-04 23:32:36 +00:00
|
|
|
gif: GifDefaults,
|
2022-03-28 00:10:06 +00:00
|
|
|
enable_silent_video: bool,
|
2022-09-25 22:36:07 +00:00
|
|
|
enable_full_video: bool,
|
2022-10-01 00:38:11 +00:00
|
|
|
video_codec: VideoCodec,
|
2022-03-28 00:10:06 +00:00
|
|
|
filters: Vec<String>,
|
|
|
|
skip_validate_imports: bool,
|
|
|
|
}
|
|
|
|
|
2023-02-04 23:32:36 +00:00
|
|
|
#[derive(Clone, Debug, serde::Serialize)]
|
|
|
|
#[serde(rename_all = "snake_case")]
|
|
|
|
struct GifDefaults {
|
|
|
|
max_height: usize,
|
|
|
|
max_width: usize,
|
|
|
|
max_area: usize,
|
2023-02-04 23:52:23 +00:00
|
|
|
max_frame_count: usize,
|
2023-02-04 23:32:36 +00:00
|
|
|
}
|
|
|
|
|
2022-03-28 04:27:07 +00:00
|
|
|
#[derive(Clone, Debug, serde::Serialize)]
|
|
|
|
#[serde(rename_all = "snake_case")]
|
2022-03-28 00:10:06 +00:00
|
|
|
#[serde(tag = "type")]
|
|
|
|
enum RepoDefaults {
|
|
|
|
Sled(SledDefaults),
|
|
|
|
}
|
|
|
|
|
2022-03-28 04:27:07 +00:00
|
|
|
#[derive(Clone, Debug, serde::Serialize)]
|
|
|
|
#[serde(rename_all = "snake_case")]
|
2022-03-28 00:10:06 +00:00
|
|
|
struct SledDefaults {
|
|
|
|
path: PathBuf,
|
|
|
|
cache_capacity: u64,
|
2023-07-08 22:35:57 +00:00
|
|
|
export_path: PathBuf,
|
2022-03-28 00:10:06 +00:00
|
|
|
}
|
|
|
|
|
2022-03-28 04:27:07 +00:00
|
|
|
#[derive(Clone, Debug, serde::Serialize)]
|
|
|
|
#[serde(rename_all = "snake_case")]
|
2022-03-28 00:10:06 +00:00
|
|
|
#[serde(tag = "type")]
|
2023-06-19 20:04:36 +00:00
|
|
|
pub(super) enum StoreDefaults {
|
2022-03-28 00:10:06 +00:00
|
|
|
Filesystem(FilesystemDefaults),
|
|
|
|
}
|
|
|
|
|
2022-03-28 04:27:07 +00:00
|
|
|
#[derive(Clone, Debug, serde::Serialize)]
|
|
|
|
#[serde(rename_all = "snake_case")]
|
2023-06-19 20:04:36 +00:00
|
|
|
pub(super) struct FilesystemDefaults {
|
2022-03-28 00:10:06 +00:00
|
|
|
path: PathBuf,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for ServerDefaults {
|
|
|
|
fn default() -> Self {
|
|
|
|
ServerDefaults {
|
|
|
|
address: "0.0.0.0:8080".parse().expect("Valid address string"),
|
2022-03-29 17:51:16 +00:00
|
|
|
worker_id: String::from("pict-rs-1"),
|
2023-06-23 16:20:20 +00:00
|
|
|
client_pool_size: 100,
|
2022-03-28 00:10:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for LoggingDefaults {
|
|
|
|
fn default() -> Self {
|
|
|
|
LoggingDefaults {
|
|
|
|
format: LogFormat::Normal,
|
2022-03-28 20:34:36 +00:00
|
|
|
targets: "warn,tracing_actix_web=info,actix_web=info,actix_server=info"
|
|
|
|
.parse()
|
|
|
|
.expect("Valid targets string"),
|
2022-03-28 00:10:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for ConsoleDefaults {
|
|
|
|
fn default() -> Self {
|
|
|
|
ConsoleDefaults {
|
|
|
|
buffer_capacity: 1024 * 100,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-28 04:27:07 +00:00
|
|
|
impl Default for OpenTelemetryDefaults {
|
|
|
|
fn default() -> Self {
|
|
|
|
OpenTelemetryDefaults {
|
|
|
|
service_name: String::from("pict-rs"),
|
|
|
|
targets: "info".parse().expect("Valid targets string"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-28 00:10:06 +00:00
|
|
|
impl Default for OldDbDefaults {
|
|
|
|
fn default() -> Self {
|
|
|
|
OldDbDefaults {
|
|
|
|
path: PathBuf::from(String::from("/mnt")),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for MediaDefaults {
|
|
|
|
fn default() -> Self {
|
|
|
|
MediaDefaults {
|
|
|
|
max_width: 10_000,
|
|
|
|
max_height: 10_000,
|
|
|
|
max_area: 40_000_000,
|
|
|
|
max_file_size: 40,
|
2022-09-25 23:16:37 +00:00
|
|
|
max_frame_count: 900,
|
2023-02-04 23:32:36 +00:00
|
|
|
gif: Default::default(),
|
2022-03-28 00:10:06 +00:00
|
|
|
enable_silent_video: true,
|
2022-09-25 22:36:07 +00:00
|
|
|
enable_full_video: false,
|
2022-10-01 15:17:32 +00:00
|
|
|
video_codec: VideoCodec::Vp9,
|
2022-03-28 00:10:06 +00:00
|
|
|
filters: vec![
|
2022-04-06 01:29:30 +00:00
|
|
|
"blur".into(),
|
|
|
|
"crop".into(),
|
2022-03-28 00:10:06 +00:00
|
|
|
"identity".into(),
|
|
|
|
"resize".into(),
|
2022-04-06 01:29:30 +00:00
|
|
|
"thumbnail".into(),
|
2022-03-28 00:10:06 +00:00
|
|
|
],
|
|
|
|
skip_validate_imports: false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-04 23:32:36 +00:00
|
|
|
impl Default for GifDefaults {
|
|
|
|
fn default() -> Self {
|
|
|
|
GifDefaults {
|
|
|
|
max_height: 128,
|
|
|
|
max_width: 128,
|
|
|
|
max_area: 16384,
|
2023-02-04 23:52:23 +00:00
|
|
|
max_frame_count: 100,
|
2023-02-04 23:32:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-28 00:10:06 +00:00
|
|
|
impl Default for RepoDefaults {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self::Sled(SledDefaults::default())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for SledDefaults {
|
|
|
|
fn default() -> Self {
|
|
|
|
SledDefaults {
|
|
|
|
path: PathBuf::from(String::from("/mnt/sled-repo")),
|
|
|
|
cache_capacity: 1024 * 1024 * 64,
|
2023-07-08 22:35:57 +00:00
|
|
|
export_path: PathBuf::from(String::from("/mnt/exports")),
|
2022-03-28 00:10:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for StoreDefaults {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self::Filesystem(FilesystemDefaults::default())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for FilesystemDefaults {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
|
|
|
path: PathBuf::from(String::from("/mnt/files")),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-06-19 20:04:36 +00:00
|
|
|
|
|
|
|
impl From<crate::config::commandline::Filesystem> for crate::config::primitives::Filesystem {
|
|
|
|
fn from(value: crate::config::commandline::Filesystem) -> Self {
|
|
|
|
Self {
|
|
|
|
path: value
|
|
|
|
.path
|
|
|
|
.unwrap_or_else(|| FilesystemDefaults::default().path),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<crate::config::commandline::Filesystem> for crate::config::primitives::Store {
|
|
|
|
fn from(value: crate::config::commandline::Filesystem) -> Self {
|
|
|
|
crate::config::primitives::Store::Filesystem(value.into())
|
|
|
|
}
|
|
|
|
}
|