fix: auto-create config directory when saving admin config
- save_admin_config_handler now creates parent directory if it doesn't exist - Prevents 500 error when config/ directory is missing - Enables first-time config save without manual directory creation
This commit is contained in:
@@ -1154,6 +1154,16 @@ async fn get_admin_config_handler() -> Response {
|
||||
|
||||
async fn save_admin_config_handler(axum::extract::Json(payload): axum::extract::Json<serde_json::Value>) -> Response {
|
||||
let config_path = get_admin_config_path();
|
||||
|
||||
// Create parent directory if it doesn't exist
|
||||
if let Some(parent) = config_path.parent() {
|
||||
if !parent.exists() {
|
||||
if let Err(e) = std::fs::create_dir_all(parent) {
|
||||
return (StatusCode::INTERNAL_SERVER_ERROR, format!("Create dir failed: {}", e)).into_response();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
match serde_json::to_string_pretty(&payload) {
|
||||
Ok(formatted) => {
|
||||
match std::fs::write(&config_path, formatted) {
|
||||
|
||||
Reference in New Issue
Block a user