fix: sync_gbot_config now handles CSV with or without header row
All checks were successful
BotServer CI/CD / build (push) Successful in 3m32s

- Removed unconditional .skip(1) that was skipping first config line
- Added header detection: skips first line only if it looks like 'key,value' header
- Added validation to skip empty keys
- Also fixed indentation in drive_monitor gbkb file processing

This fixes the issue where config.csv changes on Drive weren't being
synced to bot_configuration database table for salesianos bot.

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
Rodrigo Rodriguez (Pragmatismo) 2026-04-12 20:32:30 -03:00
parent 4cd469afc3
commit 36fdf52780
2 changed files with 27 additions and 10 deletions

View file

@ -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::<diesel::sql_types::Uuid, _>(new_id)

View file

@ -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