security: stop tracking env files; admin gate via VITE_SITE_ADMIN_GATE; Redis/cache/docs
Remove InfoGenie-frontend and Go .env from version control; add .env.example templates; ignore .claude local settings. Admin UI reads site gate from env only. Note: rotate secrets if repo history was ever public. Made-with: Cursor
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"infogenie-backend/internal/cache"
|
||||
"infogenie-backend/internal/database"
|
||||
"infogenie-backend/internal/model"
|
||||
)
|
||||
@@ -43,6 +45,19 @@ func (h *SiteConfigHandler) GetFeatureCardClicks(c *gin.Context) {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid_section"})
|
||||
return
|
||||
}
|
||||
ctx := c.Request.Context()
|
||||
key := cache.KeySiteFeatureClicks(section)
|
||||
var cached struct {
|
||||
Section string `json:"section"`
|
||||
Counts map[string]uint64 `json:"counts"`
|
||||
}
|
||||
if hit, err := cache.GetJSON(ctx, key, &cached); err != nil {
|
||||
log.Printf("redis GET %s: %v", key, err)
|
||||
} else if hit {
|
||||
c.JSON(http.StatusOK, gin.H{"section": cached.Section, "counts": cached.Counts})
|
||||
return
|
||||
}
|
||||
|
||||
var rows []model.SiteFeatureCardClick
|
||||
if err := database.DB.Where("section = ?", section).Find(&rows).Error; err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "db_error"})
|
||||
@@ -52,7 +67,11 @@ func (h *SiteConfigHandler) GetFeatureCardClicks(c *gin.Context) {
|
||||
for _, r := range rows {
|
||||
counts[r.ItemID] = r.ClickCount
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"section": section, "counts": counts})
|
||||
payload := gin.H{"section": section, "counts": counts}
|
||||
if err := cache.SetJSON(ctx, key, payload, 0); err != nil {
|
||||
log.Printf("redis SET %s: %v", key, err)
|
||||
}
|
||||
c.JSON(http.StatusOK, payload)
|
||||
}
|
||||
|
||||
type postFeatureCardClickBody struct {
|
||||
@@ -91,5 +110,6 @@ ON DUPLICATE KEY UPDATE click_count = click_count + 1, updated_at = NOW()`
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "db_error"})
|
||||
return
|
||||
}
|
||||
cache.Delete(c.Request.Context(), cache.KeySiteFeatureClicks(section))
|
||||
c.JSON(http.StatusOK, gin.H{"section": section, "item_id": itemID, "count": row.ClickCount})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user