mirror of
https://github.com/Dvorinka/MyClubServer.git
synced 2026-06-04 02:32:57 +00:00
hot fix #1
This commit is contained in:
@@ -27,25 +27,25 @@ func NewArticleController(db *gorm.DB) *ArticleController {
|
||||
|
||||
// CreateArticleRequest represents the request body for creating an article
|
||||
type CreateArticleRequest struct {
|
||||
Title string `json:"title" binding:"required"`
|
||||
Content string `json:"content"`
|
||||
CategoryID *uint `json:"category_id"`
|
||||
CategoryName string `json:"category_name"`
|
||||
ImageURL string `json:"image_url"`
|
||||
Published *bool `json:"published"`
|
||||
PublishedAt *string `json:"published_at"`
|
||||
Featured *bool `json:"featured"`
|
||||
Slug string `json:"slug"`
|
||||
SeoTitle string `json:"seo_title"`
|
||||
SeoDescription string `json:"seo_description"`
|
||||
OgImageURL string `json:"og_image_url"`
|
||||
GalleryAlbumID string `json:"gallery_album_id"`
|
||||
GalleryAlbumURL string `json:"gallery_album_url"`
|
||||
GalleryPhotoIDs []string `json:"gallery_photo_ids"`
|
||||
YouTubeVideoID string `json:"youtube_video_id"`
|
||||
YouTubeVideoTitle string `json:"youtube_video_title"`
|
||||
YouTubeVideoURL string `json:"youtube_video_url"`
|
||||
YouTubeVideoThumbnail string `json:"youtube_video_thumbnail"`
|
||||
Title string `json:"title" binding:"required"`
|
||||
Content string `json:"content"`
|
||||
CategoryID *uint `json:"category_id"`
|
||||
CategoryName string `json:"category_name"`
|
||||
ImageURL string `json:"image_url"`
|
||||
Published *bool `json:"published"`
|
||||
PublishedAt *string `json:"published_at"`
|
||||
Featured *bool `json:"featured"`
|
||||
Slug string `json:"slug"`
|
||||
SeoTitle string `json:"seo_title"`
|
||||
SeoDescription string `json:"seo_description"`
|
||||
OgImageURL string `json:"og_image_url"`
|
||||
GalleryAlbumID string `json:"gallery_album_id"`
|
||||
GalleryAlbumURL string `json:"gallery_album_url"`
|
||||
GalleryPhotoIDs []string `json:"gallery_photo_ids"`
|
||||
YouTubeVideoID string `json:"youtube_video_id"`
|
||||
YouTubeVideoTitle string `json:"youtube_video_title"`
|
||||
YouTubeVideoURL string `json:"youtube_video_url"`
|
||||
YouTubeVideoThumbnail string `json:"youtube_video_thumbnail"`
|
||||
Attachments []AttachmentItem `json:"attachments"`
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ func (ac *ArticleController) CreateArticle(c *gin.Context) {
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
logger.Error("CreateArticle: Invalid request body: %v", err)
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"error": "Neplatná data požadavku",
|
||||
"error": "Neplatná data požadavku",
|
||||
"details": err.Error(),
|
||||
})
|
||||
return
|
||||
@@ -138,7 +138,9 @@ func (ac *ArticleController) CreateArticle(c *gin.Context) {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "Chyba při kontrole jedinečnosti URL"})
|
||||
return
|
||||
}
|
||||
if sc == 0 { break }
|
||||
if sc == 0 {
|
||||
break
|
||||
}
|
||||
s = fmt.Sprintf("%s-%d", orig, i+1)
|
||||
}
|
||||
category = models.Category{Name: categoryName, Slug: s}
|
||||
@@ -199,8 +201,31 @@ func (ac *ArticleController) CreateArticle(c *gin.Context) {
|
||||
seoDesc = deriveSeoDescription(req.Content)
|
||||
}
|
||||
|
||||
// 10. Set default image if empty
|
||||
// 10. Set image: prefer provided, otherwise try Grok (XAI) main image, then fallback to static placeholder
|
||||
imageURL := strings.TrimSpace(req.ImageURL)
|
||||
if imageURL == "" && isXAIEnabled() {
|
||||
promptParts := []string{
|
||||
fmt.Sprintf("Titulní obrázek k článku na oficiálním webu fotbalového klubu. Titulek článku: \"%s\".", strings.TrimSpace(req.Title)),
|
||||
}
|
||||
if strings.TrimSpace(req.CategoryName) != "" {
|
||||
promptParts = append(promptParts, fmt.Sprintf("Téma / soutěž: %s.", strings.TrimSpace(req.CategoryName)))
|
||||
}
|
||||
promptParts = append(promptParts,
|
||||
"Zaměř se na atmosféru klubu – stadion, hráče a fanoušky v klubových barvách.",
|
||||
"Styl: realistický, moderní, sportovní, bez textu, široký banner v poměru 16:9 vhodný jako hlavní obrázek článku.",
|
||||
)
|
||||
prompt := strings.Join(promptParts, " ")
|
||||
urls, _, err := callXAIImage(getXAIImageModel(), prompt, "1920x1080", 1)
|
||||
if err != nil {
|
||||
logger.Error("CreateArticle: XAI image generation failed: %v", err)
|
||||
} else if len(urls) > 0 {
|
||||
candidate := strings.TrimSpace(urls[0])
|
||||
if candidate != "" {
|
||||
imageURL = candidate
|
||||
logger.Info("CreateArticle: Using XAI-generated main image")
|
||||
}
|
||||
}
|
||||
}
|
||||
if imageURL == "" {
|
||||
imageURL = "/dist/img/logo-club-empty.svg"
|
||||
logger.Info("CreateArticle: Using default image")
|
||||
@@ -264,7 +289,7 @@ func (ac *ArticleController) CreateArticle(c *gin.Context) {
|
||||
if err := ac.DB.Create(&article).Error; err != nil {
|
||||
logger.Error("CreateArticle: Database error: %v", err)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{
|
||||
"error": "Nelze vytvořit článek",
|
||||
"error": "Nelze vytvořit článek",
|
||||
"details": err.Error(),
|
||||
})
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user