Files
v2rayA/service/controller/setting.go
T

42 lines
1.0 KiB
Go

package controller
import (
"github.com/mzz2017/v2rayA/common"
"github.com/mzz2017/v2rayA/core/v2ray/asset"
"github.com/mzz2017/v2rayA/db/configure"
"github.com/mzz2017/v2rayA/service"
"github.com/gin-gonic/gin"
)
func GetSetting(ctx *gin.Context) {
s := service.GetSetting()
var localGFWListVersion string
t, err := asset.GetGFWListModTime()
if err == nil {
localGFWListVersion = t.Local().Format("2006-01-02")
}
common.ResponseSuccess(ctx, gin.H{
"setting": s,
"localGFWListVersion": localGFWListVersion,
})
}
func PutSetting(ctx *gin.Context) {
var data configure.Setting
err := ctx.ShouldBindJSON(&data)
if err != nil {
common.ResponseError(ctx, logError(err, "bad request"))
return
}
if data.MuxOn == configure.Yes && (data.Mux < 1 || data.Mux > 1024) {
common.ResponseError(ctx, logError(nil, "mux should be between 1 and 1024"))
return
}
err = service.UpdateSetting(&data)
if err != nil {
common.ResponseError(ctx, logError(err))
return
}
common.ResponseSuccess(ctx, nil)
}