package controller import ( "encoding/json" "github.com/gin-gonic/gin" "net/http" "one-api/common" "one-api/model" "strings" ) func GetOptions(c *gin.Context) { var options []*model.Option common.OptionMapRWMutex.Lock() for k, v := range common.OptionMap { if strings.Contains(k, "Token") || strings.Contains(k, "Secret") { continue } options = append(options, &model.Option{ Key: k, Value: common.Interface2String(v), }) } common.OptionMapRWMutex.Unlock() c.JSON(http.StatusOK, gin.H{ "success": true, "message": "", "data": options, }) return } func UpdateOption(c *gin.Context) { var option model.Option err := json.NewDecoder(c.Request.Body).Decode(&option) if err != nil { c.JSON(http.StatusBadRequest, gin.H{ "success": false, "message": "invalid parameter", }) return } switch option.Key { case "GitHubOAuthEnabled": if option.Value == "true" && common.GitHubClientId == "" { c.JSON(http.StatusOK, gin.H{ "success": false, "message": "Unable to enable GitHub OAuth, please fill in GitHub Client ID and GitHub Client Secret first!", }) return } case "WeChatAuthEnabled": if option.Value == "true" && common.WeChatServerAddress == "" { c.JSON(http.StatusOK, gin.H{ "success": false, "message": "Unable to enable WeChat login, please fill in the relevant configuration information for WeChat login first!", }) return } case "TurnstileCheckEnabled": if option.Value == "true" && common.TurnstileSiteKey == "" { c.JSON(http.StatusOK, gin.H{ "success": false, "message": "Unable to enable Turnstile verification, please fill in the relevant configuration information of Turnstile verification first!", }) return } } err = model.UpdateOption(option.Key, option.Value) if err != nil { c.JSON(http.StatusOK, gin.H{ "success": false, "message": err.Error(), }) return } c.JSON(http.StatusOK, gin.H{ "success": true, "message": "", }) return }