- Updated the StartBackgroundUpdater function to accept a callback for software list updates, improving flexibility. - Refactored the API handlers to utilize a proxied software list, enhancing data handling and response efficiency. - Introduced a new method for refreshing the proxied software list, ensuring accurate data representation. - Added unit tests for API handlers to validate functionality and response correctness.
28 lines
711 B
Go
28 lines
711 B
Go
package config
|
|
|
|
import (
|
|
"log"
|
|
"time"
|
|
|
|
"software-station/internal/models"
|
|
)
|
|
|
|
func StartBackgroundUpdater(path, server, token string, interval time.Duration, onUpdate func([]models.Software)) {
|
|
ticker := time.NewTicker(interval)
|
|
go func() {
|
|
for range ticker.C {
|
|
log.Println("Checking for software updates...")
|
|
newList := LoadSoftwareFromGitea(path, server, token)
|
|
if len(newList) > 0 {
|
|
onUpdate(newList)
|
|
log.Printf("Software list updated with %d items", len(newList))
|
|
}
|
|
}
|
|
}()
|
|
}
|
|
|
|
// LoadSoftwareFromGitea always fetches from Gitea and updates cache
|
|
func LoadSoftwareFromGitea(path, server, token string) []models.Software {
|
|
return LoadSoftwareExtended(path, server, token, false)
|
|
}
|