This commit is contained in:
Tomas Dvorak
2025-11-03 19:54:39 +01:00
parent 087f30e82c
commit d5b4faea61
141 changed files with 78770 additions and 966 deletions
+114 -7
View File
@@ -1258,7 +1258,16 @@ func (bc *BaseController) UpdateArticle(c *gin.Context) {
if art.Published && !oldPublished {
go bc.triggerBlogNotification(&art)
go func() { services.PrefetchOnce(getBaseURL()) }()
go func() {
var s models.Settings
if err := bc.DB.First(&s).Error; err == nil {
base := strings.TrimSpace(s.APIBaseURL)
if base == "" { base = getPrefetchBaseURL() }
services.PrefetchOnce(strings.TrimRight(base, "/"))
} else {
services.PrefetchOnce(getPrefetchBaseURL())
}
}()
}
bc.DB.Preload("Author").Preload("Category").First(&art, art.ID)
@@ -2396,9 +2405,19 @@ func (bc *BaseController) SetupInitialize(c *gin.Context) {
s.SMTPPassword = v
}
if v := strings.TrimSpace(body.SMTP.From); v != "" {
s.SMTPFrom = v
name := ""
addr := v
if lt, gt := strings.Index(v, "<"), strings.Index(v, ">"); lt >= 0 && gt > lt {
name = strings.TrimSpace(v[:lt])
addr = strings.TrimSpace(v[lt+1 : gt])
}
addr = strings.Trim(addr, "\" ")
name = strings.Trim(name, "\" ")
s.SMTPFrom = addr
if name != "" && !strings.Contains(strings.ToLower(name), "@") {
s.SMTPFromName = name
}
}
// Default FromName if empty
if s.SMTPFromName == "" {
s.SMTPFromName = "Fotbal Club"
}
@@ -2432,8 +2451,81 @@ func (bc *BaseController) SetupInitialize(c *gin.Context) {
_ = bc.DB.Model(&models.Settings{}).Where("id = ?", s.ID).Update("club_logo_url", url).Error
}
}
// Trigger background prefetch and YouTube cache refresh when settings are updated post-setup
go func() { services.PrefetchOnce(getBaseURL()) }()
// Immediately write public settings cache from current Settings snapshot
go func(snap models.Settings) {
defer func() { _ = recover() }()
snap.LoadCustomNav()
var pubVids []string
if snap.VideosJSON != "" {
_ = json.Unmarshal([]byte(snap.VideosJSON), &pubVids)
}
var pubVidsItems any
if snap.VideosItemsJSON != "" {
_ = json.Unmarshal([]byte(snap.VideosItemsJSON), &pubVidsItems)
}
var pubMerchItems any
if snap.MerchItemsJSON != "" {
_ = json.Unmarshal([]byte(snap.MerchItemsJSON), &pubMerchItems)
}
resp := map[string]any{
"club_id": snap.ClubID,
"club_type": snap.ClubType,
"club_name": snap.ClubName,
"club_logo_url": snap.ClubLogoURL,
"club_url": snap.ClubURL,
"primary_color": snap.PrimaryColor,
"secondary_color": snap.SecondaryColor,
"accent_color": snap.AccentColor,
"background_color": snap.BackgroundColor,
"text_color": snap.TextColor,
"font_heading": snap.FontHeading,
"font_body": snap.FontBody,
"sponsors_layout": snap.SponsorsLayout,
"sponsors_theme": snap.SponsorsTheme,
"facebook_url": snap.FacebookURL,
"instagram_url": snap.InstagramURL,
"youtube_url": snap.YoutubeURL,
"gallery_url": snap.GalleryURL,
"gallery_label": snap.GalleryLabel,
"videos_module_enabled": snap.VideosModuleEnabled,
"videos_style": snap.VideosStyle,
"videos_source": snap.VideosSource,
"videos_limit": snap.VideosLimit,
"videos": pubVids,
"videos_items": pubVidsItems,
"merch_module_enabled": snap.MerchModuleEnabled,
"merch_style": snap.MerchStyle,
"merch_source": snap.MerchSource,
"merch_limit": snap.MerchLimit,
"merch_items": pubMerchItems,
"about_html": snap.AboutHTML,
"show_about_in_nav": snap.ShowAboutInNav,
"custom_nav": snap.CustomNav,
"contact_address": snap.ContactAddress,
"contact_city": snap.ContactCity,
"contact_zip": snap.ContactZip,
"contact_country": snap.ContactCountry,
"contact_phone": snap.ContactPhone,
"contact_email": snap.ContactEmail,
"location_latitude": snap.LocationLatitude,
"location_longitude": snap.LocationLongitude,
"map_zoom_level": snap.MapZoomLevel,
"map_style": snap.MapStyle,
"show_map_on_homepage": snap.ShowMapOnHomepage,
}
b, _ := json.MarshalIndent(resp, "", " ")
outPath := filepath.Join("cache", "prefetch", "settings.json")
_ = os.MkdirAll(filepath.Dir(outPath), 0o755)
tmp := outPath + ".tmp"
_ = os.WriteFile(tmp, b, 0o644)
_ = os.Rename(tmp, outPath)
}(s)
// Trigger background prefetch using APIBaseURL if set, otherwise fallback to local
go func(urlFromSettings string) {
base := strings.TrimSpace(urlFromSettings)
if base == "" { base = getPrefetchBaseURL() }
services.PrefetchOnce(strings.TrimRight(base, "/"))
}(s.APIBaseURL)
if strings.TrimSpace(s.YoutubeURL) != "" {
go func(u string) { _ = services.RefreshYouTubeChannelNow(u) }(s.YoutubeURL)
}
@@ -2703,9 +2795,19 @@ func (bc *BaseController) SetupInitialize(c *gin.Context) {
s.SMTPPassword = v
}
if v := strings.TrimSpace(body.SMTP.From); v != "" {
s.SMTPFrom = v
name := ""
addr := v
if lt, gt := strings.Index(v, "<"), strings.Index(v, ">"); lt >= 0 && gt > lt {
name = strings.TrimSpace(v[:lt])
addr = strings.TrimSpace(v[lt+1 : gt])
}
addr = strings.Trim(addr, "\" ")
name = strings.Trim(name, "\" ")
s.SMTPFrom = addr
if name != "" && !strings.Contains(strings.ToLower(name), "@") {
s.SMTPFromName = name
}
}
// Default FromName if empty
if s.SMTPFromName == "" {
s.SMTPFromName = "Fotbal Club"
}
@@ -3458,6 +3560,8 @@ func (bc *BaseController) GetPublicSettings(c *gin.Context) {
"club_name": s.ClubName,
"club_logo_url": s.ClubLogoURL,
"club_url": s.ClubURL,
// Runtime flags (env-based)
"premium": config.AppConfig.Premium,
// Theme
"primary_color": s.PrimaryColor,
@@ -3722,6 +3826,7 @@ func (bc *BaseController) CreatePlayer(c *gin.Context) {
Height *int `json:"height"`
Weight *int `json:"weight"`
ImageURL string `json:"image_url"`
Gender string `json:"gender"`
IsActive *bool `json:"is_active"`
Email string `json:"email"`
Phone string `json:"phone"`
@@ -3736,6 +3841,7 @@ func (bc *BaseController) CreatePlayer(c *gin.Context) {
Position: strings.TrimSpace(body.Position),
Nationality: strings.TrimSpace(body.Nationality),
ImageURL: strings.TrimSpace(body.ImageURL),
Gender: strings.TrimSpace(body.Gender),
IsActive: true,
Email: strings.TrimSpace(body.Email),
}
@@ -3796,6 +3902,7 @@ func (bc *BaseController) UpdatePlayer(c *gin.Context) {
Height *int `json:"height"`
Weight *int `json:"weight"`
ImageURL *string `json:"image_url"`
Gender *string `json:"gender"`
IsActive *bool `json:"is_active"`
Email *string `json:"email"`
Phone *string `json:"phone"`