feat: add image upload for avatar and banner
This commit is contained in:
@@ -11,6 +11,18 @@ pub struct Config {
|
||||
pub host: String,
|
||||
pub cors_origins: String,
|
||||
pub rate_limit: Option<u32>,
|
||||
// Storage
|
||||
pub storage_backend: String,
|
||||
pub storage_path: Option<String>,
|
||||
pub storage_prefix: String,
|
||||
pub s3_endpoint: Option<String>,
|
||||
pub s3_access_key_id: Option<String>,
|
||||
pub s3_secret_access_key: Option<String>,
|
||||
pub s3_bucket: Option<String>,
|
||||
pub s3_region: Option<String>,
|
||||
// Upload limits
|
||||
pub upload_max_bytes: usize,
|
||||
pub upload_allowed_types: Vec<String>,
|
||||
}
|
||||
|
||||
impl Config {
|
||||
@@ -36,6 +48,23 @@ impl Config {
|
||||
rate_limit: std::env::var("RATE_LIMIT")
|
||||
.ok()
|
||||
.and_then(|v| v.parse().ok()),
|
||||
storage_backend: std::env::var("STORAGE_BACKEND").unwrap_or_else(|_| "local".into()),
|
||||
storage_path: std::env::var("STORAGE_PATH").ok(),
|
||||
storage_prefix: std::env::var("STORAGE_PREFIX").unwrap_or_default(),
|
||||
s3_endpoint: std::env::var("S3_ENDPOINT").ok(),
|
||||
s3_access_key_id: std::env::var("S3_ACCESS_KEY_ID").ok(),
|
||||
s3_secret_access_key: std::env::var("S3_SECRET_ACCESS_KEY").ok(),
|
||||
s3_bucket: std::env::var("S3_BUCKET").ok(),
|
||||
s3_region: std::env::var("S3_REGION").ok(),
|
||||
upload_max_bytes: std::env::var("UPLOAD_MAX_BYTES")
|
||||
.ok()
|
||||
.and_then(|v| v.parse().ok())
|
||||
.unwrap_or(5 * 1024 * 1024),
|
||||
upload_allowed_types: std::env::var("UPLOAD_ALLOWED_TYPES")
|
||||
.unwrap_or_else(|_| "image/jpeg,image/png,image/gif,image/webp,image/avif".into())
|
||||
.split(',')
|
||||
.map(|s| s.trim().to_string())
|
||||
.collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user