diff --git a/go-backend/internal/handlers/admin_handler.go b/go-backend/internal/handlers/admin_handler.go index bc5030f..847e448 100644 --- a/go-backend/internal/handlers/admin_handler.go +++ b/go-backend/internal/handlers/admin_handler.go @@ -2981,8 +2981,9 @@ func (h *AdminHandler) TriggerOfficialPost(c *gin.Context) { return } - if cfg.AccountType == "news" { - // Fetch new articles and post the first one + switch cfg.AccountType { + case "news": + // Fetch new articles and post the first one with AI commentary items, sourceNames, err := h.officialAccountsService.FetchNewArticles(ctx, id) if err != nil { c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to fetch news: " + err.Error()}) @@ -3006,7 +3007,35 @@ func (h *AdminHandler) TriggerOfficialPost(c *gin.Context) { "title": items[0].Title, "remaining": len(items) - 1, }) - } else { + + case "rss": + // Post link directly — no AI + items, sourceNames, err := h.officialAccountsService.FetchNewArticles(ctx, id) + if err != nil { + c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to fetch RSS: " + err.Error()}) + return + } + if len(items) == 0 { + c.JSON(http.StatusOK, gin.H{"message": "No new articles found", "post_id": nil}) + return + } + + body := items[0].Link + postID, err := h.officialAccountsService.CreatePostForAccount(ctx, id, body, &items[0], sourceNames[0]) + if err != nil { + c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) + return + } + c.JSON(http.StatusOK, gin.H{ + "message": "RSS post created", + "post_id": postID, + "body": body, + "source": sourceNames[0], + "title": items[0].Title, + "remaining": len(items) - 1, + }) + + default: postID, body, err := h.officialAccountsService.GenerateAndPost(ctx, id, nil, "") if err != nil { c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) @@ -3031,7 +3060,8 @@ func (h *AdminHandler) PreviewOfficialPost(c *gin.Context) { return } - if cfg.AccountType == "news" { + switch cfg.AccountType { + case "news": items, sourceNames, err := h.officialAccountsService.FetchNewArticles(ctx, id) if err != nil { c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) @@ -3054,7 +3084,27 @@ func (h *AdminHandler) PreviewOfficialPost(c *gin.Context) { "article_link": items[0].Link, "pending_count": len(items), }) - } else { + + case "rss": + // No AI — preview shows the link that would be posted + items, sourceNames, err := h.officialAccountsService.FetchNewArticles(ctx, id) + if err != nil { + c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) + return + } + if len(items) == 0 { + c.JSON(http.StatusOK, gin.H{"message": "No new articles", "preview": nil}) + return + } + c.JSON(http.StatusOK, gin.H{ + "preview": items[0].Link, + "source": sourceNames[0], + "article_title": items[0].Title, + "article_link": items[0].Link, + "pending_count": len(items), + }) + + default: body, err := h.officialAccountsService.GeneratePost(ctx, id, nil, "") if err != nil { c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})