use std::env; use async_std::{fs, path::PathBuf}; #[derive(Clone)] pub struct Config { pub files_dir: PathBuf, pub max_file_size: Option, } pub async fn get_config() -> Config { let max_file_size = env::var("UPLOAD_MAX_BYTES") .ok() .and_then(|variable| variable.parse().ok()) .unwrap_or(8 * 1024 * 1024); let max_file_size = (max_file_size != 0).then(|| max_file_size); let files_dir = PathBuf::from(env::var("FILES_DIR").unwrap_or_else(|_| "./files".to_owned())); fs::create_dir_all(&files_dir) .await .expect("could not create directory for storing files"); Config { files_dir, max_file_size, } }