This commit is contained in:
Tomas Dvorak
2026-01-26 08:13:18 +01:00
parent aa036b6550
commit dfc079288f
505 changed files with 95755 additions and 5712 deletions
+50 -5
View File
@@ -20,6 +20,7 @@ type logoAPIResponse struct {
LogoURLSVG string `json:"logo_url_svg"`
LogoURLPNG string `json:"logo_url_png"`
LogoURL string `json:"logo_url"`
ClubName string `json:"club_name"`
}
func CacheClubLogo(db *gorm.DB, clubID string) (string, error) {
@@ -137,11 +138,11 @@ func CacheClubLogo(db *gorm.DB, clubID string) (string, error) {
if db != nil {
if err := db.Where("file_path = ?", dest).First(&existing).Error; err != nil {
uf := models.UploadedFile{
Filename: "club-logo" + ext,
FilePath: dest,
FileURL: publicURL,
MimeType: mime,
FileSize: 0,
Filename: "club-logo" + ext,
FilePath: dest,
FileURL: publicURL,
MimeType: mime,
FileSize: 0,
UploadedByID: nil,
}
if fi != nil {
@@ -153,3 +154,47 @@ func CacheClubLogo(db *gorm.DB, clubID string) (string, error) {
return publicURL, nil
}
type ClubLogoAndName struct {
LogoURL string
ClubName string
}
func CacheClubLogoAndName(db *gorm.DB, clubID string) (*ClubLogoAndName, error) {
cid := strings.TrimSpace(clubID)
if cid == "" {
return nil, fmt.Errorf("empty club id")
}
client := &http.Client{Timeout: 12 * time.Second}
req, err := http.NewRequest("GET", "https://logoapi.sportcreative.eu/logos/"+cid+"/json", nil)
if err != nil {
return nil, err
}
req.Header.Set("Accept", "application/json")
req.Header.Set("User-Agent", "fotbal-club/logo-cache")
resp, err := client.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
return nil, fmt.Errorf("logoapi status %d", resp.StatusCode)
}
var api logoAPIResponse
if err := json.NewDecoder(resp.Body).Decode(&api); err != nil {
return nil, err
}
// Cache the logo using existing function
logoURL, err := CacheClubLogo(db, clubID)
if err != nil {
// Even if logo caching fails, we still return the club name if available
logoURL = ""
}
return &ClubLogoAndName{
LogoURL: logoURL,
ClubName: strings.TrimSpace(api.ClubName),
}, nil
}