mirror of
https://github.com/Dvorinka/MyClubServer.git
synced 2026-06-04 02:32:57 +00:00
dev day #77
This commit is contained in:
@@ -95,6 +95,13 @@ func getPrefetchBaseURL() string {
|
||||
return base
|
||||
}
|
||||
|
||||
func foldAccents(s string) string {
|
||||
s = strings.ToLower(strings.TrimSpace(s))
|
||||
t := transform.Chain(norm.NFD, transform.RemoveFunc(func(r rune) bool { return unicode.Is(unicode.Mn, r) }), norm.NFC)
|
||||
out, _, _ := transform.String(t, s)
|
||||
return out
|
||||
}
|
||||
|
||||
// GetMatchesHistory returns cached past matches with overrides applied (public)
|
||||
// Optional query: q= filters by home/away/venue/competition
|
||||
func (bc *BaseController) GetMatchesHistory(c *gin.Context) {
|
||||
@@ -183,6 +190,7 @@ func (bc *BaseController) GetMatchesHistory(c *gin.Context) {
|
||||
|
||||
// Optional search filter
|
||||
if s := strings.ToLower(strings.TrimSpace(c.Query("q"))); s != "" {
|
||||
sq := foldAccents(s)
|
||||
filtered := make([]map[string]interface{}, 0, len(matches))
|
||||
for _, m := range matches {
|
||||
get := func(k string) string {
|
||||
@@ -199,7 +207,7 @@ func (bc *BaseController) GetMatchesHistory(c *gin.Context) {
|
||||
if f == "" {
|
||||
continue
|
||||
}
|
||||
if strings.Contains(strings.ToLower(f), s) {
|
||||
if strings.Contains(foldAccents(f), sq) {
|
||||
matched = true
|
||||
break
|
||||
}
|
||||
@@ -211,6 +219,7 @@ func (bc *BaseController) GetMatchesHistory(c *gin.Context) {
|
||||
matches = filtered
|
||||
}
|
||||
|
||||
// Respond with filtered/processed past matches
|
||||
c.Header("Cache-Control", "public, max-age=60")
|
||||
c.JSON(http.StatusOK, matches)
|
||||
}
|
||||
@@ -311,6 +320,35 @@ func (bc *BaseController) GetMatches(c *gin.Context) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if raw := strings.TrimSpace(c.Query("q")); raw != "" {
|
||||
sq := foldAccents(raw)
|
||||
filtered := make([]map[string]any, 0, len(matches))
|
||||
for _, m := range matches {
|
||||
get := func(k string) string {
|
||||
if v, ok := m[k]; ok {
|
||||
if vs, ok2 := v.(string); ok2 {
|
||||
return vs
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
fields := []string{get("home"), get("away"), get("venue"), get("competition"), get("competition_name"), get("league")}
|
||||
matched := false
|
||||
for _, f := range fields {
|
||||
if f == "" {
|
||||
continue
|
||||
}
|
||||
if strings.Contains(foldAccents(f), sq) {
|
||||
matched = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if matched {
|
||||
filtered = append(filtered, m)
|
||||
}
|
||||
}
|
||||
matches = filtered
|
||||
}
|
||||
c.Header("Cache-Control", "public, max-age=60")
|
||||
c.JSON(http.StatusOK, matches)
|
||||
}
|
||||
@@ -318,6 +356,7 @@ func (bc *BaseController) GetMatches(c *gin.Context) {
|
||||
func (bc *BaseController) GetStandings(c *gin.Context) {
|
||||
p := filepath.Join("cache", "prefetch", "facr_tables.json")
|
||||
f, err := os.Open(p)
|
||||
// ... (rest of the code remains the same)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusNoContent, gin.H{"message": "No cached standings"})
|
||||
return
|
||||
@@ -3503,12 +3542,25 @@ func (bc *BaseController) UpdateSettings(c *gin.Context) {
|
||||
s.FinishedMatchDisplayDays = *body.FinishedMatchDisplayDays
|
||||
}
|
||||
|
||||
// Deployment base URLs
|
||||
if body.FrontendBaseURL != nil {
|
||||
s.FrontendBaseURL = strings.TrimSpace(*body.FrontendBaseURL)
|
||||
v := strings.TrimSpace(*body.FrontendBaseURL)
|
||||
if v != "" {
|
||||
if u, err := url.Parse(v); err == nil && (u.Scheme == "http" || u.Scheme == "https") && u.Host != "" {
|
||||
u.Path = ""
|
||||
s.FrontendBaseURL = u.String()
|
||||
}
|
||||
}
|
||||
}
|
||||
if body.APIBaseURL != nil {
|
||||
s.APIBaseURL = strings.TrimSpace(*body.APIBaseURL)
|
||||
v := strings.TrimSpace(*body.APIBaseURL)
|
||||
if v != "" {
|
||||
if u, err := url.Parse(v); err == nil && (u.Scheme == "http" || u.Scheme == "https") && u.Host != "" {
|
||||
if !strings.Contains(u.Path, "/api/") {
|
||||
u.Path = strings.TrimRight(u.Path, "/") + "/api/v1"
|
||||
}
|
||||
s.APIBaseURL = u.String()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if s.ID == 0 {
|
||||
@@ -3548,6 +3600,21 @@ func (bc *BaseController) UpdateSettings(c *gin.Context) {
|
||||
go func(u string) { _ = services.RefreshYouTubeChannelNow(u) }(v)
|
||||
}
|
||||
}
|
||||
if strings.TrimSpace(s.FrontendBaseURL) != "" && config.AppConfig != nil {
|
||||
if u, err := url.Parse(s.FrontendBaseURL); err == nil {
|
||||
origin := u.Scheme + "://" + u.Host
|
||||
found := false
|
||||
for _, ao := range config.AppConfig.AllowedOrigins {
|
||||
if ao == origin {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
config.AppConfig.AllowedOrigins = append(config.AppConfig.AllowedOrigins, origin)
|
||||
}
|
||||
}
|
||||
}
|
||||
c.JSON(http.StatusOK, s)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user