2023-11-09 20:22:02 -06:00
|
|
|
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,
|
2023-11-09 20:22:02 -06:00
|
|
|
pub logger: LoggerConfig,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[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,
|
|
|
|
|
|
|
|
/// Location on disk the uploads are to be saved to
|
|
|
|
pub save_path: PathBuf,
|
|
|
|
|
|
|
|
/// 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,
|
|
|
|
|
|
|
|
/// Configuration for cache system
|
|
|
|
pub cache: CacheConfig,
|
|
|
|
|
|
|
|
/// Motd displayed when the server's index page is visited.
|
|
|
|
///
|
|
|
|
/// 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,
|
2023-11-09 20:22:02 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
#[serde_as]
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
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
|
|
|
fn default_motd() -> String {
|
|
|
|
"breeze file server (v%version%) - currently hosting %uplcount% files".to_string()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
pub struct HttpConfig {
|
|
|
|
pub listen_on: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
fn default_level_filter() -> LevelFilter {
|
|
|
|
LevelFilter::WARN
|
|
|
|
}
|
|
|
|
|
2023-11-09 20:22:02 -06:00
|
|
|
#[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")]
|
|
|
|
#[serde(default = "default_level_filter")]
|
|
|
|
// yes... kind of a hack but serde doesn't have anything better
|
|
|
|
pub level: LevelFilter,
|
2023-11-09 20:22:02 -06:00
|
|
|
}
|