diff --git a/src/core/config/mod.rs b/src/core/config/mod.rs index 24c061d1..5c634673 100644 --- a/src/core/config/mod.rs +++ b/src/core/config/mod.rs @@ -496,12 +496,35 @@ impl ConfigManager { .execute(&mut conn) .map_err(|e| format!("Failed to delete existing config: {}", e))?; + // Detect if first line is a header (has "key,value" or similar) or actual config data + let lines: Vec<&str> = content.lines().collect(); + let start_idx = if lines.is_empty() { + return Ok(0); + } else { + let first_line = lines[0].trim().to_lowercase(); + // Skip if first line looks like a header (contains "key" or is just "key,value") + if first_line == "key,value" + || first_line.starts_with("key,") + || first_line.contains("header") + { + 1 + } else { + 0 + } + }; + let mut updated = 0; - for line in content.lines().skip(1) { + for line in lines.iter().skip(start_idx) { let parts: Vec<&str> = line.splitn(2, ',').collect(); if parts.len() >= 2 { let key = parts[0].trim(); let value = parts[1].trim(); + + // Skip empty keys or lines that don't look like valid config + if key.is_empty() { + continue; + } + let new_id: uuid::Uuid = uuid::Uuid::new_v4(); diesel::sql_query("INSERT INTO bot_configuration (id, bot_id, config_key, config_value, config_type) VALUES ($1, $2, $3, $4, 'string')") .bind::(new_id) diff --git a/src/drive/drive_monitor/mod.rs b/src/drive/drive_monitor/mod.rs index 053e8cd8..e6ed71b6 100644 --- a/src/drive/drive_monitor/mod.rs +++ b/src/drive/drive_monitor/mod.rs @@ -1586,12 +1586,6 @@ impl DriveMonitor { .cloned() .collect(); - for file_path in files_to_process { - if let Err(e) = self.download_gbkb_file(client, &file_path).await { - log::error!("Failed to download .gbkb file {}: {}", file_path, e); - } - } - if files_processed > 0 { trace!( "Processed {} .gbkb files (including {} PDFs for text extraction)", @@ -1620,9 +1614,9 @@ impl DriveMonitor { } }); - for path in paths_to_remove { - trace!("Detected deletion in .gbkb: {}", path); - file_states.remove(&path); + for path in paths_to_remove { + trace!("Detected deletion in .gbkb: {}", path); + file_states.remove(&path); // Delete the downloaded file from disk let bot_name = self