|
| 1 | +use serde::{Deserialize, Serialize}; |
| 2 | + |
| 3 | +#[derive(Debug, Clone, Serialize, Deserialize)] |
| 4 | +pub struct MinioConfig { |
| 5 | + pub endpoint: String, |
| 6 | + pub access_key: String, |
| 7 | + pub secret_key: String, |
| 8 | + pub region: Option<String>, |
| 9 | + pub secure: bool, |
| 10 | + pub buckets: MinioBuckets, |
| 11 | +} |
| 12 | + |
| 13 | +#[derive(Debug, Clone, Serialize, Deserialize)] |
| 14 | +pub struct MinioBuckets { |
| 15 | + pub uploads: String, |
| 16 | + pub processed: String, |
| 17 | + pub thumbnails: String, |
| 18 | + pub temp: String, |
| 19 | +} |
| 20 | + |
| 21 | +impl Default for MinioConfig { |
| 22 | + fn default() -> Self { |
| 23 | + Self { |
| 24 | + endpoint: "localhost:9000".to_string(), |
| 25 | + access_key: "minioadmin".to_string(), |
| 26 | + secret_key: "minioadmin123".to_string(), |
| 27 | + region: Some("us-east-1".to_string()), |
| 28 | + secure: false, |
| 29 | + buckets: MinioBuckets::default(), |
| 30 | + } |
| 31 | + } |
| 32 | +} |
| 33 | + |
| 34 | +impl Default for MinioBuckets { |
| 35 | + fn default() -> Self { |
| 36 | + Self { |
| 37 | + uploads: "uploads".to_string(), |
| 38 | + processed: "processed".to_string(), |
| 39 | + thumbnails: "thumbnails".to_string(), |
| 40 | + temp: "temp".to_string(), |
| 41 | + } |
| 42 | + } |
| 43 | +} |
| 44 | + |
| 45 | +impl MinioConfig { |
| 46 | + pub fn from_env() -> Self { |
| 47 | + Self { |
| 48 | + endpoint: std::env::var("MINIO_ENDPOINT").unwrap_or_else(|_| "localhost:9000".to_string()), |
| 49 | + access_key: std::env::var("MINIO_ACCESS_KEY").unwrap_or_else(|_| "minioadmin".to_string()), |
| 50 | + secret_key: std::env::var("MINIO_SECRET_KEY").unwrap_or_else(|_| "minioadmin123".to_string()), |
| 51 | + region: std::env::var("MINIO_REGION").ok(), |
| 52 | + secure: std::env::var("MINIO_SECURE").unwrap_or_else(|_| "false".to_string()).parse().unwrap_or(false), |
| 53 | + buckets: MinioBuckets { |
| 54 | + uploads: std::env::var("MINIO_BUCKET_UPLOADS").unwrap_or_else(|_| "uploads".to_string()), |
| 55 | + processed: std::env::var("MINIO_BUCKET_PROCESSED").unwrap_or_else(|_| "processed".to_string()), |
| 56 | + thumbnails: std::env::var("MINIO_BUCKET_THUMBNAILS").unwrap_or_else(|_| "thumbnails".to_string()), |
| 57 | + temp: std::env::var("MINIO_BUCKET_TEMP").unwrap_or_else(|_| "temp".to_string()), |
| 58 | + }, |
| 59 | + } |
| 60 | + } |
| 61 | +} |
0 commit comments