diff --git a/.github/workflows/chatci.yml b/.github/workflows/chatci.yml index b4ef74eb..e6c1b7a8 100644 --- a/.github/workflows/chatci.yml +++ b/.github/workflows/chatci.yml @@ -36,7 +36,7 @@ jobs: # name: openim strategy: matrix: - arch: [arm64, armv7, amd64] + arch: [amd64] steps: - uses: actions/checkout@v3 diff --git a/go.mod b/go.mod index 723dd02e..b66f01b2 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,6 @@ require ( github.com/golang/protobuf v1.5.4 // indirect github.com/google/uuid v1.6.0 github.com/jinzhu/copier v0.4.0 // indirect - github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible // indirect github.com/pkg/errors v0.9.1 // indirect google.golang.org/grpc v1.62.1 google.golang.org/protobuf v1.33.0 @@ -26,8 +25,8 @@ require ( github.com/livekit/protocol v1.10.1 github.com/mitchellh/mapstructure v1.5.0 github.com/openimsdk/gomake v0.0.14-alpha.5 - github.com/openimsdk/protocol v0.0.63 - github.com/openimsdk/tools v0.0.49-alpha.24 + github.com/openimsdk/protocol v0.0.72-alpha.38 + github.com/openimsdk/tools v0.0.50-alpha.15 github.com/redis/go-redis/v9 v9.5.1 github.com/spf13/cobra v1.8.0 github.com/spf13/viper v1.18.2 diff --git a/go.sum b/go.sum index 6587e0cd..2af777e3 100644 --- a/go.sum +++ b/go.sum @@ -187,10 +187,10 @@ github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OS github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/openimsdk/gomake v0.0.14-alpha.5 h1:VY9c5x515lTfmdhhPjMvR3BBRrRquAUCFsz7t7vbv7Y= github.com/openimsdk/gomake v0.0.14-alpha.5/go.mod h1:PndCozNc2IsQIciyn9mvEblYWZwJmAI+06z94EY+csI= -github.com/openimsdk/protocol v0.0.63 h1:9DnweZe9nEYDFa4fGTbC9Cqi0gLUdtBhRo1NRP2X3WQ= -github.com/openimsdk/protocol v0.0.63/go.mod h1:OZQA9FR55lseYoN2Ql1XAHYKHJGu7OMNkUbuekrKCM8= -github.com/openimsdk/tools v0.0.49-alpha.24 h1:lJsqnjTPujnr91LRQ6QmcTliMIa4fMOBSTri6rFz2ek= -github.com/openimsdk/tools v0.0.49-alpha.24/go.mod h1:g7mkHXYUPi0/8aAX8VPMHpnb3hqdV69Jph+bXOGvvNM= +github.com/openimsdk/protocol v0.0.72-alpha.38 h1:v0GLgS9cNm627NSG3B2k2VF2AMoo90DSKixxiBMKPS4= +github.com/openimsdk/protocol v0.0.72-alpha.38/go.mod h1:OZQA9FR55lseYoN2Ql1XAHYKHJGu7OMNkUbuekrKCM8= +github.com/openimsdk/tools v0.0.50-alpha.15 h1:HV9aKZ4vvCZCGG4wFDsgUONkkdJeCcrFNn3BT52nUVQ= +github.com/openimsdk/tools v0.0.50-alpha.15/go.mod h1:h1cYmfyaVtgFbKmb1Cfsl8XwUOMTt8ubVUQrdGtsUh4= github.com/pelletier/go-toml/v2 v2.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6/MHO4= github.com/pelletier/go-toml/v2 v2.1.0/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc= github.com/pion/datachannel v1.5.5 h1:10ef4kwdjije+M9d7Xm9im2Y3O6A6ccQb0zcqZcJew8= diff --git a/internal/api/admin/admin.go b/internal/api/admin/admin.go index 96f15974..28031ee0 100644 --- a/internal/api/admin/admin.go +++ b/internal/api/admin/admin.go @@ -72,7 +72,7 @@ func (o *Api) AdminLogin(c *gin.Context) { return } imAdminUserID := o.GetDefaultIMAdminUserID() - imToken, err := o.imApiCaller.UserToken(c, imAdminUserID, constant.AdminPlatformID) + imToken, err := o.imApiCaller.AdminToken(c, imAdminUserID) if err != nil { apiresp.GinError(c, err) return @@ -127,7 +127,7 @@ func (o *Api) AdminUpdateInfo(c *gin.Context) { } imAdminUserID := o.GetDefaultIMAdminUserID() - imToken, err := o.imApiCaller.UserToken(c, imAdminUserID, constant.AdminPlatformID) + imToken, err := o.imApiCaller.AdminToken(c, imAdminUserID) if err != nil { log.ZError(c, "AdminUpdateInfo ImAdminTokenWithDefaultAdmin", err, "imAdminUserID", imAdminUserID) return @@ -207,7 +207,7 @@ func (o *Api) AddDefaultGroup(c *gin.Context) { apiresp.GinError(c, err) return } - imToken, err := o.imApiCaller.UserToken(c, o.GetDefaultIMAdminUserID(), constant.AdminPlatformID) + imToken, err := o.imApiCaller.AdminToken(c, o.GetDefaultIMAdminUserID()) if err != nil { apiresp.GinError(c, err) return @@ -255,7 +255,7 @@ func (o *Api) SearchDefaultGroup(c *gin.Context) { Groups: make([]*sdkws.GroupInfo, 0, len(searchResp.GroupIDs)), } if len(searchResp.GroupIDs) > 0 { - imToken, err := o.imApiCaller.UserToken(c, o.GetDefaultIMAdminUserID(), constant.AdminPlatformID) + imToken, err := o.imApiCaller.AdminToken(c, o.GetDefaultIMAdminUserID()) if err != nil { apiresp.GinError(c, err) return @@ -337,7 +337,7 @@ func (o *Api) BlockUser(c *gin.Context) { apiresp.GinError(c, err) return } - imToken, err := o.imApiCaller.UserToken(c, o.GetDefaultIMAdminUserID(), constant.AdminPlatformID) + imToken, err := o.imApiCaller.AdminToken(c, o.GetDefaultIMAdminUserID()) if err != nil { apiresp.GinError(c, err) return @@ -396,7 +396,7 @@ func (o *Api) NewUserCount(c *gin.Context) { apiresp.GinError(c, err) return } - imToken, err := o.imApiCaller.UserToken(c, o.GetDefaultIMAdminUserID(), constant.AdminPlatformID) + imToken, err := o.imApiCaller.AdminToken(c, o.GetDefaultIMAdminUserID()) if err != nil { apiresp.GinError(c, err) return diff --git a/internal/api/chat/chat.go b/internal/api/chat/chat.go index 94fd36d4..131c8539 100644 --- a/internal/api/chat/chat.go +++ b/internal/api/chat/chat.go @@ -146,7 +146,7 @@ func (o *Api) RegisterUser(c *gin.Context) { } var resp apistruct.UserRegisterResp if req.AutoLogin { - resp.ImToken, err = o.imApiCaller.UserToken(c, respRegisterUser.UserID, req.Platform) + resp.ImToken, err = o.imApiCaller.GetUserToken(apiCtx, respRegisterUser.UserID, req.Platform) if err != nil { apiresp.GinError(c, err) return @@ -174,7 +174,14 @@ func (o *Api) Login(c *gin.Context) { apiresp.GinError(c, err) return } - imToken, err := o.imApiCaller.UserToken(c, resp.UserID, req.Platform) + adminToken, err := o.imApiCaller.ImAdminTokenWithDefaultAdmin(c) + if err != nil { + apiresp.GinError(c, err) + return + } + apiCtx := mctx.WithApiToken(c, adminToken) + + imToken, err := o.imApiCaller.GetUserToken(apiCtx, resp.UserID, req.Platform) if err != nil { apiresp.GinError(c, err) return @@ -237,7 +244,7 @@ func (o *Api) UpdateUserInfo(c *gin.Context) { if opUserType == constant.NormalUser { imToken, err = o.imApiCaller.ImAdminTokenWithDefaultAdmin(c) } else if opUserType == constant.AdminUser { - imToken, err = o.imApiCaller.UserToken(c, o.GetDefaultIMAdminUserID(), constantpb.AdminPlatformID) + imToken, err = o.imApiCaller.AdminToken(c, o.GetDefaultIMAdminUserID()) } else { apiresp.GinError(c, errs.ErrArgs.WrapMsg("opUserType unknown")) return diff --git a/pkg/common/cmd/root.go b/pkg/common/cmd/root.go index 7c4a3075..9e06bf16 100644 --- a/pkg/common/cmd/root.go +++ b/pkg/common/cmd/root.go @@ -16,9 +16,10 @@ package cmd import ( "fmt" - "github.com/openimsdk/chat/pkg/common/config" "path/filepath" + "github.com/openimsdk/chat/pkg/common/config" + "github.com/openimsdk/tools/errs" "github.com/openimsdk/tools/log" "github.com/spf13/cobra" @@ -117,9 +118,11 @@ func (r *RootCmd) applyOptions(opts ...func(*CmdOpts)) *CmdOpts { } func (r *RootCmd) initializeLogger(cmdOpts *CmdOpts) error { - err := log.InitFromConfig( + err := log.InitLoggerFromConfig( cmdOpts.loggerPrefixName, r.processName, + "", + "", r.log.RemainLogLevel, r.log.IsStdout, r.log.IsJson, @@ -127,6 +130,7 @@ func (r *RootCmd) initializeLogger(cmdOpts *CmdOpts) error { r.log.RemainRotationCount, r.log.RotationTime, config.Version, + false, ) if err != nil { return errs.Wrap(err) diff --git a/pkg/common/imapi/api.go b/pkg/common/imapi/api.go index 6d5aff2f..3586a960 100644 --- a/pkg/common/imapi/api.go +++ b/pkg/common/imapi/api.go @@ -16,21 +16,22 @@ package imapi import ( "github.com/openimsdk/protocol/auth" - "github.com/openimsdk/protocol/friend" "github.com/openimsdk/protocol/group" + "github.com/openimsdk/protocol/relation" "github.com/openimsdk/protocol/user" ) // im caller. var ( - importFriend = NewApiCaller[friend.ImportFriendReq, friend.ImportFriendResp]("/friend/import_friend") + importFriend = NewApiCaller[relation.ImportFriendReq, relation.ImportFriendResp]("/friend/import_friend") userToken = NewApiCaller[auth.UserTokenReq, auth.UserTokenResp]("/auth/user_token") + getuserToken = NewApiCaller[auth.GetUserTokenReq, auth.GetUserTokenResp]("/auth/get_user_token") inviteToGroup = NewApiCaller[group.InviteUserToGroupReq, group.InviteUserToGroupResp]("/group/invite_user_to_group") updateUserInfo = NewApiCaller[user.UpdateUserInfoReq, user.UpdateUserInfoResp]("/user/update_user_info") registerUser = NewApiCaller[user.UserRegisterReq, user.UserRegisterResp]("/user/user_register") forceOffLine = NewApiCaller[auth.ForceLogoutReq, auth.ForceLogoutResp]("/auth/force_logout") getGroupsInfo = NewApiCaller[group.GetGroupsInfoReq, group.GetGroupsInfoResp]("/group/get_groups_info") registerUserCount = NewApiCaller[user.UserRegisterCountReq, user.UserRegisterCountResp]("/statistics/user/register") - friendUserIDs = NewApiCaller[friend.GetFriendIDsReq, friend.GetFriendIDsResp]("/friend/get_friend_id") + friendUserIDs = NewApiCaller[relation.GetFriendIDsReq, relation.GetFriendIDsResp]("/friend/get_friend_id") accountCheck = NewApiCaller[user.AccountCheckReq, user.AccountCheckResp]("/user/account_check") ) diff --git a/pkg/common/imapi/caller.go b/pkg/common/imapi/caller.go index c6ca3f1e..e0573fae 100644 --- a/pkg/common/imapi/caller.go +++ b/pkg/common/imapi/caller.go @@ -23,9 +23,10 @@ import ( "github.com/openimsdk/tools/log" "github.com/openimsdk/protocol/auth" + "github.com/openimsdk/protocol/constant" constantpb "github.com/openimsdk/protocol/constant" - "github.com/openimsdk/protocol/friend" "github.com/openimsdk/protocol/group" + "github.com/openimsdk/protocol/relation" "github.com/openimsdk/protocol/sdkws" "github.com/openimsdk/protocol/user" ) @@ -33,7 +34,8 @@ import ( type CallerInterface interface { ImAdminTokenWithDefaultAdmin(ctx context.Context) (string, error) ImportFriend(ctx context.Context, ownerUserID string, friendUserID []string) error - UserToken(ctx context.Context, userID string, platform int32) (string, error) + GetUserToken(ctx context.Context, userID string, platform int32) (string, error) + AdminToken(ctx context.Context, userID string) (string, error) InviteToGroup(ctx context.Context, userID string, groupIDs []string) error UpdateUserInfo(ctx context.Context, userID string, nickName string, faceURL string) error ForceOffLine(ctx context.Context, userID string) error @@ -65,7 +67,7 @@ func (c *Caller) ImportFriend(ctx context.Context, ownerUserID string, friendUse if len(friendUserIDs) == 0 { return nil } - _, err := importFriend.Call(ctx, c.imApi, &friend.ImportFriendReq{ + _, err := importFriend.Call(ctx, c.imApi, &relation.ImportFriendReq{ OwnerUserID: ownerUserID, FriendUserIDs: friendUserIDs, }) @@ -77,7 +79,7 @@ func (c *Caller) ImAdminTokenWithDefaultAdmin(ctx context.Context) (string, erro defer c.lock.Unlock() if c.token == "" || c.timeout.Before(time.Now()) { userID := c.defaultIMUserID - token, err := c.UserToken(ctx, userID, constantpb.AdminPlatformID) + token, err := c.AdminToken(ctx, userID) if err != nil { log.ZError(ctx, "get im admin token", err, "userID", userID) return "", err @@ -89,9 +91,19 @@ func (c *Caller) ImAdminTokenWithDefaultAdmin(ctx context.Context) (string, erro return c.token, nil } -func (c *Caller) UserToken(ctx context.Context, userID string, platformID int32) (string, error) { +func (c *Caller) AdminToken(ctx context.Context, userID string) (string, error) { resp, err := userToken.Call(ctx, c.imApi, &auth.UserTokenReq{ - Secret: c.imSecret, + Secret: c.imSecret, + UserID: userID, + }) + if err != nil { + return "", err + } + return resp.Token, nil +} + +func (c *Caller) GetUserToken(ctx context.Context, userID string, platformID int32) (string, error) { + resp, err := getuserToken.Call(ctx, c.imApi, &auth.GetUserTokenReq{ PlatformID: platformID, UserID: userID, }) @@ -123,8 +135,7 @@ func (c *Caller) UpdateUserInfo(ctx context.Context, userID string, nickName str func (c *Caller) RegisterUser(ctx context.Context, users []*sdkws.UserInfo) error { _, err := registerUser.Call(ctx, c.imApi, &user.UserRegisterReq{ - Secret: c.imSecret, - Users: users, + Users: users, }) return err } @@ -161,7 +172,7 @@ func (c *Caller) UserRegisterCount(ctx context.Context, start int64, end int64) } func (c *Caller) FriendUserIDs(ctx context.Context, userID string) ([]string, error) { - resp, err := friendUserIDs.Call(ctx, c.imApi, &friend.GetFriendIDsReq{UserID: userID}) + resp, err := friendUserIDs.Call(ctx, c.imApi, &relation.GetFriendIDsReq{UserID: userID}) if err != nil { return nil, err } @@ -174,7 +185,7 @@ func (c *Caller) AccountCheckSingle(ctx context.Context, userID string) (bool, e if err != nil { return false, err } - if resp.Results[0].AccountStatus == "registered" { + if resp.Results[0].AccountStatus == constant.Registered { return false, eerrs.ErrAccountAlreadyRegister.Wrap() } return true, nil diff --git a/tools/check-component/main.go b/tools/check-component/main.go index cc3937ba..00ccd43b 100644 --- a/tools/check-component/main.go +++ b/tools/check-component/main.go @@ -24,7 +24,6 @@ import ( "github.com/openimsdk/chat/pkg/common/cmd" "github.com/openimsdk/chat/pkg/common/config" "github.com/openimsdk/chat/pkg/common/imapi" - constantpb "github.com/openimsdk/protocol/constant" "github.com/openimsdk/tools/db/mongoutil" "github.com/openimsdk/tools/db/redisutil" "github.com/openimsdk/tools/discovery/etcd" @@ -58,7 +57,7 @@ func CheckRedis(ctx context.Context, config *config.Redis) error { func CheckOpenIM(ctx context.Context, apiURL, secret, adminUserID string) error { imAPI := imapi.New(apiURL, secret, adminUserID) - _, err := imAPI.UserToken(mcontext.SetOperationID(ctx, "CheckOpenIM"+idutil.OperationIDGenerator()), adminUserID, constantpb.AdminPlatformID) + _, err := imAPI.AdminToken(mcontext.SetOperationID(ctx, "CheckOpenIM"+idutil.OperationIDGenerator()), adminUserID) return err }