You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
synctv/server/handlers/admin.go

41 lines
931 B
Go

package handlers
import (
"fmt"
"net/http"
"github.com/gin-gonic/gin"
dbModel "github.com/synctv-org/synctv/internal/model"
"github.com/synctv-org/synctv/internal/op"
"github.com/synctv-org/synctv/server/model"
)
func AdminSettings(ctx *gin.Context) {
// user := ctx.MustGet("user").(*op.User)
req := model.AdminSettingsReq{}
if err := req.Decode(ctx); err != nil {
ctx.AbortWithError(http.StatusBadRequest, err)
return
}
for k, v := range req {
t, ok := op.GetSettingType(k)
if !ok {
ctx.AbortWithStatusJSON(http.StatusBadRequest, model.NewApiErrorStringResp(fmt.Sprintf("setting %s not found", k)))
return
}
switch t {
case dbModel.SettingTypeBool:
b, ok := v.(bool)
if !ok {
ctx.AbortWithStatusJSON(http.StatusBadRequest, model.NewApiErrorStringResp(fmt.Sprintf("setting %s is not bool", k)))
return
}
op.BoolSettings[k].Set(b)
}
}
ctx.Status(http.StatusNoContent)
}