Files
nl-game-api/internal/handler/config.go
2026-08-14 13:17:03 +08:00

39 lines
1.4 KiB
Go

package handler
import (
"encoding/json"
"github.com/gin-gonic/gin"
"nl-game-api-gin/internal/database"
"nl-game-api-gin/internal/model"
"nl-game-api-gin/internal/service"
"nl-game-api-gin/pkg/resp"
)
// SiteConfigPublic 公开的站点配置:站点名、公告、当前主题(含 CSS 变量),无需登录
func SiteConfigPublic(c *gin.Context) {
// 读取当前启用的主题(后台可切换)
activeCode := service.GetConfig(model.ConfKeyActiveTheme, "arcade")
var theme model.Theme
if err := database.DB.Where("code = ? AND status = 1", activeCode).First(&theme).Error; err != nil {
// 配置的主题不存在时回退到第一个可用主题
database.DB.Where("status = 1").Order("sort").First(&theme)
}
// 把 CSS 变量 JSON 解析成对象,前端直接注入 :root
vars := map[string]string{}
json.Unmarshal([]byte(theme.CSSVars), &vars)
resp.OK(c, gin.H{
"site_name": service.GetConfig(model.ConfKeySiteName, "像素游戏厅"),
"announcement": service.GetConfig(model.ConfKeyAnnouncement, ""),
// 大厅轮播配置:效果样式 + 自动播放间隔(参与轮播的游戏由 games.carousel 决定)
"carousel_style": service.GetConfig(model.ConfKeyCarouselStyle, "slide"),
"carousel_interval": service.GetConfigInt(model.ConfKeyCarouselInterval, 5),
"theme": gin.H{
"code": theme.Code,
"name": theme.Name,
"css_vars": vars,
},
})
}