feat(config): add drive config persistence to .env file
Added functionality to write drive configuration (MinIO settings) to a .env file when the AppConfig is created. The new write_drive_config_to_env function handles the file operations and logs warnings if the write fails. This change ensures drive configuration is persisted for future use while maintaining backward compatibility.
This commit is contained in:
parent
31d65bcfd9
commit
f18b35d5b6
1 changed files with 23 additions and 0 deletions
|
|
@ -3,6 +3,8 @@ use diesel::sql_types::Text;
|
|||
use log::{info, warn};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::HashMap;
|
||||
use std::fs::OpenOptions;
|
||||
use std::io::Write;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
|
|
@ -223,6 +225,11 @@ impl AppConfig {
|
|||
endpoint: get_str("AI_ENDPOINT", "https://api.openai.com"),
|
||||
};
|
||||
|
||||
// Write drive config to .env file
|
||||
if let Err(e) = write_drive_config_to_env(&minio) {
|
||||
warn!("Failed to write drive config to .env: {}", e);
|
||||
}
|
||||
|
||||
AppConfig {
|
||||
drive: minio,
|
||||
server: ServerConfig {
|
||||
|
|
@ -374,6 +381,22 @@ impl AppConfig {
|
|||
}
|
||||
}
|
||||
|
||||
fn write_drive_config_to_env(drive: &DriveConfig) -> std::io::Result<()> {
|
||||
let mut file = OpenOptions::new()
|
||||
.append(true)
|
||||
.create(true)
|
||||
.open(".env")?;
|
||||
|
||||
writeln!(file,"")?;
|
||||
writeln!(file, "DRIVE_SERVER={}", drive.server)?;
|
||||
writeln!(file, "DRIVE_ACCESSKEY={}", drive.access_key)?;
|
||||
writeln!(file, "DRIVE_SECRET={}", drive.secret_key)?;
|
||||
writeln!(file, "DRIVE_USE_SSL={}", drive.use_ssl)?;
|
||||
writeln!(file, "DRIVE_ORG_PREFIX={}", drive.org_prefix)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn parse_database_url(url: &str) -> (String, String, String, u32, String) {
|
||||
if let Some(stripped) = url.strip_prefix("postgres://") {
|
||||
let parts: Vec<&str> = stripped.split('@').collect();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue