breeze/src/config.rs

102 lines
2.9 KiB
Rust
Raw Normal View History

use std::{path::PathBuf, time::Duration};
use serde::Deserialize;
use serde_with::{serde_as, DisplayFromStr, DurationSeconds};
use tracing_subscriber::filter::LevelFilter;
#[derive(Deserialize)]
pub struct Config {
pub engine: EngineConfig,
2023-12-07 12:31:27 -06:00
pub http: HttpConfig,
pub logger: LoggerConfig,
}
fn default_motd() -> String {
"breeze file server (v%version%) - currently hosting %uplcount% files".to_string()
}
2024-05-25 00:21:36 -05:00
#[serde_as]
#[derive(Deserialize)]
pub struct EngineConfig {
/// The url that the instance of breeze is meant to be accessed from.
///
/// ex: https://picture.wtf would generate links like https://picture.wtf/p/abcdef.png
pub base_url: String,
/// Authentication key for new uploads, will be required if this is specified. (optional)
2023-12-07 12:31:27 -06:00
#[serde(default)]
pub upload_key: String,
2024-05-25 00:21:36 -05:00
/// Configuration for disk system
pub disk: DiskConfig,
2023-12-07 12:31:27 -06:00
/// Configuration for cache system
pub cache: CacheConfig,
2024-07-13 22:10:52 -05:00
/// Maximum size of an upload that will be accepted.
/// Files above this size can not be uploaded.
pub max_upload_len: Option<usize>,
2024-05-25 00:21:36 -05:00
/// Maximum lifetime of a temporary upload
#[serde_as(as = "DurationSeconds")]
pub max_temp_lifetime: Duration,
2024-05-27 12:12:18 -05:00
/// Maximum length (in bytes) a file can be before the server will
/// decide not to remove its EXIF data.
pub max_strip_len: usize,
2023-12-07 12:31:27 -06:00
/// Motd displayed when the server's index page is visited.
2024-01-12 23:49:26 -06:00
///
2023-12-07 12:31:27 -06:00
/// This isn't explicitly engine-related but the engine is what gets passed to routes,
/// so it is here for now.
#[serde(default = "default_motd")]
pub motd: String,
}
2024-05-25 00:21:36 -05:00
#[derive(Deserialize, Clone)]
pub struct DiskConfig {
/// Location on disk the uploads are to be saved to
pub save_path: PathBuf,
}
#[serde_as]
2024-05-25 00:21:36 -05:00
#[derive(Deserialize, Clone)]
pub struct CacheConfig {
/// The maximum length in bytes that a file can be
/// before it skips cache (in seconds)
pub max_length: usize,
/// The amount of time a file can last inside the cache (in seconds)
#[serde_as(as = "DurationSeconds")]
pub upload_lifetime: Duration,
/// How often the cache is to be scanned for
/// expired entries (in seconds)
#[serde_as(as = "DurationSeconds")]
pub scan_freq: Duration,
/// How much memory the cache is allowed to use (in bytes)
pub mem_capacity: usize,
}
2023-12-07 12:31:27 -06:00
#[derive(Deserialize)]
pub struct HttpConfig {
2024-05-27 12:12:18 -05:00
/// The IP address the HTTP server should listen on
2023-12-07 12:31:27 -06:00
pub listen_on: String,
}
fn default_level_filter() -> LevelFilter {
LevelFilter::WARN
}
#[serde_as]
#[derive(Deserialize)]
pub struct LoggerConfig {
/// Minimum level a log must be for it to be shown.
/// This defaults to "warn" if not specified.
2023-12-07 12:31:27 -06:00
#[serde_as(as = "DisplayFromStr")]
// yes... kind of a hack but serde doesn't have anything better
2024-01-12 23:49:26 -06:00
#[serde(default = "default_level_filter")]
2023-12-07 12:31:27 -06:00
pub level: LevelFilter,
}