add set client init

pull/351/head
wangchuxiao 2 years ago
parent c0b49ff219
commit 6553ada66f

@ -3,6 +3,7 @@ package main
import (
_ "Open_IM/cmd/open_im_api/docs"
apiAuth "Open_IM/internal/api/auth"
clientInit "Open_IM/internal/api/client_init"
"Open_IM/internal/api/conversation"
"Open_IM/internal/api/friend"
"Open_IM/internal/api/group"
@ -206,6 +207,12 @@ func main() {
}
initGroup := r.Group("/init")
{
initGroup.POST("/set_client_config", clientInit.SetClientInitConfig)
initGroup.POST("/get_client_config", clientInit.GetClientInitConfig)
}
go apiThird.MinioInit()
defaultPorts := config.Config.Api.GinPort
ginPort := flag.Int("port", defaultPorts[0], "get ginServerPort from cmd,default 10002 as port")

@ -0,0 +1,55 @@
package clientInit
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/utils"
"net/http"
"github.com/gin-gonic/gin"
)
func SetClientInitConfig(c *gin.Context) {
var req api.SetClientInitConfigReq
var resp api.SetClientInitConfigResp
if err := c.BindJSON(&req); err != nil {
log.NewError("0", utils.GetSelfFuncName(), err.Error())
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return
}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req)
m := make(map[string]interface{})
if req.DiscoverPageURL != nil {
m["discover_page_url"] = *req.DiscoverPageURL
}
if len(m) > 0 {
err := imdb.SetClientInitConfig(m)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error())
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
}
}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
c.JSON(http.StatusOK, resp)
}
func GetClientInitConfig(c *gin.Context) {
var req api.GetClientInitConfigReq
var resp api.GetClientInitConfigResp
if err := c.BindJSON(&req); err != nil {
log.NewError("0", utils.GetSelfFuncName(), err.Error())
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return
}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req)
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()})
}
resp.Data.DiscoverPageURL = config.DiscoverPageURL
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp ", resp)
c.JSON(http.StatusOK, resp)
}

@ -10,20 +10,21 @@ import (
api "Open_IM/pkg/base_info"
"Open_IM/pkg/common/config"
"Open_IM/pkg/common/constant"
"Open_IM/pkg/common/db/mysql_model/im_mysql_model"
"Open_IM/pkg/common/log"
"Open_IM/pkg/common/token_verify"
"Open_IM/pkg/grpc-etcdv3/getcdv3"
pbChat "Open_IM/pkg/proto/msg"
"Open_IM/pkg/proto/sdk_ws"
open_im_sdk "Open_IM/pkg/proto/sdk_ws"
server_api_params "Open_IM/pkg/proto/sdk_ws"
"Open_IM/pkg/utils"
"context"
"net/http"
"strings"
"github.com/gin-gonic/gin"
"github.com/go-playground/validator/v10"
"github.com/golang/protobuf/proto"
"github.com/mitchellh/mapstructure"
"net/http"
"strings"
)
var validate *validator.Validate
@ -332,7 +333,13 @@ func ManagementBatchSendMsg(c *gin.Context) {
ManagementSendMsg: params.ManagementSendMsg,
}
pbData := newUserSendMsgReq(req)
for _, recvID := range params.RecvIDList {
var recvList []string
if params.IsSendAll {
recvList, err = im_mysql_model.SelectAllUserID()
} else {
recvList = params.RecvIDList
}
for _, recvID := range recvList {
pbData.MsgData.RecvID = recvID
log.Info(params.OperationID, "", "api ManagementSendMsg call start..., ", pbData.String())

@ -0,0 +1,21 @@
package base_info
type SetClientInitConfigReq struct {
OperationID string `json:"operationID" binding:"required"`
DiscoverPageURL *string `json:"discoverPageURL"`
}
type SetClientInitConfigResp struct {
CommResp
}
type GetClientInitConfigReq struct {
OperationID string `json:"operationID" binding:"required"`
}
type GetClientInitConfigResp struct {
CommResp
Data struct {
DiscoverPageURL string `json:"discoverPageURL"`
} `json:"data"`
}

@ -2,8 +2,7 @@ package base_info
import (
pbRelay "Open_IM/pkg/proto/relay"
"Open_IM/pkg/proto/sdk_ws"
open_im_sdk "Open_IM/pkg/proto/sdk_ws"
server_api_params "Open_IM/pkg/proto/sdk_ws"
pbUser "Open_IM/pkg/proto/user"
)
@ -68,6 +67,7 @@ type ManagementSendMsgResp struct {
type ManagementBatchSendMsgReq struct {
ManagementSendMsg
IsSendAll bool `json:"isSendAll"`
RecvIDList []string `json:"recvIDList"`
}

@ -339,3 +339,11 @@ type RegisterAddFriend struct {
func (RegisterAddFriend) TableName() string {
return "register_add_friend"
}
type ClientInitConfig struct {
DiscoverPageURL string `gorm:"column:discover_page_url;size:64" json:"version"`
}
func (ClientInitConfig) TableName() string {
return "client_init_config"
}

@ -78,7 +78,8 @@ func initMysqlDB() {
&GroupMember{},
&GroupRequest{},
&User{},
&Black{}, &ChatLog{}, &Register{}, &Conversation{}, &AppVersion{}, &Department{}, &BlackList{}, &IpLimit{}, &UserIpLimit{}, &Invitation{}, &RegisterAddFriend{})
&Black{}, &ChatLog{}, &Register{}, &Conversation{}, &AppVersion{}, &Department{}, &BlackList{}, &IpLimit{}, &UserIpLimit{}, &Invitation{}, &RegisterAddFriend{},
&ClientInitConfig{})
db.Set("gorm:table_options", "CHARSET=utf8")
db.Set("gorm:table_options", "collation=utf8_unicode_ci")
@ -163,6 +164,12 @@ func initMysqlDB() {
fmt.Println("CreateTable Invitation")
db.Migrator().CreateTable(&Invitation{})
}
if !db.Migrator().HasTable(&ClientInitConfig{}) {
fmt.Println("CreateTable ClientInitConfig")
db.Migrator().CreateTable(&ClientInitConfig{})
}
DB.MysqlDB.db = db
return
}

@ -0,0 +1,22 @@
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)
if result.Error != nil {
return result.Error
}
if result.RowsAffected == 1 {
err := db.DB.MysqlDB.DefaultGormDB().Model(&db.ClientInitConfig{}).Create(m).Error
return err
}
return nil
}
func GetClientInitConfig() (db.ClientInitConfig, error) {
var config db.ClientInitConfig
err := db.DB.MysqlDB.DefaultGormDB().Model((&db.ClientInitConfig{})).First(&config).Error
return config, err
}
Loading…
Cancel
Save