新增了针对 mac 地址屏蔽webui 导航栏的接口
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/luxsin/app-api/internal/repository"
|
||||
"github.com/luxsin/app-api/internal/response"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type NavConfigHandler struct {
|
||||
repo *repository.NavConfigRepository
|
||||
log *zap.Logger
|
||||
}
|
||||
|
||||
func NewNavConfigHandler(repo *repository.NavConfigRepository, log *zap.Logger) *NavConfigHandler {
|
||||
return &NavConfigHandler{repo: repo, log: log}
|
||||
}
|
||||
|
||||
// GetNavConfig 获取导航栏隐藏配置
|
||||
//
|
||||
// @Summary 获取导航栏隐藏配置
|
||||
// @Description 根据设备 MAC 查询需要隐藏的导航入口(nav key: community|hpEq|home|effects|myAi)。未命中返回空数组,前端应默认全部显示。
|
||||
// @Tags NavConfig
|
||||
// @Produce json
|
||||
// @Param mac query string true "设备 MAC 地址"
|
||||
// @Success 200 {object} object "成功返回 hidden 列表"
|
||||
// @Failure 400 {object} object
|
||||
// @Failure 500 {object} object
|
||||
// @Router /audio/getNavConfig [get]
|
||||
func (h *NavConfigHandler) GetNavConfig(c *gin.Context) {
|
||||
mac := strings.TrimSpace(c.Query("mac"))
|
||||
if mac == "" {
|
||||
response.BadRequest(c, "mac参数不能为空")
|
||||
return
|
||||
}
|
||||
|
||||
ctx := c.Request.Context()
|
||||
|
||||
cfg, err := h.repo.FindByMac(ctx, mac)
|
||||
if err != nil {
|
||||
h.log.Error("query nav config failed", zap.String("mac", mac), zap.Error(err))
|
||||
response.InternalError(c, "查询导航配置失败")
|
||||
return
|
||||
}
|
||||
|
||||
hidden := make([]string, 0)
|
||||
if cfg != nil {
|
||||
for _, key := range strings.Split(cfg.HiddenKeys, ",") {
|
||||
if k := strings.TrimSpace(key); k != "" {
|
||||
hidden = append(hidden, k)
|
||||
}
|
||||
}
|
||||
if len(hidden) > 0 {
|
||||
h.log.Info("mac命中导航隐藏配置",
|
||||
zap.String("mac", repository.NormalizeMac(mac)),
|
||||
zap.Strings("hidden", hidden),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": 200,
|
||||
"msg": "操作成功",
|
||||
"data": gin.H{"hidden": hidden},
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user