diff --git a/cmd/open_im_api/main.go b/cmd/open_im_api/main.go index c6fba662a..d902c2b9c 100644 --- a/cmd/open_im_api/main.go +++ b/cmd/open_im_api/main.go @@ -122,6 +122,7 @@ func main() { managementGroup.POST("/get_all_users_uid", manage.GetAllUsersUid) //1 managementGroup.POST("/account_check", manage.AccountCheck) //1 managementGroup.POST("/get_users_online_status", manage.GetUsersOnlineStatus) //1 + } //Conversation conversationGroup := r.Group("/conversation") diff --git a/config/config.yaml b/config/config.yaml index 3ea75b135..8c1ffcc1a 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -98,7 +98,8 @@ credential: #腾讯cos,发送图片、视频、文件时需要,请自行申 secretID: AKIDGNYVChzIQinu7QEgtNp0hnNgqcV8vZTC1 secretKey: kz15vW83qM6dBUWIq681eBZA0c0vlIbe1 minio: #MinIO 发送图片、视频、文件时需要,请自行申请后替换,必须修改。 客户端初始化InitSDK,中 object_storage参数为minio - bucket: openim + bucket: openim # 存储内容桶 + appBucket: app # 存储app的桶 location: us-east-1 endpoint: http://127.0.0.1:10005 #minio外网ip 这个ip是给客户端访问的 endpointInner: http://127.0.0.1:10005 #minio内网地址 如果im server 可以通过内网访问到 minio就可以填写 diff --git a/internal/api/chat/del_msg.go b/internal/api/chat/del_msg.go index 81b705953..d883f095c 100644 --- a/internal/api/chat/del_msg.go +++ b/internal/api/chat/del_msg.go @@ -25,10 +25,10 @@ func DelMsg(c *gin.Context) { c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()}) return } + log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req:", req) if err := utils.CopyStructFields(&reqPb, &req); err != nil { log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields", err.Error()) } - log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req:", req) grpcConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfflineMessageName) msgClient := pbChat.NewChatClient(grpcConn) respPb, err := msgClient.DelMsgList(context.Background(), &reqPb) @@ -39,5 +39,6 @@ func DelMsg(c *gin.Context) { } resp.ErrCode = respPb.ErrCode resp.ErrMsg = respPb.ErrMsg + log.NewInfo(req.OperationID, utils.GetSelfFuncName(), resp) c.JSON(http.StatusOK, resp) } diff --git a/internal/api/conversation/conversation.go b/internal/api/conversation/conversation.go index dcaa2b62e..2e1709847 100644 --- a/internal/api/conversation/conversation.go +++ b/internal/api/conversation/conversation.go @@ -25,13 +25,13 @@ func SetConversation(c *gin.Context) { c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "bind json failed " + err.Error()}) return } + log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req) reqPb.Conversation = &pbUser.Conversation{} err := utils.CopyStructFields(&reqPb, req) err = utils.CopyStructFields(reqPb.Conversation, req.Conversation) if err != nil { log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error()) } - log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", reqPb.String()) etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName) client := pbUser.NewUserClient(etcdConn) respPb, err := client.SetConversation(context.Background(), &reqPb) @@ -56,13 +56,13 @@ func ModifyConversationField(c *gin.Context) { c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "bind json failed " + err.Error()}) return } + log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req) reqPb.Conversation = &pbConversation.Conversation{} err := utils.CopyStructFields(&reqPb, req) err = utils.CopyStructFields(reqPb.Conversation, req.Conversation) if err != nil { log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error()) } - log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", reqPb.String()) etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImConversationName) client := pbConversation.NewConversationClient(etcdConn) respPb, err := client.ModifyConversationField(context.Background(), &reqPb) @@ -88,10 +88,10 @@ func BatchSetConversations(c *gin.Context) { c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "bind json failed " + err.Error()}) return } + log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req) if err := utils.CopyStructFields(&reqPb, req); err != nil { log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error()) } - log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", reqPb.String()) etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName) client := pbUser.NewUserClient(etcdConn) respPb, err := client.BatchSetConversations(context.Background(), &reqPb) @@ -120,10 +120,10 @@ func GetAllConversations(c *gin.Context) { c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "bind json failed " + err.Error()}) return } + log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req) if err := utils.CopyStructFields(&reqPb, req); err != nil { log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error()) } - log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", reqPb.String()) etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName) client := pbUser.NewUserClient(etcdConn) respPb, err := client.GetAllConversations(context.Background(), &reqPb) @@ -152,10 +152,10 @@ func GetConversation(c *gin.Context) { c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "bind json failed " + err.Error()}) return } + log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req) if err := utils.CopyStructFields(&reqPb, req); err != nil { log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error()) } - log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", reqPb.String()) etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName) client := pbUser.NewUserClient(etcdConn) respPb, err := client.GetConversation(context.Background(), &reqPb) @@ -184,10 +184,10 @@ func GetConversations(c *gin.Context) { c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "bind json failed " + err.Error()}) return } + log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req) if err := utils.CopyStructFields(&reqPb, req); err != nil { log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error()) } - log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", reqPb.String()) etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName) client := pbUser.NewUserClient(etcdConn) respPb, err := client.GetConversations(context.Background(), &reqPb) @@ -216,10 +216,10 @@ func SetRecvMsgOpt(c *gin.Context) { c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "bind json failed " + err.Error()}) return } + log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req) if err := utils.CopyStructFields(&reqPb, req); err != nil { log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error()) } - log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", reqPb.String()) etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName) client := pbUser.NewUserClient(etcdConn) respPb, err := client.SetRecvMsgOpt(context.Background(), &reqPb) diff --git a/internal/api/third/minio_init.go b/internal/api/third/minio_init.go index 2c00965bf..e9aa7c1aa 100644 --- a/internal/api/third/minio_init.go +++ b/internal/api/third/minio_init.go @@ -12,7 +12,7 @@ import ( ) var ( - minioClient *minio.Client + MinioClient *minio.Client ) func MinioInit() { @@ -31,7 +31,7 @@ func MinioInit() { return } log.NewInfo(operationID, utils.GetSelfFuncName(), "Parse ok ", config.Config.Credential.Minio) - minioClient, err = minio.New(minioUrl.Host, &minio.Options{ + MinioClient, err = minio.New(minioUrl.Host, &minio.Options{ Creds: credentials.NewStaticV4(config.Config.Credential.Minio.AccessKeyID, config.Config.Credential.Minio.SecretAccessKey, ""), Secure: false, }) @@ -44,10 +44,25 @@ func MinioInit() { Region: config.Config.Credential.Minio.Location, ObjectLocking: false, } - err = minioClient.MakeBucket(context.Background(), config.Config.Credential.Minio.Bucket, opt) + err = MinioClient.MakeBucket(context.Background(), config.Config.Credential.Minio.Bucket, opt) if err != nil { log.NewError(operationID, utils.GetSelfFuncName(), "MakeBucket failed ", err.Error()) - exists, err := minioClient.BucketExists(context.Background(), config.Config.Credential.Minio.Bucket) + exists, err := MinioClient.BucketExists(context.Background(), config.Config.Credential.Minio.Bucket) + if err == nil && exists { + log.NewWarn(operationID, utils.GetSelfFuncName(), "We already own ", config.Config.Credential.Minio.Bucket) + } else { + if err != nil { + log.NewError(operationID, utils.GetSelfFuncName(), err.Error()) + } + log.NewError(operationID, utils.GetSelfFuncName(), "create bucket failed and bucket not exists") + return + } + } + // make app bucket + err = MinioClient.MakeBucket(context.Background(), config.Config.Credential.Minio.AppBucket, opt) + if err != nil { + log.NewError(operationID, utils.GetSelfFuncName(), "MakeBucket failed ", err.Error()) + exists, err := MinioClient.BucketExists(context.Background(), config.Config.Credential.Minio.Bucket) if err == nil && exists { log.NewWarn(operationID, utils.GetSelfFuncName(), "We already own ", config.Config.Credential.Minio.Bucket) } else { @@ -59,7 +74,7 @@ func MinioInit() { } } // 自动化桶public的代码 - err = minioClient.SetBucketPolicy(context.Background(), config.Config.Credential.Minio.Bucket, policy.BucketPolicyReadWrite) + err = MinioClient.SetBucketPolicy(context.Background(), config.Config.Credential.Minio.Bucket, policy.BucketPolicyReadWrite) if err != nil { log.NewDebug("", utils.GetSelfFuncName(), "SetBucketPolicy failed please set in web", err.Error()) return diff --git a/internal/api/third/minio_storage_credential.go b/internal/api/third/minio_storage_credential.go index 3df001e18..d6552518a 100644 --- a/internal/api/third/minio_storage_credential.go +++ b/internal/api/third/minio_storage_credential.go @@ -33,7 +33,7 @@ func MinioUploadFile(c *gin.Context) { c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()}) return } - + log.NewInfo(req.OperationID, utils.GetSelfFuncName(), req) var ok bool var errInfo string ok, _, errInfo = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID) @@ -61,7 +61,7 @@ func MinioUploadFile(c *gin.Context) { } snapShotNewName, snapShotNewType := utils.GetNewFileNameAndContentType(snapShotFile.Filename, constant.ImageType) log.Debug(req.OperationID, utils.GetSelfFuncName(), snapShotNewName, snapShotNewType) - _, err = minioClient.PutObject(context.Background(), config.Config.Credential.Minio.Bucket, snapShotNewName, snapShotFileObj, snapShotFile.Size, minio.PutObjectOptions{ContentType: snapShotNewType}) + _, err = MinioClient.PutObject(context.Background(), config.Config.Credential.Minio.Bucket, snapShotNewName, snapShotFileObj, snapShotFile.Size, minio.PutObjectOptions{ContentType: snapShotNewType}) if err != nil { log.NewError(req.OperationID, utils.GetSelfFuncName(), "PutObject snapShotFile error", err.Error()) c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()}) @@ -72,6 +72,7 @@ func MinioUploadFile(c *gin.Context) { } 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 } @@ -83,10 +84,10 @@ func MinioUploadFile(c *gin.Context) { } newName, newType := utils.GetNewFileNameAndContentType(file.Filename, req.FileType) log.Debug(req.OperationID, utils.GetSelfFuncName(), newName, newType) - _, err = minioClient.PutObject(context.Background(), config.Config.Credential.Minio.Bucket, newName, fileObj, file.Size, minio.PutObjectOptions{ContentType: newType}) + _, err = MinioClient.PutObject(context.Background(), config.Config.Credential.Minio.Bucket, newName, fileObj, file.Size, minio.PutObjectOptions{ContentType: newType}) if err != nil { - log.NewError(req.OperationID, utils.GetSelfFuncName(), "open file error") - c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "invalid file path" + err.Error()}) + log.NewError(req.OperationID, utils.GetSelfFuncName(), "upload file error") + c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "upload file error" + err.Error()}) return } resp.NewName = newName @@ -106,7 +107,7 @@ func MinioStorageCredential(c *gin.Context) { c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()}) return } - + log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req) var ok bool var errInfo string ok, _, errInfo = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID) diff --git a/internal/api/user/user.go b/internal/api/user/user.go index f9bb9cdae..6be7ed710 100644 --- a/internal/api/user/user.go +++ b/internal/api/user/user.go @@ -26,21 +26,18 @@ func GetUsersInfoFromCache(c *gin.Context) { c.JSON(http.StatusBadRequest, gin.H{"errCode": http.StatusBadRequest, "errMsg": err.Error()}) return } + log.NewInfo(params.OperationID, "GetUsersInfoFromCache req: ", params) req := &rpc.GetUserInfoReq{} utils.CopyStructFields(req, ¶ms) - var ok bool var errInfo string ok, req.OpUserID, errInfo = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID) if !ok { - errMsg := req.OperationID + " " + "GetUserIDFromToken failed " + errInfo + " token:" + c.Request.Header.Get("token") + errMsg := "GetUserIDFromToken failed " + errInfo + " token:" + c.Request.Header.Get("token") log.NewError(req.OperationID, errMsg) c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg}) return } - - log.NewInfo(params.OperationID, "GetUserInfo args ", req.String()) - etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName) client := rpc.NewUserClient(etcdConn) RpcResp, err := client.GetUserInfo(context.Background(), req) @@ -54,117 +51,12 @@ func GetUsersInfoFromCache(c *gin.Context) { publicUserInfoList = append(publicUserInfoList, &open_im_sdk.PublicUserInfo{UserID: v.UserID, Nickname: v.Nickname, FaceURL: v.FaceURL, Gender: v.Gender, Ex: v.Ex}) } - resp := api.GetUsersInfoResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}, UserInfoList: publicUserInfoList} resp.Data = jsonData.JsonDataList(resp.UserInfoList) log.NewInfo(req.OperationID, "GetUserInfo api return ", resp) c.JSON(http.StatusOK, resp) } -//func GetUsersInfoFromCache(c *gin.Context) { -// params := api.GetUsersInfoReq{} -// if err := c.BindJSON(¶ms); err != nil { -// log.NewError("0", "BindJSON failed ", err.Error()) -// c.JSON(http.StatusBadRequest, gin.H{"errCode": http.StatusBadRequest, "errMsg": err.Error()}) -// return -// } -// getUserInfoReq := &rpc.GetUserInfoReq{} -// getUserInfoReq.OperationID = params.OperationID -// var ok bool -// ok, getUserInfoReq.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), getUserInfoReq.OperationID) -// if !ok { -// log.NewError(getUserInfoReq.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token")) -// c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"}) -// return -// } -// log.NewInfo(params.OperationID, "GetUserInfo args ", getUserInfoReq.String()) -// reqCacheGetUserInfo := &cacheRpc.GetUserInfoFromCacheReq{} -// utils.CopyStructFields(reqCacheGetUserInfo, ¶ms) -// var userInfoList []*open_im_sdk.UserInfo -// var publicUserInfoList []*open_im_sdk.PublicUserInfo -// etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName) -// cacheClient := cacheRpc.NewCacheClient(etcdConn) -// cacheResp, err := cacheClient.GetUserInfoFromCache(context.Background(), reqCacheGetUserInfo) -// if err != nil { -// log.NewError(getUserInfoReq.OperationID, utils.GetSelfFuncName(), "GetUserInfo failed", err.Error()) -// c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call rpc server failed: " + err.Error()}) -// return -// } -// if cacheResp.CommonResp.ErrCode != 0 { -// log.NewError(getUserInfoReq.OperationID, utils.GetSelfFuncName(), "GetUserInfo failed", cacheResp.CommonResp) -// resp := api.GetUsersInfoResp{CommResp: api.CommResp{ErrCode: cacheResp.CommonResp.ErrCode, ErrMsg: cacheResp.CommonResp.ErrMsg}} -// resp.Data = []map[string]interface{}{} -// log.NewInfo(getUserInfoReq.OperationID, "GetUserInfo api return ", resp) -// c.JSON(http.StatusOK, resp) -// return -// } -// log.NewInfo(getUserInfoReq.OperationID, utils.GetSelfFuncName(), "cacheResp:", cacheResp.String()) -// userInfoList = cacheResp.UserInfoList -// var needCacheUserIDList []string -// for _, userID := range reqCacheGetUserInfo.UserIDList { -// isGetUserInfoFromCache := false -// for _, cacheUser := range userInfoList { -// if cacheUser.UserID == userID { -// isGetUserInfoFromCache = true -// } -// } -// if !isGetUserInfoFromCache { -// needCacheUserIDList = append(needCacheUserIDList, userID) -// } -// } -// if len(needCacheUserIDList) == 0 { -// log.NewInfo(getUserInfoReq.OperationID, utils.GetSelfFuncName(), "get all userInfo from cache success") -// for _, v := range userInfoList { -// publicUserInfoList = append(publicUserInfoList, -// &open_im_sdk.PublicUserInfo{UserID: v.UserID, Nickname: v.Nickname, FaceURL: v.FaceURL, Gender: v.Gender, Ex: v.Ex}) -// } -// resp := api.GetUsersInfoResp{CommResp: api.CommResp{ErrCode: cacheResp.CommonResp.ErrCode, ErrMsg: cacheResp.CommonResp.ErrMsg}, UserInfoList: publicUserInfoList} -// resp.Data = jsonData.JsonDataList(resp.UserInfoList) -// log.NewInfo(getUserInfoReq.OperationID, "GetUserInfo api return ", resp) -// c.JSON(http.StatusOK, resp) -// return -// } -// -// log.NewDebug(getUserInfoReq.OperationID, utils.GetSelfFuncName(), "need cache user list", needCacheUserIDList) -// getUserInfoReq.UserIDList = needCacheUserIDList -// etcdConn = getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName) -// client := rpc.NewUserClient(etcdConn) -// rpcResp, err := client.GetUserInfo(context.Background(), getUserInfoReq) -// if err != nil { -// log.NewError(getUserInfoReq.OperationID, "GetUserInfo failed ", err.Error(), getUserInfoReq.String()) -// c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call rpc server failed" + err.Error()}) -// return -// } -// if rpcResp.CommonResp.ErrCode != 0 { -// log.NewError(getUserInfoReq.OperationID, utils.GetSelfFuncName(), "GetUserInfo failed", cacheResp.CommonResp) -// resp := api.GetUsersInfoResp{CommResp: api.CommResp{ErrCode: cacheResp.CommonResp.ErrCode, ErrMsg: cacheResp.CommonResp.ErrMsg}} -// resp.Data = []map[string]interface{}{} -// log.NewInfo(getUserInfoReq.OperationID, "GetUserInfo api return ", resp) -// c.JSON(http.StatusOK, resp) -// return -// } -// userInfoList = append(userInfoList, rpcResp.UserInfoList...) -// cacheUpdateUserInfoReq := &cacheRpc.UpdateUserInfoToCacheReq{ -// UserInfoList: rpcResp.UserInfoList, -// OperationID: getUserInfoReq.OperationID, -// } -// _, err = cacheClient.UpdateUserInfoToCache(context.Background(), cacheUpdateUserInfoReq) -// if err != nil { -// log.NewError(getUserInfoReq.OperationID, "GetUserInfo failed ", err.Error()) -// c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call rpc server failed:" + err.Error()}) -// return -// } -// userInfoList = rpcResp.UserInfoList -// for _, v := range userInfoList { -// publicUserInfoList = append(publicUserInfoList, -// &open_im_sdk.PublicUserInfo{UserID: v.UserID, Nickname: v.Nickname, FaceURL: v.FaceURL, Gender: v.Gender, Ex: v.Ex}) -// } -// resp := api.GetUsersInfoResp{CommResp: api.CommResp{ErrCode: rpcResp.CommonResp.ErrCode, ErrMsg: rpcResp.CommonResp.ErrMsg}, UserInfoList: publicUserInfoList} -// resp.Data = jsonData.JsonDataList(resp.UserInfoList) -// log.NewInfo(getUserInfoReq.OperationID, "GetUserInfo api return ", resp) -// c.JSON(http.StatusOK, resp) -//} - func GetFriendIDListFromCache(c *gin.Context) { var ( req api.GetFriendIDListFromCacheReq @@ -177,18 +69,17 @@ func GetFriendIDListFromCache(c *gin.Context) { c.JSON(http.StatusBadRequest, gin.H{"errCode": http.StatusBadRequest, "errMsg": err.Error()}) return } + log.NewInfo(req.OperationID, utils.GetSelfFuncName(), req) reqPb.OperationID = req.OperationID - var ok bool var errInfo string ok, reqPb.UserID, errInfo = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID) if !ok { - errMsg := req.OperationID + " " + "GetUserIDFromToken failed " + errInfo + " token:" + c.Request.Header.Get("token") + errMsg := "GetUserIDFromToken failed " + errInfo + " token:" + c.Request.Header.Get("token") log.NewError(req.OperationID, errMsg) c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg}) return } - etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName) client := cacheRpc.NewCacheClient(etcdConn) respPb, err := client.GetFriendIDListFromCache(context.Background(), &reqPb) @@ -214,8 +105,8 @@ func GetBlackIDListFromCache(c *gin.Context) { c.JSON(http.StatusBadRequest, gin.H{"errCode": http.StatusBadRequest, "errMsg": err.Error()}) return } + log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req) reqPb.OperationID = req.OperationID - var ok bool var errInfo string ok, reqPb.UserID, errInfo = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID) @@ -225,7 +116,6 @@ func GetBlackIDListFromCache(c *gin.Context) { c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg}) return } - etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName) client := cacheRpc.NewCacheClient(etcdConn) respPb, err := client.GetBlackIDListFromCache(context.Background(), &reqPb) diff --git a/internal/cms_api/admin/admin.go b/internal/cms_api/admin/admin.go index 02b2390c5..eb5ccd156 100644 --- a/internal/cms_api/admin/admin.go +++ b/internal/cms_api/admin/admin.go @@ -1,25 +1,29 @@ package admin import ( - "Open_IM/pkg/cms_api_struct" + 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" + "github.com/minio/minio-go/v7" + "net/http" "strings" + "Open_IM/internal/api/third" "github.com/gin-gonic/gin" ) // register func AdminLogin(c *gin.Context) { var ( - req cms_api_struct.AdminLoginRequest - resp cms_api_struct.AdminLoginResponse + req apiStruct.AdminLoginRequest + resp apiStruct.AdminLoginResponse reqPb pbAdmin.AdminLoginReq ) if err := c.BindJSON(&req); err != nil { @@ -40,3 +44,87 @@ 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("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) + newFileName, newYamlName, err := utils.GetUploadAppNewName(req.Type, req.Version) + 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() + yamlObj, err := req.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 + } + log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "name: ", newFileName, newYamlName) + // v2.0.9_app_linux v2.0.9_yaml_linux + _, err = apiThird.MinioClient.PutObject(context.Background(), config.Config.Credential.Minio.AppBucket, newFileName, fileObj, req.File.Size, minio.PutObjectOptions{}) + _, err = apiThird.MinioClient.PutObject(context.Background(), config.Config.Credential.Minio.AppBucket, newYamlName, yamlObj, req.Yaml.Size, minio.PutObjectOptions{}) + if err != nil { + log.NewError(req.OperationID, utils.GetSelfFuncName(), "open file error") + c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "invalid file path" + err.Error()}) + return + } + if err := imdb.UpdateAppVersion(req.Type, req.Version, req.ForceUpdate); 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) + fileName, yamlName, err := utils.GetUploadAppNewName(req.Type, req.Version) + 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 + } + app, err := imdb.GetNewestVersion(req.Type) + if err != nil { + log.NewError(req.OperationID, utils.GetSelfFuncName(), "getNewestVersion failed", err.Error()) + c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "getNewestVersion failed" + err.Error()}) + return + } + if app.Version != req.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 + "/" + yamlName + resp.Data.FileURL = config.Config.Credential.Minio.Endpoint + "/" + config.Config.Credential.Minio.AppBucket + "/" + fileName + c.JSON(http.StatusOK, resp) + } else { + resp.Data.HasNewVersion = false + c.JSON(http.StatusOK, resp) + } +} diff --git a/internal/cms_api/group/group.go b/internal/cms_api/group/group.go index 740fd5821..69b9e32fc 100644 --- a/internal/cms_api/group/group.go +++ b/internal/cms_api/group/group.go @@ -28,6 +28,7 @@ func GetGroupById(c *gin.Context) { openIMHttp.RespHttp200(c, constant.ErrArgs, nil) return } + log.NewInfo("", utils.GetSelfFuncName(), "req: ", req) reqPb.GroupId = req.GroupId etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName) client := pbGroup.NewGroupClient(etcdConn) @@ -44,6 +45,7 @@ func GetGroupById(c *gin.Context) { resp.GroupMasterName = respPb.CMSGroup.GroupMasterName resp.GroupMasterId = respPb.CMSGroup.GroupMasterId resp.IsBanChat = constant.GroupIsBanChat(respPb.CMSGroup.GroupInfo.Status) + log.NewInfo("", utils.GetSelfFuncName(), "req: ", resp) openIMHttp.RespHttp200(c, constant.OK, resp) } @@ -58,6 +60,7 @@ func GetGroups(c *gin.Context) { openIMHttp.RespHttp200(c, constant.ErrArgs, nil) return } + log.NewInfo("", utils.GetSelfFuncName(), "req: ", req) reqPb.Pagination = &commonPb.RequestPagination{} utils.CopyStructFields(&reqPb.Pagination, req) etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName) @@ -83,6 +86,7 @@ func GetGroups(c *gin.Context) { resp.GroupNums = int(respPb.GroupNum) resp.CurrentPage = int(respPb.Pagination.PageNumber) resp.ShowNumber = int(respPb.Pagination.ShowNumber) + log.NewInfo("", utils.GetSelfFuncName(), "resp: ", resp) openIMHttp.RespHttp200(c, constant.OK, resp) } @@ -97,6 +101,7 @@ func GetGroupByName(c *gin.Context) { openIMHttp.RespHttp200(c, constant.ErrArgs, nil) return } + log.NewInfo("", utils.GetSelfFuncName(), "req: ", req) reqPb.GroupName = req.GroupName reqPb.Pagination = &commonPb.RequestPagination{} utils.CopyStructFields(&reqPb.Pagination, req) @@ -123,6 +128,7 @@ func GetGroupByName(c *gin.Context) { resp.CurrentPage = int(respPb.Pagination.PageNumber) resp.ShowNumber = int(respPb.Pagination.ShowNumber) resp.GroupNums = int(respPb.GroupNums) + log.NewInfo("", utils.GetSelfFuncName(), "resp: ", resp) openIMHttp.RespHttp200(c, constant.OK, resp) } @@ -137,6 +143,7 @@ func CreateGroup(c *gin.Context) { openIMHttp.RespHttp200(c, constant.ErrArgs, nil) return } + log.NewInfo("", utils.GetSelfFuncName(), "req: ", req) reqPb.GroupInfo = &commonPb.GroupInfo{} reqPb.GroupInfo.GroupName = req.GroupName reqPb.GroupInfo.CreatorUserID = req.GroupMasterId @@ -169,6 +176,7 @@ func BanGroupChat(c *gin.Context) { openIMHttp.RespHttp200(c, constant.ErrArgs, nil) return } + log.NewInfo("", utils.GetSelfFuncName(), "req: ", req) reqPb.GroupId = req.GroupId reqPb.Status = constant.GroupBanChat etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName) @@ -193,6 +201,7 @@ func BanPrivateChat(c *gin.Context) { openIMHttp.RespHttp200(c, constant.ErrArgs, nil) return } + log.NewInfo("", utils.GetSelfFuncName(), "req: ", req) reqPb.GroupId = req.GroupId reqPb.Status = constant.GroupBanPrivateChat etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName) @@ -216,6 +225,7 @@ func OpenGroupChat(c *gin.Context) { openIMHttp.RespHttp200(c, constant.ErrArgs, nil) return } + log.NewInfo("", utils.GetSelfFuncName(), "req: ", req) reqPb.GroupId = req.GroupId reqPb.Status = constant.GroupOk etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName) @@ -239,6 +249,7 @@ func OpenPrivateChat(c *gin.Context) { openIMHttp.RespHttp200(c, constant.ErrArgs, nil) return } + log.NewInfo("", utils.GetSelfFuncName(), "req: ", req) reqPb.GroupId = req.GroupId reqPb.Status = constant.GroupOk etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName) @@ -263,6 +274,7 @@ func GetGroupMembers(c *gin.Context) { openIMHttp.RespHttp200(c, constant.ErrArgs, nil) return } + log.NewInfo("", utils.GetSelfFuncName(), "req: ", req) reqPb.Pagination = &commonPb.RequestPagination{ PageNumber: int32(req.PageNumber), ShowNumber: int32(req.ShowNumber), @@ -290,6 +302,7 @@ func GetGroupMembers(c *gin.Context) { JoinTime: utils.UnixSecondToTime(int64(groupMembers.JoinTime)).String(), }) } + log.NewInfo("", utils.GetSelfFuncName(), "req: ", resp) openIMHttp.RespHttp200(c, constant.OK, resp) } @@ -304,6 +317,7 @@ func AddGroupMembers(c *gin.Context) { openIMHttp.RespHttp200(c, constant.ErrArgs, nil) return } + log.NewInfo("", utils.GetSelfFuncName(), "req: ", req) reqPb.UserIds = req.Members reqPb.GroupId = req.GroupId etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName) @@ -316,6 +330,7 @@ func AddGroupMembers(c *gin.Context) { } resp.Success = respPb.Success resp.Failed = respPb.Failed + log.NewInfo("", utils.GetSelfFuncName(), "resp: ", resp) openIMHttp.RespHttp200(c, constant.OK, resp) } @@ -330,6 +345,7 @@ func RemoveGroupMembers(c *gin.Context) { openIMHttp.RespHttp200(c, constant.ErrArgs, nil) return } + log.NewInfo("", utils.GetSelfFuncName(), "req: ", req) reqPb.UserIds = req.Members reqPb.GroupId = req.GroupId etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName) @@ -342,6 +358,7 @@ func RemoveGroupMembers(c *gin.Context) { } resp.Success = respPb.Success resp.Failed = respPb.Failed + log.NewInfo("", utils.GetSelfFuncName(), "req: ", resp) openIMHttp.RespHttp200(c, constant.OK, resp) } @@ -356,6 +373,7 @@ func DeleteGroup(c *gin.Context) { openIMHttp.RespHttp200(c, constant.ErrArgs, nil) return } + log.NewInfo("", utils.GetSelfFuncName(), "req: ", req) reqPb.GroupId = req.GroupId etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName) client := pbGroup.NewGroupClient(etcdConn) @@ -379,6 +397,7 @@ func SetGroupMaster(c *gin.Context) { openIMHttp.RespHttp200(c, constant.ErrArgs, nil) return } + log.NewInfo("", utils.GetSelfFuncName(), "req: ", req) reqPb.GroupId = req.GroupId reqPb.UserId = req.UserId reqPb.RoleLevel = constant.GroupOwner @@ -404,6 +423,7 @@ func SetGroupOrdinaryUsers(c *gin.Context) { openIMHttp.RespHttp200(c, constant.ErrArgs, nil) return } + log.NewInfo("", utils.GetSelfFuncName(), "req: ", req) reqPb.GroupId = req.GroupId reqPb.UserId = req.UserId reqPb.RoleLevel = constant.GroupOrdinaryUsers @@ -424,6 +444,7 @@ func AlterGroupInfo(c *gin.Context) { _ cms_api_struct.SetGroupMasterResponse reqPb pbGroup.SetGroupInfoReq ) + log.NewInfo("", utils.GetSelfFuncName(), "req: ", req) if err := c.BindJSON(&req); err != nil { log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "BindJSON failed ", err.Error()) openIMHttp.RespHttp200(c, constant.ErrArgs, nil) diff --git a/internal/cms_api/message_cms/message.go b/internal/cms_api/message_cms/message.go index c5ced390e..0a56bb99a 100644 --- a/internal/cms_api/message_cms/message.go +++ b/internal/cms_api/message_cms/message.go @@ -78,6 +78,7 @@ func GetChatLogs(c *gin.Context) { ShowNumber: int32(req.ShowNumber), } utils.CopyStructFields(&reqPb, &req) + log.NewInfo("", utils.GetSelfFuncName(), "req: ", req) etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImMessageCMSName) client := pbMessage.NewMessageCMSClient(etcdConn) respPb, err := client.GetChatLogs(context.Background(), &reqPb) @@ -105,5 +106,6 @@ func GetChatLogs(c *gin.Context) { resp.ShowNumber = int(respPb.Pagination.ShowNumber) resp.CurrentPage = int(respPb.Pagination.CurrentPage) resp.ChatLogsNum = int(respPb.ChatLogsNum) + log.NewInfo("", utils.GetSelfFuncName(), "resp", resp) openIMHttp.RespHttp200(c, constant.OK, resp) } diff --git a/internal/cms_api/router.go b/internal/cms_api/router.go index a0221d536..fbd3b9fcc 100644 --- a/internal/cms_api/router.go +++ b/internal/cms_api/router.go @@ -20,6 +20,8 @@ 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()) diff --git a/internal/cms_api/statistics/statistics.go b/internal/cms_api/statistics/statistics.go index c8a9488ca..89fb6056b 100644 --- a/internal/cms_api/statistics/statistics.go +++ b/internal/cms_api/statistics/statistics.go @@ -27,6 +27,7 @@ func GetMessagesStatistics(c *gin.Context) { openIMHttp.RespHttp200(c, constant.ErrArgs, nil) return } + log.NewInfo("", utils.GetSelfFuncName(), "req: ", req) utils.CopyStructFields(&reqPb.StatisticsReq, &req) etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImStatisticsName) client := pb.NewUserClient(etcdConn) @@ -57,6 +58,7 @@ func GetMessagesStatistics(c *gin.Context) { MessageNum: int(v.Num), }) } + log.NewInfo("", utils.GetSelfFuncName(), "resp: ", resp) openIMHttp.RespHttp200(c, constant.OK, resp) } @@ -72,6 +74,7 @@ func GetUserStatistics(c *gin.Context) { openIMHttp.RespHttp200(c, constant.ErrArgs, nil) return } + log.NewInfo("", utils.GetSelfFuncName(), "req: ", req) utils.CopyStructFields(&reqPb.StatisticsReq, &req) etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImStatisticsName) client := pb.NewUserClient(etcdConn) @@ -112,6 +115,7 @@ func GetUserStatistics(c *gin.Context) { TotalUserNum: int(v.Num), }) } + log.NewInfo("", utils.GetSelfFuncName(), "resp: ", resp) openIMHttp.RespHttp200(c, constant.OK, resp) } @@ -127,6 +131,7 @@ func GetGroupStatistics(c *gin.Context) { openIMHttp.RespHttp200(c, constant.ErrArgs, nil) return } + log.NewInfo("", utils.GetSelfFuncName(), "req: ", req) utils.CopyStructFields(&reqPb.StatisticsReq, &req) etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImStatisticsName) client := pb.NewUserClient(etcdConn) @@ -160,6 +165,7 @@ func GetGroupStatistics(c *gin.Context) { }) } + log.NewInfo("", utils.GetSelfFuncName(), "resp: ", resp) openIMHttp.RespHttp200(c, constant.OK, resp) } @@ -175,6 +181,7 @@ func GetActiveUser(c *gin.Context) { openIMHttp.RespHttp200(c, constant.ErrArgs, nil) return } + log.NewInfo("", utils.GetSelfFuncName(), "req: ", req) utils.CopyStructFields(&reqPb.StatisticsReq, req) etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImStatisticsName) client := pb.NewUserClient(etcdConn) @@ -185,6 +192,7 @@ func GetActiveUser(c *gin.Context) { return } utils.CopyStructFields(&resp.ActiveUserList, respPb.Users) + log.NewInfo("", utils.GetSelfFuncName(), "resp: ", resp) openIMHttp.RespHttp200(c, constant.OK, resp) } @@ -200,6 +208,7 @@ func GetActiveGroup(c *gin.Context) { openIMHttp.RespHttp200(c, constant.ErrArgs, nil) return } + log.NewInfo("", utils.GetSelfFuncName(), "req: ", req) utils.CopyStructFields(&reqPb.StatisticsReq, req) etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImStatisticsName) client := pb.NewUserClient(etcdConn) @@ -220,5 +229,6 @@ func GetActiveGroup(c *gin.Context) { MessageNum: int(group.MessageNum), }) } + log.NewInfo("", utils.GetSelfFuncName(), "resp: ", resp) openIMHttp.RespHttp200(c, constant.OK, resp) } diff --git a/internal/cms_api/user/user.go b/internal/cms_api/user/user.go index a0e5dc188..f8d96e35e 100644 --- a/internal/cms_api/user/user.go +++ b/internal/cms_api/user/user.go @@ -29,6 +29,7 @@ func GetUserById(c *gin.Context) { openIMHttp.RespHttp200(c, constant.ErrArgs, nil) return } + log.NewInfo("", utils.GetSelfFuncName(), "req: ", req) utils.CopyStructFields(&reqPb, &req) etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName) client := pb.NewUserClient(etcdConn) @@ -43,15 +44,17 @@ func GetUserById(c *gin.Context) { return } utils.CopyStructFields(&resp, respPb.User) + log.NewInfo("", utils.GetSelfFuncName(), "resp: ", resp) openIMHttp.RespHttp200(c, constant.OK, resp) } func GetUsersByName(c *gin.Context) { var ( - req cms_api_struct.GetUsersByNameRequest - resp cms_api_struct.GetUsersByNameResponse + req cms_api_struct.GetUsersByNameRequest + resp cms_api_struct.GetUsersByNameResponse reqPb pb.GetUsersByNameReq ) + log.NewInfo("", utils.GetSelfFuncName(), "req: ", req) if err := c.ShouldBindQuery(&req); err != nil { log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "ShouldBindQuery failed", err.Error()) openIMHttp.RespHttp200(c, constant.ErrArgs, nil) @@ -74,6 +77,7 @@ func GetUsersByName(c *gin.Context) { resp.ShowNumber = int(respPb.Pagination.ShowNumber) resp.CurrentPage = int(respPb.Pagination.CurrentPage) resp.UserNums = respPb.UserNums + log.NewInfo("", utils.GetSelfFuncName(), "resp: ", resp) openIMHttp.RespHttp200(c, constant.OK, resp) } @@ -89,6 +93,7 @@ func GetUsers(c *gin.Context) { openIMHttp.RespHttp200(c, constant.ErrArgs, nil) return } + log.NewInfo("", utils.GetSelfFuncName(), "req: ", req) utils.CopyStructFields(&reqPb.Pagination, &req) etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName) client := pb.NewUserClient(etcdConn) @@ -101,6 +106,7 @@ func GetUsers(c *gin.Context) { resp.ShowNumber = int(respPb.Pagination.ShowNumber) resp.CurrentPage = int(respPb.Pagination.CurrentPage) resp.UserNums = respPb.UserNums + log.NewInfo("", utils.GetSelfFuncName(), "resp: ", resp) openIMHttp.RespHttp200(c, constant.OK, resp) } @@ -116,14 +122,15 @@ func ResignUser(c *gin.Context) { c.JSON(http.StatusBadRequest, gin.H{"errCode": http.StatusBadRequest, "errMsg": err.Error()}) return } + log.NewInfo("", utils.GetSelfFuncName(), "req: ", req) utils.CopyStructFields(&reqPb, &req) - fmt.Println(reqPb.UserId) etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName) client := pb.NewUserClient(etcdConn) _, err := client.ResignUser(context.Background(), &reqPb) if err != nil { openIMHttp.RespHttp200(c, err, resp) } + log.NewInfo("", utils.GetSelfFuncName(), "resp: ", resp) openIMHttp.RespHttp200(c, constant.OK, resp) } @@ -138,6 +145,7 @@ func AlterUser(c *gin.Context) { openIMHttp.RespHttp200(c, constant.ErrArgs, resp) return } + log.NewInfo("", utils.GetSelfFuncName(), "req: ", req) utils.CopyStructFields(&reqPb, &req) etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName) client := pb.NewUserClient(etcdConn) @@ -159,6 +167,7 @@ func AddUser(c *gin.Context) { openIMHttp.RespHttp200(c, constant.ErrArgs, nil) return } + log.NewInfo("", utils.GetSelfFuncName(), "req: ", req) utils.CopyStructFields(&reqPb, &req) etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName) client := pb.NewUserClient(etcdConn) @@ -182,6 +191,7 @@ func BlockUser(c *gin.Context) { openIMHttp.RespHttp200(c, constant.ErrArgs, resp) return } + log.NewInfo("", utils.GetSelfFuncName(), "req: ", req) utils.CopyStructFields(&reqPb, &req) etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName) client := pb.NewUserClient(etcdConn) @@ -205,6 +215,7 @@ func UnblockUser(c *gin.Context) { openIMHttp.RespHttp200(c, constant.ErrArgs, resp) return } + log.NewInfo("", utils.GetSelfFuncName(), "req: ", req) utils.CopyStructFields(&reqPb, &req) etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName) client := pb.NewUserClient(etcdConn) @@ -213,6 +224,7 @@ func UnblockUser(c *gin.Context) { openIMHttp.RespHttp200(c, err, resp) return } + log.NewInfo("", utils.GetSelfFuncName(), "resp: ", resp) openIMHttp.RespHttp200(c, constant.OK, resp) } @@ -229,6 +241,7 @@ func GetBlockUsers(c *gin.Context) { openIMHttp.RespHttp200(c, constant.ErrArgs, resp) return } + log.NewInfo("", utils.GetSelfFuncName(), "req: ", req) utils.CopyStructFields(&reqPb.Pagination, &req) log.NewInfo(reqPb.OperationID, utils.GetSelfFuncName(), "blockUsers", reqPb.Pagination, req) etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName) @@ -255,6 +268,7 @@ func GetBlockUsers(c *gin.Context) { resp.ShowNumber = int(respPb.Pagination.ShowNumber) resp.CurrentPage = int(respPb.Pagination.CurrentPage) resp.UserNums = respPb.UserNums + log.NewInfo("", utils.GetSelfFuncName(), "req: ", resp) openIMHttp.RespHttp200(c, constant.OK, resp) } @@ -269,6 +283,7 @@ func GetBlockUserById(c *gin.Context) { openIMHttp.RespHttp200(c, constant.ErrArgs, nil) return } + log.NewInfo("", utils.GetSelfFuncName(), "req: ", req) reqPb.UserId = req.UserId etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName) client := pb.NewUserClient(etcdConn) @@ -281,6 +296,7 @@ func GetBlockUserById(c *gin.Context) { resp.EndDisableTime = respPb.BlockUser.EndDisableTime resp.BeginDisableTime = respPb.BlockUser.BeginDisableTime utils.CopyStructFields(&resp, respPb.BlockUser.User) + log.NewInfo("", utils.GetSelfFuncName(), "resp: ", resp) openIMHttp.RespHttp200(c, constant.OK, resp) } @@ -294,6 +310,7 @@ func DeleteUser(c *gin.Context) { openIMHttp.RespHttp200(c, constant.ErrArgs, nil) return } + log.NewInfo("", utils.GetSelfFuncName(), "req: ", req) reqPb.UserId = req.UserId etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName) client := pb.NewUserClient(etcdConn) diff --git a/internal/rpc/admin_cms/admin_cms.go b/internal/rpc/admin_cms/admin_cms.go index 3a3f7dffd..8c3754b74 100644 --- a/internal/rpc/admin_cms/admin_cms.go +++ b/internal/rpc/admin_cms/admin_cms.go @@ -96,5 +96,6 @@ func (s *adminCMSServer) AdminLogin(_ context.Context, req *pbAdminCMS.AdminLogi log.NewError(req.OperationID, utils.GetSelfFuncName(), "failed") return resp, openIMHttp.WrapError(constant.ErrTokenMalformed) } + log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String()) return resp, nil } diff --git a/internal/rpc/cache/cache.go b/internal/rpc/cache/cache.go index 2cf6f33d0..8a5526930 100644 --- a/internal/rpc/cache/cache.go +++ b/internal/rpc/cache/cache.go @@ -90,6 +90,7 @@ func SyncDB2Cache() error { var err error log.NewInfo("0", utils.GetSelfFuncName()) userList, err := imdb.GetAllUser() + log.NewDebug("", utils.GetSelfFuncName(), "userList", userList) if err != nil { return utils.Wrap(err, "") } @@ -118,10 +119,10 @@ func updateAllUserToCache(userList []db.User) error { } m, err := utils.Pb2Map(userInfoPb) if err != nil { - log.NewError("", utils.GetSelfFuncName(), err.Error()) + log.NewWarn("", utils.GetSelfFuncName(), err.Error()) } if err := db.DB.SetUserInfoToCache(userInfo.UserID, m); err != nil { - log.NewError("0", utils.GetSelfFuncName(), "set userInfo to cache failed", err.Error()) + log.NewWarn("0", utils.GetSelfFuncName(), "set userInfo to cache failed", err.Error()) } } log.NewInfo("0", utils.GetSelfFuncName(), "ok") @@ -132,19 +133,19 @@ func updateAllGroupMemberListToCache() error { log.NewInfo("0", utils.GetSelfFuncName()) groupIDList, err := imdb.GetAllGroupIDList() if err != nil { - log.NewError("0", utils.GetSelfFuncName(), "getAllGroupIDList failed", err.Error()) + log.NewWarn("0", utils.GetSelfFuncName(), "getAllGroupIDList failed", err.Error()) panic(err.Error()) } for _, groupID := range groupIDList { groupMemberIDList, err := imdb.GetGroupMemberIDListByGroupID(groupID) if err != nil { - log.NewError("", utils.GetSelfFuncName(), "GetGroupMemberIDListByGroupID", err.Error()) + log.NewWarn("", utils.GetSelfFuncName(), "GetGroupMemberIDListByGroupID", err.Error()) continue } //log.NewDebug("", utils.GetSelfFuncName(), "groupMemberIDList", groupMemberIDList) if len(groupMemberIDList) > 0 { if err := db.DB.AddGroupMemberToCache(groupID, groupMemberIDList...); err != nil { - log.NewError("", utils.GetSelfFuncName(), "AddGroupMemberToCache", err.Error()) + log.NewWarn("", utils.GetSelfFuncName(), "AddGroupMemberToCache", err.Error()) } } } @@ -157,13 +158,12 @@ func updateAllFriendToCache(userList []db.User) error { for _, user := range userList { friendIDList, err := imdb.GetFriendIDListByUserID(user.UserID) if err != nil { - log.NewError("0", utils.GetSelfFuncName(), err.Error()) + log.NewWarn("0", utils.GetSelfFuncName(), err.Error()) continue } - //log.NewDebug("", utils.GetSelfFuncName(), "friendIDList", user.UserID, friendIDList) if len(friendIDList) > 0 { if err := db.DB.AddFriendToCache(user.UserID, friendIDList...); err != nil { - log.NewError("0", utils.GetSelfFuncName(), err.Error(), friendIDList, user.UserID) + log.NewWarn("0", utils.GetSelfFuncName(), err.Error(), friendIDList, user.UserID) } } } @@ -176,13 +176,12 @@ func updateAllBlackListToCache(userList []db.User) error { for _, user := range userList { blackIDList, err := imdb.GetBlackIDListByUserID(user.UserID) if err != nil { - log.NewError("", utils.GetSelfFuncName(), err.Error()) + log.NewWarn("", utils.GetSelfFuncName(), err.Error()) continue } - //log.NewDebug("", utils.GetSelfFuncName(), "updateAllBlackListToCache", user.UserID, blackIDList) if len(blackIDList) > 0 { if err := db.DB.AddBlackUserToCache(user.UserID, blackIDList...); err != nil { - log.NewError("0", utils.GetSelfFuncName(), err.Error()) + log.NewWarn("0", utils.GetSelfFuncName(), err.Error()) } } } diff --git a/internal/rpc/group/group.go b/internal/rpc/group/group.go index c9f63cac3..d5e5ed602 100644 --- a/internal/rpc/group/group.go +++ b/internal/rpc/group/group.go @@ -593,7 +593,7 @@ func (s *groupServer) GetGroupsInfo(ctx context.Context, req *pbGroup.GetGroupsI } resp := pbGroup.GetGroupsInfoResp{GroupInfoList: groupsInfoList} - log.NewInfo(req.OperationID, "GetGroupsInfo rpc return ", resp) + log.NewInfo(req.OperationID, "GetGroupsInfo rpc return ", resp.String()) return &resp, nil } @@ -991,7 +991,8 @@ func (s *groupServer) GetGroups(_ context.Context, req *pbGroup.GetGroupsReq) (* for _, v := range groups { groupMember, err := imdb.GetGroupMaster(v.GroupID) if err != nil { - log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error()) + log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupMaster failed", err.Error(), v) + continue } resp.CMSGroups = append(resp.CMSGroups, &pbGroup.CMSGroup{ GroupInfo: &open_im_sdk.GroupInfo{ @@ -1007,7 +1008,7 @@ func (s *groupServer) GetGroups(_ context.Context, req *pbGroup.GetGroupsReq) (* GroupMasterName: groupMember.Nickname, }) } - + log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "GetGroups ", resp.String()) return resp, nil } @@ -1087,6 +1088,7 @@ func (s *groupServer) GetGroupMembersCMS(_ context.Context, req *pbGroup.GetGrou CurrentPage: req.Pagination.PageNumber, ShowNumber: req.Pagination.ShowNumber, } + log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp:", resp.String()) return resp, nil } diff --git a/internal/rpc/message_cms/message_cms.go b/internal/rpc/message_cms/message_cms.go index 40609de7c..907b60112 100644 --- a/internal/rpc/message_cms/message_cms.go +++ b/internal/rpc/message_cms/message_cms.go @@ -110,6 +110,7 @@ func (s *messageCMSServer) GetChatLogs(_ context.Context, req *pbMessageCMS.GetC chatLog.RecvID = req.GroupId chatLog.SendID = req.UserId } + log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "chat_log: ", chatLog) nums, err := imdb.GetChatLogCount(chatLog) resp.ChatLogsNum = int32(nums) if err != nil { diff --git a/internal/rpc/msg/del_msg.go b/internal/rpc/msg/del_msg.go index d8b28b847..17610a384 100644 --- a/internal/rpc/msg/del_msg.go +++ b/internal/rpc/msg/del_msg.go @@ -12,13 +12,6 @@ import ( func (rpc *rpcChat) DelMsgList(_ context.Context, req *commonPb.DelMsgListReq) (*commonPb.DelMsgListResp, error) { log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String()) resp := &commonPb.DelMsgListResp{} - //if err := db.DB.DelMsgLogic(req.UserID, req.SeqList, req.OperationID); err != nil { - // log.NewError(req.OperationID, utils.GetSelfFuncName(), "DelMsg failed", err.Error()) - // resp.ErrMsg = constant.ErrDB.ErrMsg - // resp.ErrCode = constant.ErrDB.ErrCode - // return resp, nil - //} - if err := db.DB.DelMsgBySeqList(req.UserID, req.SeqList, req.OperationID); err != nil { log.NewError(req.OperationID, utils.GetSelfFuncName(), "DelMsg failed", err.Error()) resp.ErrMsg = constant.ErrDB.ErrMsg diff --git a/internal/rpc/office/office.go b/internal/rpc/office/office.go index 46e8a0cba..069e3d029 100644 --- a/internal/rpc/office/office.go +++ b/internal/rpc/office/office.go @@ -147,10 +147,10 @@ func (s *officeServer) DeleteTag(_ context.Context, req *pbOffice.DeleteTagReq) func (s *officeServer) SetTag(_ context.Context, req *pbOffice.SetTagReq) (resp *pbOffice.SetTagResp, err error) { log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String()) resp = &pbOffice.SetTagResp{CommonResp: &pbOffice.CommonResp{}} - IncreaseUserIDList := utils.RemoveRepeatedStringInList(req.IncreaseUserIDList) + increaseUserIDList := utils.RemoveRepeatedStringInList(req.IncreaseUserIDList) reduceUserIDList := utils.RemoveRepeatedStringInList(req.ReduceUserIDList) - if err := db.DB.SetTag(req.UserID, req.TagID, req.NewName, IncreaseUserIDList, reduceUserIDList); err != nil { - log.NewError(req.OperationID, utils.GetSelfFuncName(), "SetTag failed", err.Error()) + if err := db.DB.SetTag(req.UserID, req.TagID, req.NewName, increaseUserIDList, reduceUserIDList); err != nil { + log.NewError(req.OperationID, utils.GetSelfFuncName(), "SetTag failed", increaseUserIDList, reduceUserIDList, err.Error()) resp.CommonResp.ErrMsg = constant.ErrDB.ErrMsg resp.CommonResp.ErrCode = constant.ErrDB.ErrCode return resp, nil @@ -175,13 +175,13 @@ func (s *officeServer) SendMsg2Tag(_ context.Context, req *pbOffice.SendMsg2TagR for _, groupID := range req.GroupList { userIDList, err := im_mysql_model.GetGroupMemberIDListByGroupID(groupID) if err != nil { - log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupMemberIDListByGroupID failed", err.Error()) + log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupMemberIDListByGroupID failed", err.Error(), groupID) continue } log.NewDebug(req.OperationID, utils.GetSelfFuncName(), userIDList) groupUserIDList = append(groupUserIDList, userIDList...) } - log.NewInfo(req.OperationID, utils.GetSelfFuncName(), groupUserIDList, req.GroupList) + log.NewDebug(req.OperationID, utils.GetSelfFuncName(), groupUserIDList, req.GroupList) var userIDList []string userIDList = append(userIDList, tagUserIDList...) userIDList = append(userIDList, groupUserIDList...) @@ -192,13 +192,13 @@ func (s *officeServer) SendMsg2Tag(_ context.Context, req *pbOffice.SendMsg2TagR userIDList = append(userIDList[:i], userIDList[i+1:]...) } } - log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "total userIDList result: ", userIDList) - us, err := imdb.GetUserByUserID(req.SendID) + log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "total userIDList result: ", userIDList) + user, err := imdb.GetUserByUserID(req.SendID) if err != nil { log.NewError(req.OperationID, "GetUserByUserID failed ", err.Error(), req.SendID) } for _, userID := range userIDList { - msg.TagSendMessage(req.OperationID, us, userID, req.Content, req.SenderPlatformID) + msg.TagSendMessage(req.OperationID, user, userID, req.Content, req.SenderPlatformID) } var tagSendLogs db.TagSendLog for _, userID := range userIDList { @@ -217,7 +217,7 @@ func (s *officeServer) SendMsg2Tag(_ context.Context, req *pbOffice.SendMsg2TagR tagSendLogs.SenderPlatformID = req.SenderPlatformID tagSendLogs.SendTime = time.Now().Unix() if err := db.DB.SaveTagSendLog(&tagSendLogs); err != nil { - log.NewError(req.OperationID, utils.GetSelfFuncName(), "SaveTagSendLog failed", err.Error()) + log.NewError(req.OperationID, utils.GetSelfFuncName(), "SaveTagSendLog failed", tagSendLogs, err.Error()) resp.CommonResp.ErrCode = constant.ErrDB.ErrCode resp.CommonResp.ErrMsg = constant.ErrDB.ErrMsg return resp, nil diff --git a/internal/rpc/statistics/statistics.go b/internal/rpc/statistics/statistics.go index d7100c50d..69b5545eb 100644 --- a/internal/rpc/statistics/statistics.go +++ b/internal/rpc/statistics/statistics.go @@ -89,13 +89,14 @@ func (s *statisticsServer) Run() { } func (s *statisticsServer) GetActiveGroup(_ context.Context, req *pbStatistics.GetActiveGroupReq) (*pbStatistics.GetActiveGroupResp, error) { - log.NewInfo(req.OperationID, utils.GetSelfFuncName(), req.String()) + log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req", req.String()) resp := &pbStatistics.GetActiveGroupResp{} fromTime, toTime, err := ParseTimeFromTo(req.StatisticsReq.From, req.StatisticsReq.To) if err != nil { log.NewError(req.OperationID, utils.GetSelfFuncName(), "ParseTimeFromTo failed", err.Error()) return resp, errors.WrapError(constant.ErrArgs) } + log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "time: ", fromTime, toTime) activeGroups, err := imdb.GetActiveGroups(fromTime, toTime, 12) if err != nil { log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetActiveGroups failed", err.Error()) @@ -109,6 +110,7 @@ func (s *statisticsServer) GetActiveGroup(_ context.Context, req *pbStatistics.G MessageNum: int32(activeGroup.MessageNum), }) } + log.NewInfo(req.OperationID, utils.GetSelfFuncName(), resp.String()) return resp, nil } @@ -120,6 +122,7 @@ func (s *statisticsServer) GetActiveUser(_ context.Context, req *pbStatistics.Ge log.NewError(req.OperationID, utils.GetSelfFuncName(), "ParseTimeFromTo failed", err.Error()) return resp, errors.WrapError(constant.ErrDB) } + log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "time: ", fromTime, toTime) activeUsers, err := imdb.GetActiveUsers(fromTime, toTime, 12) if err != nil { log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetActiveUsers failed", err.Error()) @@ -134,6 +137,7 @@ func (s *statisticsServer) GetActiveUser(_ context.Context, req *pbStatistics.Ge }, ) } + log.NewInfo(req.OperationID, utils.GetSelfFuncName(), resp.String()) return resp, nil } @@ -233,7 +237,7 @@ func (s *statisticsServer) GetGroupStatistics(_ context.Context, req *pbStatisti } increaseGroupNum, err := imdb.GetIncreaseGroupNum(fromTime, toTime.Add(time.Hour*24)) if err != nil { - log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetIncreaseGroupNum failed", err.Error()) + log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetIncreaseGroupNum failed", err.Error(), fromTime, toTime) return resp, errors.WrapError(constant.ErrDB) } totalGroupNum, err := imdb.GetTotalGroupNum() @@ -244,7 +248,7 @@ func (s *statisticsServer) GetGroupStatistics(_ context.Context, req *pbStatisti resp.IncreaseGroupNum = increaseGroupNum resp.TotalGroupNum = totalGroupNum times := GetRangeDate(fromTime, toTime) - log.NewInfo(req.OperationID, "times:", times) + log.NewDebug(req.OperationID, "times:", times) wg := &sync.WaitGroup{} resp.IncreaseGroupNumList = make([]*pbStatistics.DateNumList, len(times), len(times)) resp.TotalGroupNumList = make([]*pbStatistics.DateNumList, len(times), len(times)) @@ -271,6 +275,7 @@ func (s *statisticsServer) GetGroupStatistics(_ context.Context, req *pbStatisti }(wg, i, v) } wg.Wait() + log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp) return resp, nil } @@ -278,6 +283,7 @@ func (s *statisticsServer) GetMessageStatistics(_ context.Context, req *pbStatis log.NewInfo(req.OperationID, utils.GetSelfFuncName(), req.String()) resp := &pbStatistics.GetMessageStatisticsResp{} fromTime, toTime, err := ParseTimeFromTo(req.StatisticsReq.From, req.StatisticsReq.To) + log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "times: ", fromTime, toTime) if err != nil { log.NewError(req.OperationID, utils.GetSelfFuncName(), "ParseTimeFromTo failed", err.Error()) return resp, errors.WrapError(constant.ErrArgs) @@ -292,6 +298,7 @@ func (s *statisticsServer) GetMessageStatistics(_ context.Context, req *pbStatis log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupMessageNum failed", err.Error()) return resp, errors.WrapError(constant.ErrDB) } + log.NewDebug(req.OperationID, utils.GetSelfFuncName(), privateMessageNum, groupMessageNum) resp.PrivateMessageNum = privateMessageNum resp.GroupMessageNum = groupMessageNum times := GetRangeDate(fromTime, toTime) @@ -326,7 +333,7 @@ func (s *statisticsServer) GetMessageStatistics(_ context.Context, req *pbStatis } func (s *statisticsServer) GetUserStatistics(_ context.Context, req *pbStatistics.GetUserStatisticsReq) (*pbStatistics.GetUserStatisticsResp, error) { - log.NewInfo(req.OperationID, utils.GetSelfFuncName(), req.String()) + log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String()) resp := &pbStatistics.GetUserStatisticsResp{} fromTime, toTime, err := ParseTimeFromTo(req.StatisticsReq.From, req.StatisticsReq.To) if err != nil { @@ -388,5 +395,6 @@ func (s *statisticsServer) GetUserStatistics(_ context.Context, req *pbStatistic }(wg, i, v) } wg.Wait() + log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp) return resp, nil } diff --git a/internal/rpc/user/user.go b/internal/rpc/user/user.go index abb3b0a34..6c62f8add 100644 --- a/internal/rpc/user/user.go +++ b/internal/rpc/user/user.go @@ -16,7 +16,6 @@ import ( pbUser "Open_IM/pkg/proto/user" "Open_IM/pkg/utils" "context" - "fmt" "net" "strconv" "strings" @@ -171,6 +170,7 @@ func (s *userServer) GetAllConversations(ctx context.Context, req *pbUser.GetAll log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String()) resp := &pbUser.GetAllConversationsResp{Conversations: []*pbUser.Conversation{}} conversations, err := imdb.GetUserAllConversations(req.OwnerUserID) + log.NewDebug(req.OperationID, "conversations: ", conversations) if err != nil { log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetConversations error", err.Error()) resp.CommonResp = &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg} @@ -188,6 +188,7 @@ func (s *userServer) GetConversation(ctx context.Context, req *pbUser.GetConvers log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String()) resp := &pbUser.GetConversationResp{Conversation: &pbUser.Conversation{}} conversation, err := imdb.GetConversation(req.OwnerUserID, req.ConversationID) + log.NewDebug("", utils.GetSelfFuncName(), "conversation", conversation) if err != nil { log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetConversation error", err.Error()) resp.CommonResp = &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg} @@ -205,6 +206,7 @@ func (s *userServer) GetConversations(ctx context.Context, req *pbUser.GetConver log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String()) resp := &pbUser.GetConversationsResp{Conversations: []*pbUser.Conversation{}} conversations, err := imdb.GetConversations(req.OwnerUserID, req.ConversationIDs) + log.NewDebug("", utils.GetSelfFuncName(), "conversations", conversations) if err != nil { log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetConversations error", err.Error()) resp.CommonResp = &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg} @@ -232,6 +234,7 @@ func (s *userServer) SetConversation(ctx context.Context, req *pbUser.SetConvers return resp, nil } if groupInfo.Status == constant.GroupStatusDismissed && !req.Conversation.IsNotInGroup { + log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "group status is dismissed", groupInfo) errMsg := "group status is dismissed" resp.CommonResp = &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg} return resp, nil @@ -444,6 +447,7 @@ func (s *userServer) GetUsersByName(ctx context.Context, req *pbUser.GetUsersByN CurrentPage: req.Pagination.PageNumber, ShowNumber: req.Pagination.ShowNumber, } + log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp) return resp, nil } @@ -467,6 +471,7 @@ func (s *userServer) GetUserById(ctx context.Context, req *pbUser.GetUserByIdReq CreateTime: user.CreateTime.String(), IsBlock: isBlock, } + log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String()) return resp, nil } @@ -475,6 +480,7 @@ func (s *userServer) GetUsers(ctx context.Context, req *pbUser.GetUsersReq) (*pb resp := &pbUser.GetUsersResp{User: []*pbUser.User{}} users, err := imdb.GetUsers(req.Pagination.ShowNumber, req.Pagination.PageNumber) if err != nil { + log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUsers failed", err.Error()) return resp, errors.WrapError(constant.ErrDB) } for _, v := range users { @@ -488,16 +494,19 @@ func (s *userServer) GetUsers(ctx context.Context, req *pbUser.GetUsersReq) (*pb IsBlock: isBlock, } resp.User = append(resp.User, user) + } else { + log.NewError(req.OperationID, utils.GetSelfFuncName(), "UserIsBlock failed", err.Error()) } } user := db.User{} nums, err := imdb.GetUsersCount(user) if err != nil { - log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUsersCount failed", err.Error()) + log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUsersCount failed", err.Error(), user) return resp, errors.WrapError(constant.ErrDB) } resp.UserNums = nums resp.Pagination = &sdkws.ResponsePagination{ShowNumber: req.Pagination.ShowNumber, CurrentPage: req.Pagination.PageNumber} + log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String()) return resp, nil } @@ -507,7 +516,7 @@ func (s *userServer) ResignUser(ctx context.Context, req *pbUser.ResignUserReq) } func (s *userServer) AlterUser(ctx context.Context, req *pbUser.AlterUserReq) (*pbUser.AlterUserResp, error) { - log.NewInfo(req.OperationID, "AlterUser args ", req.String()) + log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String()) resp := &pbUser.AlterUserResp{} user := db.User{ PhoneNumber: strconv.FormatInt(req.PhoneNumber, 10), @@ -520,11 +529,12 @@ func (s *userServer) AlterUser(ctx context.Context, req *pbUser.AlterUserReq) (* return resp, errors.WrapError(constant.ErrDB) } chat.UserInfoUpdatedNotification(req.OperationID, req.UserId, req.OpUserId) + log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String()) return resp, nil } func (s *userServer) AddUser(ctx context.Context, req *pbUser.AddUserReq) (*pbUser.AddUserResp, error) { - log.NewInfo(req.OperationID, "AddUser args ", req.String()) + log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String()) resp := &pbUser.AddUserResp{} err := imdb.AddUser(req.UserId, req.PhoneNumber, req.Name) if err != nil { @@ -535,8 +545,7 @@ func (s *userServer) AddUser(ctx context.Context, req *pbUser.AddUserReq) (*pbUs } func (s *userServer) BlockUser(ctx context.Context, req *pbUser.BlockUserReq) (*pbUser.BlockUserResp, error) { - log.NewInfo(req.OperationID, "BlockUser args ", req.String()) - fmt.Println("BlockUser args ", req.String()) + log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String()) resp := &pbUser.BlockUserResp{} err := imdb.BlockUser(req.UserId, req.EndDisableTime) if err != nil { @@ -547,7 +556,7 @@ func (s *userServer) BlockUser(ctx context.Context, req *pbUser.BlockUserReq) (* } func (s *userServer) UnBlockUser(ctx context.Context, req *pbUser.UnBlockUserReq) (*pbUser.UnBlockUserResp, error) { - log.NewInfo(req.OperationID, "UnBlockUser args ", req.String()) + log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String()) resp := &pbUser.UnBlockUserResp{} err := imdb.UnBlockUser(req.UserId) if err != nil { @@ -558,7 +567,7 @@ func (s *userServer) UnBlockUser(ctx context.Context, req *pbUser.UnBlockUserReq } func (s *userServer) GetBlockUsers(ctx context.Context, req *pbUser.GetBlockUsersReq) (*pbUser.GetBlockUsersResp, error) { - log.NewInfo(req.OperationID, "GetBlockUsers args ", req.String()) + log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String()) resp := &pbUser.GetBlockUsersResp{} blockUsers, err := imdb.GetBlockUsers(req.Pagination.ShowNumber, req.Pagination.PageNumber) if err != nil { @@ -586,11 +595,12 @@ func (s *userServer) GetBlockUsers(ctx context.Context, req *pbUser.GetBlockUser return resp, errors.WrapError(constant.ErrDB) } resp.UserNums = nums + log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp) return resp, nil } func (s *userServer) GetBlockUserById(_ context.Context, req *pbUser.GetBlockUserByIdReq) (*pbUser.GetBlockUserByIdResp, error) { - log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "GetBlockUserById args ", req.String()) + log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String()) resp := &pbUser.GetBlockUserByIdResp{} user, err := imdb.GetBlockUserById(req.UserId) if err != nil { @@ -607,6 +617,7 @@ func (s *userServer) GetBlockUserById(_ context.Context, req *pbUser.GetBlockUse BeginDisableTime: (user.BeginDisableTime).String(), EndDisableTime: (user.EndDisableTime).String(), } + log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", req.String()) return resp, nil } diff --git a/pkg/cms_api_struct/admin.go b/pkg/cms_api_struct/admin.go index 54674662e..e06a04324 100644 --- a/pkg/cms_api_struct/admin.go +++ b/pkg/cms_api_struct/admin.go @@ -1,10 +1,44 @@ package cms_api_struct +import ( + apiStruct "Open_IM/pkg/base_info" + "mime/multipart" +) + type AdminLoginRequest struct { AdminName string `json:"admin_name" binding:"required"` - Secret string `json:"secret" binding:"required"` + Secret string `json:"secret" binding:"required"` } type AdminLoginResponse struct { Token string `json:"token"` -} \ No newline at end of file +} + +type UploadUpdateAppReq struct { + OperationID string `form:"operationID" binding:"required"` + Type int `form:"type" binding:"required"` + Version string `form:"version" binding:"required"` + File multipart.FileHeader `form:"file" binding:"required"` + Yaml multipart.FileHeader `form:"yaml" binding:"required"` + ForceUpdate bool `form:"forceUpdate" binding:"required"` +} + +type UploadUpdateAppResp struct { + apiStruct.CommResp +} + +type GetDownloadURLReq struct { + OperationID string `json:"operationID" binding:"required"` + Type int `json:"type" binding:"required"` + Version string `json:"version" binding:"required"` +} + +type GetDownloadURLResp struct { + apiStruct.CommResp + Data struct { + HasNewVersion bool `json:"hasNewVersion"` + ForceUpdate bool `json:"forceUpdate"` + FileURL string `json:"fileURL"` + YamlURL string `json:"yamlURL"` + } `json:"data"` +} diff --git a/pkg/common/config/config.go b/pkg/common/config/config.go index 972cf27c1..478d1ba6d 100644 --- a/pkg/common/config/config.go +++ b/pkg/common/config/config.go @@ -63,6 +63,7 @@ type config struct { } Minio struct { Bucket string `yaml:"bucket"` + AppBucket string `yaml:"appBucket"` Location string `yaml:"location"` Endpoint string `yaml:"endpoint"` AccessKeyID string `yaml:"accessKeyID"` diff --git a/pkg/common/db/model_struct.go b/pkg/common/db/model_struct.go index 9e50a8fc6..6ed3f2dc1 100644 --- a/pkg/common/db/model_struct.go +++ b/pkg/common/db/model_struct.go @@ -272,3 +272,14 @@ type DepartmentMember struct { func (DepartmentMember) TableName() string { return "department_members" } + +type AppVersion struct { + Version string `gorm:"column:user_id;size:64"` + Type int `gorm:"column:user_id;primary_key"` + UpdateTime int `gorm:"column:update_time"` + ForceUpdate bool `gorm:"column:force_update"` +} + +func (AppVersion) TableName() string { + return "app_version" +} diff --git a/pkg/common/db/mysql.go b/pkg/common/db/mysql.go index cfef4dfee..bde529293 100644 --- a/pkg/common/db/mysql.go +++ b/pkg/common/db/mysql.go @@ -119,7 +119,10 @@ func initMysqlDB() { fmt.Println("CreateTable DepartmentMember") db.CreateTable(&DepartmentMember{}) } - + if !db.HasTable(&AppVersion{}) { + fmt.Println("CreateTable DepartmentMember") + db.CreateTable(&AppVersion{}) + } return } diff --git a/pkg/common/db/mysql_model/im_mysql_model/file_model.go b/pkg/common/db/mysql_model/im_mysql_model/file_model.go new file mode 100644 index 000000000..8265ee9de --- /dev/null +++ b/pkg/common/db/mysql_model/im_mysql_model/file_model.go @@ -0,0 +1,38 @@ +package im_mysql_model + +import ( + "Open_IM/pkg/common/db" + "time" +) + +func UpdateAppVersion(appType int, version string, forceUpdate bool) error { + dbConn, err := db.DB.MysqlDB.DefaultGormDB() + if err != nil { + return err + } + app := db.AppVersion{ + Version: version, + Type: appType, + UpdateTime: int(time.Now().Unix()), + ForceUpdate: forceUpdate, + } + result := dbConn.Model(db.AppVersion{}).Where("app_type = ?", appType).Updates(&app) + if result.Error != nil { + return result.Error + } + if result.RowsAffected == 0 { + err := dbConn.Create(&app).Error + return err + } + return nil +} + +func GetNewestVersion(appType int) (*db.AppVersion, error) { + dbConn, err := db.DB.MysqlDB.DefaultGormDB() + if err != nil { + return nil, err + } + dbConn.LogMode(true) + app := db.AppVersion{} + return &app, dbConn.Model(db.AppVersion{}).First(&app, appType).Error +} diff --git a/pkg/utils/file.go b/pkg/utils/file.go index e46050516..c5db776d0 100644 --- a/pkg/utils/file.go +++ b/pkg/utils/file.go @@ -2,6 +2,7 @@ package utils import ( "Open_IM/pkg/common/constant" + "errors" "fmt" "math/rand" "os" @@ -37,3 +38,33 @@ func GetNewFileNameAndContentType(fileName string, fileType int) (string, string } return newName, contentType } + +func GetUploadAppNewName(appType int, version string) (string, string, error) { + var newFileName, newYamlName = version + "_app_", version + "_yaml_" + switch appType { + case constant.IOSPlatformID: + newFileName += constant.IOSPlatformStr + newYamlName += constant.IOSPlatformStr + case constant.AndroidPlatformID: + newFileName += constant.AndroidPlatformStr + newYamlName += constant.AndroidPlatformStr + case constant.WindowsPlatformID: + newFileName += constant.WindowsPlatformStr + newYamlName += constant.WindowsPlatformStr + case constant.OSXPlatformID: + newFileName += constant.OSXPlatformStr + newYamlName += constant.OSXPlatformStr + case constant.WebPlatformID: + newFileName += constant.WebPlatformStr + newYamlName += constant.WebPlatformStr + case constant.MiniWebPlatformID: + newFileName += constant.MiniWebPlatformStr + newYamlName += constant.MiniWebPlatformStr + case constant.LinuxPlatformID: + newFileName += constant.LinuxPlatformStr + newYamlName += constant.LinuxPlatformStr + default: + return "", "", errors.New("invalid app type") + } + return newFileName, newYamlName, nil +}