feat: implement YAML-based configuration, .env support, and customizable prompt templates for AI analysis
This commit is contained in:
@@ -16,7 +16,7 @@ type targetConfig struct {
|
||||
} `yaml:"targets"`
|
||||
}
|
||||
|
||||
// LoadTargetsFromYAML reads a YAML file and inserts targets into the database if it's empty
|
||||
// LoadTargetsFromYAML reads a YAML file and inserts/syncs targets with the database
|
||||
func (db *DB) LoadTargetsFromYAML(filepath string) error {
|
||||
data, err := os.ReadFile(filepath)
|
||||
if err != nil {
|
||||
@@ -28,23 +28,29 @@ func (db *DB) LoadTargetsFromYAML(filepath string) error {
|
||||
return fmt.Errorf("could not parse target config: %w", err)
|
||||
}
|
||||
|
||||
// Get existing targets to prevent duplicates
|
||||
// Get existing targets to prevent duplicates and sync is_active if needed
|
||||
existingTargets, err := db.GetAllTargets()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
existingURLs := make(map[string]bool)
|
||||
for _, t := range existingTargets {
|
||||
existingURLs[t.TargetURL] = true
|
||||
|
||||
existingURLs := make(map[string]*SearchTarget)
|
||||
for i := range existingTargets {
|
||||
existingURLs[existingTargets[i].TargetURL] = &existingTargets[i]
|
||||
}
|
||||
|
||||
for _, t := range config.Targets {
|
||||
if !existingURLs[t.TargetURL] {
|
||||
_, err := db.CreateTarget(t.Name, t.TargetURL, t.Platform)
|
||||
existing, found := existingURLs[t.TargetURL]
|
||||
if !found {
|
||||
_, err := db.CreateTarget(t.Name, t.TargetURL, t.Platform, t.IsActive)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to insert target %s: %w", t.Name, err)
|
||||
}
|
||||
} else {
|
||||
// Sync is_active state with targets.yaml on startup
|
||||
if existing.IsActive != t.IsActive {
|
||||
_ = db.SetTargetActive(existing.ID, t.IsActive)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user