2022-03-28 00:10:06 +00:00
|
|
|
use crate::{
|
2023-07-13 22:42:21 +00:00
|
|
|
config::primitives::{LogFormat, Targets},
|
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,
|
2023-07-17 18:44:31 +00:00
|
|
|
client: ClientDefaults,
|
2023-10-03 21:27:19 +00:00
|
|
|
upgrade: UpgradeDefaults,
|
2022-03-28 00:10:06 +00:00
|
|
|
tracing: TracingDefaults,
|
|
|
|
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,
|
2023-07-17 19:24:49 +00:00
|
|
|
read_only: bool,
|
2023-11-11 20:22:12 +00:00
|
|
|
danger_dummy_mode: bool,
|
2023-07-19 01:32:17 +00:00
|
|
|
max_file_count: u32,
|
2023-11-24 17:48:45 +00:00
|
|
|
temporary_directory: PathBuf,
|
2023-07-17 18:44:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Debug, serde::Serialize)]
|
|
|
|
#[serde(rename_all = "snake_case")]
|
|
|
|
struct ClientDefaults {
|
|
|
|
timeout: u64,
|
2022-03-28 00:10:06 +00:00
|
|
|
}
|
|
|
|
|
2023-10-03 21:27:19 +00:00
|
|
|
#[derive(Clone, Debug, serde::Serialize)]
|
|
|
|
#[serde(rename_all = "snake_case")]
|
|
|
|
struct UpgradeDefaults {
|
|
|
|
concurrency: usize,
|
|
|
|
}
|
|
|
|
|
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>,
|
2023-12-11 20:58:53 +00:00
|
|
|
log_spans: bool,
|
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 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 MediaDefaults {
|
2023-09-21 00:22:49 +00:00
|
|
|
external_validation_timeout: u64,
|
2022-03-28 00:10:06 +00:00
|
|
|
max_file_size: usize,
|
2023-08-05 17:41:06 +00:00
|
|
|
process_timeout: u64,
|
2022-03-28 00:10:06 +00:00
|
|
|
filters: Vec<String>,
|
2023-07-22 23:37:25 +00:00
|
|
|
retention: RetentionDefaults,
|
2023-07-13 22:42:21 +00:00
|
|
|
image: ImageDefaults,
|
|
|
|
animation: AnimationDefaults,
|
|
|
|
video: VideoDefaults,
|
|
|
|
}
|
|
|
|
|
2023-07-22 23:37:25 +00:00
|
|
|
#[derive(Clone, Debug, serde::Serialize)]
|
|
|
|
#[serde(rename_all = "snake_case")]
|
|
|
|
struct RetentionDefaults {
|
|
|
|
variants: &'static str,
|
|
|
|
proxy: &'static str,
|
|
|
|
}
|
|
|
|
|
2023-07-13 22:42:21 +00:00
|
|
|
#[derive(Clone, Debug, serde::Serialize)]
|
|
|
|
#[serde(rename_all = "snake_case")]
|
|
|
|
struct ImageDefaults {
|
|
|
|
max_width: u16,
|
|
|
|
max_height: u16,
|
|
|
|
max_area: u32,
|
|
|
|
max_file_size: usize,
|
2023-07-17 22:45:26 +00:00
|
|
|
quality: ImageQualityDefaults,
|
2023-07-13 22:42:21 +00:00
|
|
|
}
|
|
|
|
|
2023-07-17 22:45:26 +00:00
|
|
|
#[derive(Clone, Debug, Default, serde::Serialize)]
|
|
|
|
#[serde(rename_all = "snake_case")]
|
|
|
|
struct ImageQualityDefaults {}
|
|
|
|
|
2023-07-13 22:42:21 +00:00
|
|
|
#[derive(Clone, Debug, serde::Serialize)]
|
|
|
|
#[serde(rename_all = "snake_case")]
|
|
|
|
struct AnimationDefaults {
|
|
|
|
max_width: u16,
|
|
|
|
max_height: u16,
|
|
|
|
max_area: u32,
|
|
|
|
max_frame_count: u32,
|
|
|
|
max_file_size: usize,
|
2023-07-17 22:45:26 +00:00
|
|
|
quality: AnimationQualityDefaults,
|
2022-03-28 00:10:06 +00:00
|
|
|
}
|
|
|
|
|
2023-07-17 22:45:26 +00:00
|
|
|
#[derive(Clone, Debug, Default, serde::Serialize)]
|
|
|
|
#[serde(rename_all = "snake_case")]
|
|
|
|
struct AnimationQualityDefaults {}
|
|
|
|
|
2023-02-04 23:32:36 +00:00
|
|
|
#[derive(Clone, Debug, serde::Serialize)]
|
|
|
|
#[serde(rename_all = "snake_case")]
|
2023-07-13 22:42:21 +00:00
|
|
|
struct VideoDefaults {
|
|
|
|
enable: bool,
|
|
|
|
allow_audio: bool,
|
|
|
|
max_height: u16,
|
|
|
|
max_width: u16,
|
|
|
|
max_area: u32,
|
|
|
|
max_frame_count: u32,
|
|
|
|
max_file_size: usize,
|
2023-07-17 22:45:26 +00:00
|
|
|
quality: VideoQualityDefaults,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Debug, serde::Serialize)]
|
|
|
|
#[serde(rename_all = "snake_case")]
|
|
|
|
struct VideoQualityDefaults {
|
|
|
|
crf_max: u8,
|
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")]
|
2023-10-01 03:43:40 +00:00
|
|
|
pub(super) struct SledDefaults {
|
2022-03-28 00:10:06 +00:00
|
|
|
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")]
|
2023-07-11 18:01:58 +00:00
|
|
|
pub(super) struct StoreDefaults {
|
|
|
|
#[serde(rename = "type")]
|
|
|
|
type_: String,
|
|
|
|
|
|
|
|
#[serde(flatten)]
|
|
|
|
pub(super) filesystem: FilesystemDefaults,
|
|
|
|
|
|
|
|
#[serde(flatten)]
|
|
|
|
pub(super) object_storage: ObjectStorageDefaults,
|
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")]
|
2023-06-19 20:04:36 +00:00
|
|
|
pub(super) struct FilesystemDefaults {
|
2022-03-28 00:10:06 +00:00
|
|
|
path: PathBuf,
|
|
|
|
}
|
|
|
|
|
2023-07-11 18:01:58 +00:00
|
|
|
#[derive(Clone, Debug, serde::Serialize)]
|
|
|
|
#[serde(rename_all = "snake_case")]
|
|
|
|
pub(super) struct ObjectStorageDefaults {
|
|
|
|
signature_duration: u64,
|
|
|
|
|
|
|
|
client_timeout: u64,
|
|
|
|
}
|
|
|
|
|
2022-03-28 00:10:06 +00:00
|
|
|
impl Default for ServerDefaults {
|
|
|
|
fn default() -> Self {
|
|
|
|
ServerDefaults {
|
|
|
|
address: "0.0.0.0:8080".parse().expect("Valid address string"),
|
2023-07-17 19:24:49 +00:00
|
|
|
read_only: false,
|
2023-11-11 20:22:12 +00:00
|
|
|
danger_dummy_mode: false,
|
2023-07-19 01:32:17 +00:00
|
|
|
max_file_count: 1,
|
2023-11-24 17:48:45 +00:00
|
|
|
temporary_directory: std::env::temp_dir(),
|
2023-07-17 18:44:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for ClientDefaults {
|
|
|
|
fn default() -> Self {
|
2023-10-01 03:43:40 +00:00
|
|
|
ClientDefaults { timeout: 30 }
|
2022-03-28 00:10:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-03 21:27:19 +00:00
|
|
|
impl Default for UpgradeDefaults {
|
|
|
|
fn default() -> Self {
|
|
|
|
UpgradeDefaults { concurrency: 32 }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-28 00:10:06 +00:00
|
|
|
impl Default for LoggingDefaults {
|
|
|
|
fn default() -> Self {
|
|
|
|
LoggingDefaults {
|
|
|
|
format: LogFormat::Normal,
|
2023-09-30 21:28:04 +00:00
|
|
|
targets: "info".parse().expect("Valid targets string"),
|
2023-12-11 20:58:53 +00:00
|
|
|
log_spans: false,
|
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 MediaDefaults {
|
|
|
|
fn default() -> Self {
|
|
|
|
MediaDefaults {
|
2023-09-21 00:22:49 +00:00
|
|
|
external_validation_timeout: 30,
|
2022-03-28 00:10:06 +00:00
|
|
|
max_file_size: 40,
|
2023-08-05 17:41:06 +00:00
|
|
|
process_timeout: 30,
|
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
|
|
|
],
|
2023-07-22 23:37:25 +00:00
|
|
|
retention: Default::default(),
|
2023-07-13 22:42:21 +00:00
|
|
|
image: Default::default(),
|
|
|
|
animation: Default::default(),
|
|
|
|
video: Default::default(),
|
2022-03-28 00:10:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-22 23:37:25 +00:00
|
|
|
impl Default for RetentionDefaults {
|
|
|
|
fn default() -> Self {
|
|
|
|
RetentionDefaults {
|
|
|
|
variants: "7d",
|
|
|
|
proxy: "7d",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-13 22:42:21 +00:00
|
|
|
impl Default for ImageDefaults {
|
2023-02-04 23:32:36 +00:00
|
|
|
fn default() -> Self {
|
2023-07-13 22:42:21 +00:00
|
|
|
ImageDefaults {
|
|
|
|
max_width: 10_000,
|
|
|
|
max_height: 10_000,
|
|
|
|
max_area: 40_000_000,
|
|
|
|
max_file_size: 40,
|
2023-07-17 22:45:26 +00:00
|
|
|
quality: ImageQualityDefaults {},
|
2023-07-13 22:42:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for AnimationDefaults {
|
|
|
|
fn default() -> Self {
|
|
|
|
AnimationDefaults {
|
2023-08-31 02:55:53 +00:00
|
|
|
max_height: 1920,
|
|
|
|
max_width: 1920,
|
|
|
|
max_area: 2_073_600,
|
|
|
|
max_frame_count: 900,
|
2023-07-13 22:42:21 +00:00
|
|
|
max_file_size: 40,
|
2023-07-17 22:45:26 +00:00
|
|
|
quality: AnimationQualityDefaults {},
|
2023-07-13 22:42:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for VideoDefaults {
|
|
|
|
fn default() -> Self {
|
|
|
|
VideoDefaults {
|
|
|
|
enable: true,
|
|
|
|
allow_audio: false,
|
|
|
|
max_height: 3_840,
|
|
|
|
max_width: 3_840,
|
|
|
|
max_area: 8_294_400,
|
|
|
|
max_frame_count: 900,
|
|
|
|
max_file_size: 40,
|
2023-07-17 22:45:26 +00:00
|
|
|
quality: VideoQualityDefaults::default(),
|
2023-02-04 23:32:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-17 22:45:26 +00:00
|
|
|
impl Default for VideoQualityDefaults {
|
|
|
|
fn default() -> Self {
|
|
|
|
VideoQualityDefaults { crf_max: 32 }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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 {
|
2023-07-11 18:01:58 +00:00
|
|
|
Self {
|
|
|
|
type_: String::from("filesystem"),
|
|
|
|
filesystem: FilesystemDefaults::default(),
|
|
|
|
object_storage: ObjectStorageDefaults::default(),
|
|
|
|
}
|
2022-03-28 00:10:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for FilesystemDefaults {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
|
|
|
path: PathBuf::from(String::from("/mnt/files")),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-06-19 20:04:36 +00:00
|
|
|
|
2023-07-11 18:01:58 +00:00
|
|
|
impl Default for ObjectStorageDefaults {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
|
|
|
signature_duration: 15,
|
|
|
|
client_timeout: 30,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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())
|
|
|
|
}
|
|
|
|
}
|
2023-08-16 21:32:19 +00:00
|
|
|
|
2023-10-01 03:43:40 +00:00
|
|
|
impl From<SledDefaults> for crate::config::file::Sled {
|
|
|
|
fn from(defaults: SledDefaults) -> Self {
|
|
|
|
crate::config::file::Sled {
|
|
|
|
path: defaults.path,
|
|
|
|
cache_capacity: defaults.cache_capacity,
|
|
|
|
export_path: defaults.export_path,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-16 21:32:19 +00:00
|
|
|
impl From<crate::config::commandline::Sled> for crate::config::file::Sled {
|
|
|
|
fn from(value: crate::config::commandline::Sled) -> Self {
|
|
|
|
let defaults = SledDefaults::default();
|
|
|
|
|
|
|
|
crate::config::file::Sled {
|
|
|
|
path: value.path.unwrap_or(defaults.path),
|
|
|
|
cache_capacity: value.cache_capacity.unwrap_or(defaults.cache_capacity),
|
|
|
|
export_path: defaults.export_path,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-02 16:52:55 +00:00
|
|
|
impl From<crate::config::commandline::Postgres> for crate::config::file::Postgres {
|
|
|
|
fn from(value: crate::config::commandline::Postgres) -> Self {
|
2024-01-15 23:11:08 +00:00
|
|
|
crate::config::file::Postgres {
|
|
|
|
url: value.url,
|
|
|
|
use_tls: value.use_tls,
|
|
|
|
certificate_file: value.certificate_file,
|
|
|
|
}
|
2023-09-02 16:52:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-16 21:32:19 +00:00
|
|
|
impl From<crate::config::commandline::Sled> for crate::config::file::Repo {
|
|
|
|
fn from(value: crate::config::commandline::Sled) -> Self {
|
|
|
|
crate::config::file::Repo::Sled(value.into())
|
|
|
|
}
|
|
|
|
}
|
2023-09-02 16:52:55 +00:00
|
|
|
|
|
|
|
impl From<crate::config::commandline::Postgres> for crate::config::file::Repo {
|
|
|
|
fn from(value: crate::config::commandline::Postgres) -> Self {
|
|
|
|
crate::config::file::Repo::Postgres(value.into())
|
|
|
|
}
|
|
|
|
}
|