mirror of
https://github.com/songquanpeng/message-pusher.git
synced 2025-10-05 00:02:38 +08:00
70 lines
1.6 KiB
Go
70 lines
1.6 KiB
Go
package controller
|
||
|
||
import (
|
||
"encoding/json"
|
||
"github.com/gin-gonic/gin"
|
||
"message-pusher/common"
|
||
"message-pusher/model"
|
||
"net/http"
|
||
"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": "无效的参数",
|
||
})
|
||
return
|
||
}
|
||
if option.Key == "GitHubOAuthEnabled" && option.Value == "true" && common.GitHubClientId == "" {
|
||
c.JSON(http.StatusOK, gin.H{
|
||
"success": false,
|
||
"message": "无法启用 GitHub OAuth,请先填入 GitHub Client ID 以及 GitHub Client Secret!",
|
||
})
|
||
return
|
||
} else if option.Key == "WeChatAuthEnabled" && option.Value == "true" && common.WeChatServerAddress == "" {
|
||
c.JSON(http.StatusOK, gin.H{
|
||
"success": false,
|
||
"message": "无法启用微信登录,请先填入微信登录相关配置信息!",
|
||
})
|
||
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
|
||
}
|