mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-08-06 19:20:12 +08:00
Merge remote-tracking branch 'origin/tuoyun' into tuoyun
This commit is contained in:
commit
f4f3ff0eda
2
go.sum
2
go.sum
@ -519,8 +519,6 @@ google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv
|
||||
google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU=
|
||||
google.golang.org/grpc v1.38.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM=
|
||||
google.golang.org/grpc v1.40.0/go.mod h1:ogyxbiOoUXAkP+4+xa6PZSE9DZgIHtSpzjDTB9KAK34=
|
||||
google.golang.org/grpc v1.42.0 h1:XT2/MFpuPFsEX2fWh3YQtHkZ+WYZFQRfaUgLZYj/p6A=
|
||||
google.golang.org/grpc v1.42.0/go.mod h1:k+4IHHFw41K8+bbowsex27ge2rCb65oeWqe4jJ590SU=
|
||||
google.golang.org/grpc v1.45.0 h1:NEpgUqV3Z+ZjkqMsxMg11IaDrXY4RY6CQukSGK0uI1M=
|
||||
google.golang.org/grpc v1.45.0/go.mod h1:lN7owxKUQEqMfSyQikvvk5tf/6zMPsrK+ONuO11+0rQ=
|
||||
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
|
||||
|
@ -15,7 +15,6 @@ import (
|
||||
_ "github.com/minio/minio-go/v7"
|
||||
cr "github.com/minio/minio-go/v7/pkg/credentials"
|
||||
"net/http"
|
||||
"path"
|
||||
)
|
||||
|
||||
func MinioUploadFile(c *gin.Context) {
|
||||
@ -167,28 +166,22 @@ func UploadUpdateApp(c *gin.Context) {
|
||||
} else {
|
||||
yamlName = req.Yaml.Filename
|
||||
}
|
||||
newFileName, newYamlName, err := utils.GetUploadAppNewName(req.Type, req.Version, req.File.Filename, yamlName)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUploadAppNewName failed", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "invalid file type" + err.Error()})
|
||||
return
|
||||
}
|
||||
fileObj, err := req.File.Open()
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "Open file error", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "Open file error" + err.Error()})
|
||||
return
|
||||
}
|
||||
_, err = MinioClient.PutObject(context.Background(), config.Config.Credential.Minio.AppBucket, newFileName, fileObj, req.File.Size, minio.PutObjectOptions{ContentType: path.Ext(newFileName)})
|
||||
_, err = MinioClient.PutObject(context.Background(), config.Config.Credential.Minio.AppBucket, req.File.Filename, fileObj, req.File.Size, minio.PutObjectOptions{})
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "PutObject file error")
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "PutObject file error" + err.Error()})
|
||||
return
|
||||
}
|
||||
if newYamlName != "" {
|
||||
if yamlName != "" {
|
||||
yamlObj, err := req.Yaml.Open()
|
||||
if err == nil {
|
||||
_, err = MinioClient.PutObject(context.Background(), config.Config.Credential.Minio.AppBucket, newYamlName, yamlObj, req.Yaml.Size, minio.PutObjectOptions{ContentType: path.Ext(newYamlName)})
|
||||
_, err = MinioClient.PutObject(context.Background(), config.Config.Credential.Minio.AppBucket, yamlName, yamlObj, req.Yaml.Size, minio.PutObjectOptions{})
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "PutObject yaml error")
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "PutObject yaml error" + err.Error()})
|
||||
@ -196,10 +189,9 @@ func UploadUpdateApp(c *gin.Context) {
|
||||
}
|
||||
} else {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error())
|
||||
newYamlName = ""
|
||||
}
|
||||
}
|
||||
if err := imdb.UpdateAppVersion(req.Type, req.Version, req.ForceUpdate, newFileName, newYamlName); err != nil {
|
||||
if err := imdb.UpdateAppVersion(req.Type, req.Version, req.ForceUpdate, req.File.Filename, yamlName, req.UpdateLog); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "UpdateAppVersion error", err.Error())
|
||||
resp.ErrCode = http.StatusInternalServerError
|
||||
resp.ErrMsg = err.Error()
|
||||
@ -239,6 +231,8 @@ func GetDownloadURL(c *gin.Context) {
|
||||
resp.Data.YamlURL = config.Config.Credential.Minio.Endpoint + "/" + config.Config.Credential.Minio.AppBucket + "/" + app.YamlName
|
||||
}
|
||||
resp.Data.FileURL = config.Config.Credential.Minio.Endpoint + "/" + config.Config.Credential.Minio.AppBucket + "/" + app.FileName
|
||||
resp.Data.Version = app.Version
|
||||
resp.Data.UpdateLog = app.UpdateLog
|
||||
c.JSON(http.StatusOK, resp)
|
||||
return
|
||||
} else {
|
||||
|
@ -4,18 +4,14 @@ import (
|
||||
apiStruct "Open_IM/pkg/cms_api_struct"
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
openIMHttp "Open_IM/pkg/common/http"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
pbAdmin "Open_IM/pkg/proto/admin_cms"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/minio/minio-go/v7"
|
||||
"github.com/minio/minio-go/v7/pkg/credentials"
|
||||
"net/http"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@ -83,124 +79,3 @@ func AdminLogin(c *gin.Context) {
|
||||
resp.Token = respPb.Token
|
||||
openIMHttp.RespHttp200(c, constant.OK, resp)
|
||||
}
|
||||
|
||||
func UploadUpdateApp(c *gin.Context) {
|
||||
var (
|
||||
req apiStruct.UploadUpdateAppReq
|
||||
resp apiStruct.UploadUpdateAppResp
|
||||
)
|
||||
if err := c.Bind(&req); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req)
|
||||
|
||||
//fileObj, err := req.File.Open()
|
||||
//if err != nil {
|
||||
// log.NewError(req.OperationID, utils.GetSelfFuncName(), "Open file error", err.Error())
|
||||
// c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "Open file error" + err.Error()})
|
||||
// return
|
||||
//}
|
||||
//yamlObj, err := req.Yaml.Open()
|
||||
//if err != nil {
|
||||
// log.NewError(req.OperationID, utils.GetSelfFuncName(), "Open Yaml error", err.Error())
|
||||
// c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "Open Yaml error" + err.Error()})
|
||||
// return
|
||||
//}
|
||||
|
||||
// v2.0.9_app_linux v2.0.9_yaml_linux
|
||||
file, err := c.FormFile("file")
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "FormFile failed", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "missing file arg: " + err.Error()})
|
||||
return
|
||||
}
|
||||
fileObj, err := file.Open()
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "Open file error", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "invalid file path" + err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
yaml, err := c.FormFile("yaml")
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "FormFile failed", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "missing file arg: " + err.Error()})
|
||||
return
|
||||
}
|
||||
yamlObj, err := yaml.Open()
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "Open file error", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "invalid file path" + err.Error()})
|
||||
return
|
||||
}
|
||||
newFileName, newYamlName, err := utils.GetUploadAppNewName(req.Type, req.Version, file.Filename, yaml.Filename)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUploadAppNewName failed", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "invalid file type" + err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println(req.OperationID, utils.GetSelfFuncName(), "name: ", config.Config.Credential.Minio.AppBucket, newFileName, fileObj, file.Size)
|
||||
fmt.Println(req.OperationID, utils.GetSelfFuncName(), "name: ", config.Config.Credential.Minio.AppBucket, newYamlName, yamlObj, yaml.Size)
|
||||
|
||||
_, err = minioClient.PutObject(context.Background(), config.Config.Credential.Minio.AppBucket, newFileName, fileObj, file.Size, minio.PutObjectOptions{ContentType: path.Ext(newFileName)})
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "PutObject file error")
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "PutObject file error" + err.Error()})
|
||||
return
|
||||
}
|
||||
_, err = minioClient.PutObject(context.Background(), config.Config.Credential.Minio.AppBucket, newYamlName, yamlObj, yaml.Size, minio.PutObjectOptions{ContentType: path.Ext(newYamlName)})
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "PutObject yaml error")
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "PutObject yaml error" + err.Error()})
|
||||
return
|
||||
}
|
||||
if err := imdb.UpdateAppVersion(req.Type, req.Version, req.ForceUpdate, newFileName, newYamlName); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "UpdateAppVersion error", err.Error())
|
||||
resp.ErrCode = http.StatusInternalServerError
|
||||
resp.ErrMsg = err.Error()
|
||||
c.JSON(http.StatusInternalServerError, resp)
|
||||
return
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName())
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func GetDownloadURL(c *gin.Context) {
|
||||
var (
|
||||
req apiStruct.GetDownloadURLReq
|
||||
resp apiStruct.GetDownloadURLResp
|
||||
)
|
||||
defer func() {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
|
||||
}()
|
||||
if err := c.Bind(&req); err != nil {
|
||||
log.NewError("0", utils.GetSelfFuncName(), "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req)
|
||||
app, err := imdb.GetNewestVersion(req.Type)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "getNewestVersion failed", err.Error())
|
||||
}
|
||||
if app != nil {
|
||||
if app.Version != req.Version && app.Version != "" {
|
||||
resp.Data.HasNewVersion = true
|
||||
if app.ForceUpdate == true {
|
||||
resp.Data.ForceUpdate = true
|
||||
}
|
||||
resp.Data.YamlURL = config.Config.Credential.Minio.Endpoint + "/" + config.Config.Credential.Minio.AppBucket + "/" + app.YamlName
|
||||
resp.Data.FileURL = config.Config.Credential.Minio.Endpoint + "/" + config.Config.Credential.Minio.AppBucket + "/" + app.FileName
|
||||
c.JSON(http.StatusOK, resp)
|
||||
return
|
||||
} else {
|
||||
resp.Data.HasNewVersion = false
|
||||
c.JSON(http.StatusOK, resp)
|
||||
return
|
||||
}
|
||||
}
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 0, "errMsg": "not found app version"})
|
||||
}
|
||||
|
@ -20,8 +20,6 @@ func NewGinRouter() *gin.Engine {
|
||||
adminRouterGroup := router.Group("/admin")
|
||||
{
|
||||
adminRouterGroup.POST("/login", admin.AdminLogin)
|
||||
adminRouterGroup.POST("/upload_update_app", admin.UploadUpdateApp)
|
||||
adminRouterGroup.POST("/get_download_url", admin.GetDownloadURL)
|
||||
}
|
||||
r2 := router.Group("")
|
||||
r2.Use(middleware.JWTAuth())
|
||||
|
@ -60,7 +60,7 @@ func (ws *WServer) msgParse(conn *UserConn, binaryMsg []byte) {
|
||||
ws.pullMsgBySeqListReq(conn, &m)
|
||||
default:
|
||||
}
|
||||
log.NewInfo("", "goroutine num is ", runtime.NumGoroutine())
|
||||
log.NewInfo(m.OperationID, "goroutine num is ", runtime.NumGoroutine())
|
||||
}
|
||||
func (ws *WServer) getSeqReq(conn *UserConn, m *Req) {
|
||||
log.NewInfo(m.OperationID, "Ws call success to getNewSeq", m.MsgIncr, m.SendID, m.ReqIdentifier, m.Data)
|
||||
|
@ -136,10 +136,10 @@ func sendMessageToPush(message *pbMsg.MsgDataToMQ, pushToUserID string) {
|
||||
log.Error(rpcPushMsg.OperationID, "rpc send failed", rpcPushMsg.OperationID, "push data", rpcPushMsg.String(), "err", err.Error())
|
||||
pid, offset, err := producer.SendMessage(&mqPushMsg)
|
||||
if err != nil {
|
||||
log.Error("kafka send failed", mqPushMsg.OperationID, "send data", mqPushMsg.String(), "pid", pid, "offset", offset, "err", err.Error())
|
||||
log.Error(message.OperationID, "kafka send failed", mqPushMsg.OperationID, "send data", mqPushMsg.String(), "pid", pid, "offset", offset, "err", err.Error())
|
||||
}
|
||||
} else {
|
||||
log.Info("rpc send success", rpcPushMsg.OperationID, "push data", rpcPushMsg.String())
|
||||
log.Info(message.OperationID, "rpc send success", rpcPushMsg.OperationID, "push data", rpcPushMsg.String())
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -64,8 +64,8 @@ func (s *groupServer) Run() {
|
||||
//Service registers with etcd
|
||||
pbGroup.RegisterGroupServer(srv, s)
|
||||
|
||||
rpcRegisterIP := ""
|
||||
if config.Config.RpcRegisterIP == "" {
|
||||
rpcRegisterIP := config.Config.RpcRegisterIP
|
||||
if rpcRegisterIP == "" {
|
||||
rpcRegisterIP, err = utils.GetLocalIP()
|
||||
if err != nil {
|
||||
log.Error("", "GetLocalIP failed ", err.Error())
|
||||
@ -76,6 +76,7 @@ func (s *groupServer) Run() {
|
||||
log.NewError("", "RegisterEtcd failed ", err.Error())
|
||||
return
|
||||
}
|
||||
log.Info("", "RegisterEtcd ", s.etcdSchema, strings.Join(s.etcdAddr, ","), rpcRegisterIP, s.rpcPort, s.rpcRegisterName)
|
||||
err = srv.Serve(listener)
|
||||
if err != nil {
|
||||
log.NewError("", "Serve failed ", err.Error())
|
||||
|
@ -33,6 +33,7 @@ type UploadUpdateAppReq struct {
|
||||
File *multipart.FileHeader `form:"file" binding:"required"`
|
||||
Yaml *multipart.FileHeader `form:"yaml"`
|
||||
ForceUpdate bool `form:"forceUpdate"`
|
||||
UpdateLog string `form:"updateLog" binding:"required"`
|
||||
}
|
||||
|
||||
type UploadUpdateAppResp struct {
|
||||
@ -52,5 +53,7 @@ type GetDownloadURLResp struct {
|
||||
ForceUpdate bool `json:"forceUpdate"`
|
||||
FileURL string `json:"fileURL"`
|
||||
YamlURL string `json:"yamlURL"`
|
||||
Version string `json:"version"`
|
||||
UpdateLog string `json:"update_log"`
|
||||
} `json:"data"`
|
||||
}
|
||||
|
@ -85,7 +85,7 @@ type config struct {
|
||||
DBMaxLifeTime int `yaml:"dbMaxLifeTime"`
|
||||
}
|
||||
Mongo struct {
|
||||
DBUri string `yaml:"dbUri"` // 当dbUri值不为空则直接使用该值
|
||||
DBUri string `yaml:"dbUri"`
|
||||
DBAddress []string `yaml:"dbAddress"`
|
||||
DBDirect bool `yaml:"dbDirect"`
|
||||
DBTimeout int `yaml:"dbTimeout"`
|
||||
|
@ -280,6 +280,7 @@ type AppVersion struct {
|
||||
ForceUpdate bool `gorm:"column:force_update" json:"force_update"`
|
||||
FileName string `gorm:"column:file_name" json:"file_name"`
|
||||
YamlName string `gorm:"column:yaml_name" json:"yaml_name"`
|
||||
UpdateLog string `gorm:"column:update_log" json:"update_log"`
|
||||
}
|
||||
|
||||
func (AppVersion) TableName() string {
|
||||
|
@ -59,7 +59,7 @@ func initMysqlDB() {
|
||||
&GroupMember{},
|
||||
&GroupRequest{},
|
||||
&User{},
|
||||
&Black{}, &ChatLog{}, &Register{}, &Conversation{})
|
||||
&Black{}, &ChatLog{}, &Register{}, &Conversation{}, &AppVersion{})
|
||||
db.Set("gorm:table_options", "CHARSET=utf8")
|
||||
db.Set("gorm:table_options", "collation=utf8_unicode_ci")
|
||||
|
||||
|
@ -5,7 +5,7 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
func UpdateAppVersion(appType int, version string, forceUpdate bool, fileName, yamlName string) error {
|
||||
func UpdateAppVersion(appType int, version string, forceUpdate bool, fileName, yamlName, updateLog string) error {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return err
|
||||
@ -18,9 +18,10 @@ func UpdateAppVersion(appType int, version string, forceUpdate bool, fileName, y
|
||||
FileName: fileName,
|
||||
YamlName: yamlName,
|
||||
ForceUpdate: forceUpdate,
|
||||
UpdateLog: updateLog,
|
||||
}
|
||||
result := dbConn.Model(db.AppVersion{}).Where("type = ?", appType).Update(map[string]interface{}{"force_update": forceUpdate,
|
||||
"version": version, "update_time": int(time.Now().Unix()), "file_name": fileName, "yaml_name": yamlName, "type": appType})
|
||||
"version": version, "update_time": int(time.Now().Unix()), "file_name": fileName, "yaml_name": yamlName, "type": appType, "update_log": updateLog})
|
||||
if result.Error != nil {
|
||||
return result.Error
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user