Merge remote-tracking branch 'origin/v2.3.0release' into v2.3.0release

pull/351/head
Gordon 2 years ago
commit 2c21bf3e0e

@ -4,10 +4,12 @@ import (
api "Open_IM/pkg/base_info"
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
"Open_IM/pkg/common/log"
"Open_IM/pkg/common/token_verify"
"Open_IM/pkg/utils"
"net/http"
"github.com/gin-gonic/gin"
"github.com/jinzhu/gorm"
)
func SetClientInitConfig(c *gin.Context) {
@ -19,6 +21,13 @@ func SetClientInitConfig(c *gin.Context) {
return
}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req)
err, _ := token_verify.ParseTokenGetUserID(c.Request.Header.Get("token"), req.OperationID)
if err != nil {
errMsg := "ParseTokenGetUserID failed " + err.Error() + c.Request.Header.Get("token")
log.NewError(req.OperationID, errMsg, errMsg)
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
return
}
m := make(map[string]interface{})
if req.DiscoverPageURL != nil {
m["discover_page_url"] = *req.DiscoverPageURL
@ -28,6 +37,7 @@ func SetClientInitConfig(c *gin.Context) {
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error())
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
return
}
}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
@ -43,10 +53,20 @@ func GetClientInitConfig(c *gin.Context) {
return
}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req)
err, _ := token_verify.ParseTokenGetUserID(c.Request.Header.Get("token"), req.OperationID)
if err != nil {
errMsg := "ParseTokenGetUserID failed " + err.Error() + c.Request.Header.Get("token")
log.NewError(req.OperationID, errMsg, errMsg)
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
return
}
config, err := imdb.GetClientInitConfig()
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error())
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
if !gorm.IsRecordNotFoundError(err) {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error())
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
return
}
}
resp.Data.DiscoverPageURL = config.DiscoverPageURL
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp ", resp)

@ -3,11 +3,11 @@ package im_mysql_model
import "Open_IM/pkg/common/db"
func SetClientInitConfig(m map[string]interface{}) error {
result := db.DB.MysqlDB.DefaultGormDB().Model(&db.ClientInitConfig{}).Updates(m)
result := db.DB.MysqlDB.DefaultGormDB().Model(&db.ClientInitConfig{}).Where("1=1").Updates(m)
if result.Error != nil {
return result.Error
}
if result.RowsAffected == 1 {
if result.RowsAffected == 0 {
err := db.DB.MysqlDB.DefaultGormDB().Model(&db.ClientInitConfig{}).Create(m).Error
return err
}

Loading…
Cancel
Save