feat: Update configuration handling and add debug logging for thumbnail processing
This commit is contained in:
@@ -2,27 +2,28 @@ use serde::Deserialize;
|
||||
|
||||
use crate::error::{CoreError, CoreResult};
|
||||
|
||||
#[derive(Deserialize, Clone)]
|
||||
#[derive(Deserialize, Clone, Debug)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum DatabaseType {
|
||||
Postgres,
|
||||
Sqlite,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Clone)]
|
||||
#[derive(Deserialize, Clone, Debug)]
|
||||
pub struct DatabaseConfig {
|
||||
pub db_type: DatabaseType,
|
||||
pub url: String,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Clone)]
|
||||
|
||||
#[derive(Deserialize, Clone, Debug)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum ThumbnailFormat {
|
||||
Jpeg,
|
||||
Webp,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Clone)]
|
||||
#[derive(Deserialize, Clone, Debug)]
|
||||
pub struct ThumbnailConfig {
|
||||
pub format: ThumbnailFormat,
|
||||
pub quality: u8,
|
||||
@@ -31,7 +32,7 @@ pub struct ThumbnailConfig {
|
||||
pub library_path: String,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Clone)]
|
||||
#[derive(Deserialize, Clone, Debug)]
|
||||
pub struct Config {
|
||||
pub database_url: String,
|
||||
pub database_db_type: DatabaseType,
|
||||
@@ -49,7 +50,6 @@ pub struct Config {
|
||||
#[serde(default = "default_allowed_sort_columns")]
|
||||
pub allowed_sort_columns: Vec<String>,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub thumbnail_config: Option<ThumbnailConfig>,
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ fn default_allowed_sort_columns() -> Vec<String> {
|
||||
vec!["created_at".to_string(), "original_filename".to_string()]
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct AppConfig {
|
||||
pub database: DatabaseConfig,
|
||||
pub server_address: String,
|
||||
@@ -73,14 +73,25 @@ pub struct AppConfig {
|
||||
}
|
||||
|
||||
pub fn load_config() -> CoreResult<AppConfig> {
|
||||
// Load the .env file at that specific path
|
||||
let env_path = dotenvy::dotenv()
|
||||
let env_path = dotenvy::dotenv()
|
||||
.map_err(|e| CoreError::Config(format!("Failed to load .env file: {}", e)))?;
|
||||
|
||||
println!("Loaded config from {}", env_path.display());
|
||||
|
||||
let config = envy::from_env::<Config>()
|
||||
.map_err(|e| CoreError::Config(format!("Failed to load config from env: {}", e)))?;
|
||||
let config = config::Config::builder()
|
||||
.add_source(config::Environment::default()
|
||||
.with_list_parse_key("allowed_sort_columns")
|
||||
.list_separator(",")
|
||||
.try_parsing(true)
|
||||
.separator("__")
|
||||
)
|
||||
.build()
|
||||
.map_err(|e| CoreError::Config(format!("Failed to build config: {}", e)))?;
|
||||
|
||||
let config: Config = config
|
||||
.try_deserialize()
|
||||
.map_err(|e| CoreError::Config(format!("Failed to deserialize config: {}", e)))?;
|
||||
println!("Built config from environment variables. Contents: {:?}", config);
|
||||
|
||||
|
||||
Ok(AppConfig {
|
||||
database: DatabaseConfig {
|
||||
|
||||
Reference in New Issue
Block a user