This commit is contained in:
Tomas Dvorak
2025-11-21 08:44:44 +01:00
parent c941313fd5
commit f5b6f83974
108 changed files with 8642 additions and 5871 deletions
+120 -1
View File
@@ -14,6 +14,7 @@ import (
"time"
"fotbal-club/internal/models"
"fotbal-club/internal/services"
"github.com/PuerkitoBio/goquery"
"github.com/gin-gonic/gin"
@@ -225,6 +226,10 @@ func getLogoBySearch(name string) string {
best = payload.Results[0].LogoURL
}
if best != "" {
// Attempt to process FACR logos to transparent PNG via rembg (best-effort)
if p, err := services.ProcessFACRLogo(best); err == nil && strings.TrimSpace(p) != "" {
best = p
}
logoCache[key] = best
return best
}
@@ -280,6 +285,9 @@ func getLogoBySearch(name string) string {
best = partial
}
if best != "" {
if p, err := services.ProcessFACRLogo(best); err == nil && strings.TrimSpace(p) != "" {
best = p
}
logoCache[key] = best
}
return best
@@ -292,11 +300,18 @@ func getLogo(teamName, teamID string) string {
return placeholder
}
if logo := getLogoBySearch(teamName); logo != "" {
if p, err := services.ProcessFACRLogo(logo); err == nil && strings.TrimSpace(p) != "" {
return p
}
return logo
}
tid := strings.TrimSpace(teamID)
if tid != "" {
return fmt.Sprintf("https://is1.fotbal.cz/media/kluby/%s/%s_crop.jpg", tid, tid)
u := fmt.Sprintf("https://is1.fotbal.cz/media/kluby/%s/%s_crop.jpg", tid, tid)
if p, err := services.ProcessFACRLogo(u); err == nil && strings.TrimSpace(p) != "" {
return p
}
return u
}
return placeholder
}
@@ -410,6 +425,10 @@ func (fc *FACRController) SearchClubs(c *gin.Context) {
}
img := a.Find("img").First()
logoURL, _ := img.Attr("src")
// Best-effort: Process FACR logos to transparent PNG. Non-facr URLs are returned unchanged.
if p, err := services.ProcessFACRLogo(logoURL); err == nil && strings.TrimSpace(p) != "" {
logoURL = p
}
category := strings.TrimSpace(li.Find(".ClubCategories .BadgeCategory").First().Text())
address := strings.TrimSpace(li.Find(".ClubAddress p").First().Text())
clubType := "football"
@@ -535,6 +554,63 @@ func (fc *FACRController) GetClubInfo(c *gin.Context) {
c.JSON(http.StatusBadGateway, gin.H{"error": fmt.Sprintf("read error: %v", err)})
return
}
// Best-effort: rewrite FACR logos in matches to processed local PNGs via rembg
// so that all consumers receive transparent logos consistently.
{
var orig map[string]any
if json.Unmarshal(b, &orig) == nil {
if comps, ok := orig["competitions"].([]any); ok {
seen := map[string]string{}
for i := range comps {
comp, _ := comps[i].(map[string]any)
if comp == nil {
continue
}
if matches, ok2 := comp["matches"].([]any); ok2 {
for j := range matches {
m, _ := matches[j].(map[string]any)
if m == nil {
continue
}
// home_logo_url
if s, ok3 := m["home_logo_url"].(string); ok3 && strings.TrimSpace(s) != "" {
if rep, ok := seen[s]; ok {
if rep != "" && rep != s {
m["home_logo_url"] = rep
}
} else {
if p, err := services.ProcessFACRLogo(s); err == nil && strings.TrimSpace(p) != "" && p != s {
seen[s] = p
m["home_logo_url"] = p
} else {
seen[s] = s
}
}
}
// away_logo_url
if s, ok3 := m["away_logo_url"].(string); ok3 && strings.TrimSpace(s) != "" {
if rep, ok := seen[s]; ok {
if rep != "" && rep != s {
m["away_logo_url"] = rep
}
} else {
if p, err := services.ProcessFACRLogo(s); err == nil && strings.TrimSpace(p) != "" && p != s {
seen[s] = p
m["away_logo_url"] = p
} else {
seen[s] = s
}
}
}
}
}
}
if nb, err := json.Marshal(orig); err == nil {
b = nb
}
}
}
}
setCachedJSON(cacheKey, b)
c.Data(http.StatusOK, "application/json", b)
}
@@ -573,6 +649,49 @@ func (fc *FACRController) GetClubTables(c *gin.Context) {
c.JSON(http.StatusBadGateway, gin.H{"error": fmt.Sprintf("read error: %v", err)})
return
}
// Best-effort: rewrite team_logo_url in tables to processed local PNGs via rembg
{
var orig map[string]any
if json.Unmarshal(b, &orig) == nil {
if comps, ok := orig["competitions"].([]any); ok {
seen := map[string]string{}
for i := range comps {
comp, _ := comps[i].(map[string]any)
if comp == nil {
continue
}
tbl, _ := comp["table"].(map[string]any)
if tbl == nil {
continue
}
overall, _ := tbl["overall"].([]any)
for j := range overall {
row, _ := overall[j].(map[string]any)
if row == nil {
continue
}
if s, ok3 := row["team_logo_url"].(string); ok3 && strings.TrimSpace(s) != "" {
if rep, ok := seen[s]; ok {
if rep != "" && rep != s {
row["team_logo_url"] = rep
}
} else {
if p, err := services.ProcessFACRLogo(s); err == nil && strings.TrimSpace(p) != "" && p != s {
seen[s] = p
row["team_logo_url"] = p
} else {
seen[s] = s
}
}
}
}
}
if nb, err := json.Marshal(orig); err == nil {
b = nb
}
}
}
}
setCachedJSON(cacheKey, b)
c.Data(http.StatusOK, "application/json", b)
}