You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
221 lines
10 KiB
221 lines
10 KiB
1 year ago
|
package api
|
||
|
|
||
|
import (
|
||
10 months ago
|
"fmt"
|
||
9 months ago
|
"github.com/gin-gonic/gin"
|
||
|
"github.com/gin-gonic/gin/binding"
|
||
|
"github.com/go-playground/validator/v10"
|
||
8 months ago
|
"github.com/openimsdk/open-im-server/v3/pkg/common/servererrs"
|
||
9 months ago
|
"github.com/openimsdk/open-im-server/v3/pkg/rpcclient"
|
||
8 months ago
|
"github.com/openimsdk/protocol/constant"
|
||
|
"github.com/openimsdk/tools/apiresp"
|
||
|
"github.com/openimsdk/tools/discovery"
|
||
|
"github.com/openimsdk/tools/log"
|
||
|
"github.com/openimsdk/tools/mw"
|
||
9 months ago
|
"google.golang.org/grpc"
|
||
|
"google.golang.org/grpc/credentials/insecure"
|
||
8 months ago
|
"net/http"
|
||
1 year ago
|
)
|
||
|
|
||
8 months ago
|
func newGinRouter(disCov discovery.SvcDiscoveryRegistry, config *Config) *gin.Engine {
|
||
|
disCov.AddOption(mw.GrpcClient(), grpc.WithTransportCredentials(insecure.NewCredentials()),
|
||
|
grpc.WithDefaultServiceConfig(fmt.Sprintf(`{"LoadBalancingPolicy": "%s"}`, "round_robin")))
|
||
1 year ago
|
gin.SetMode(gin.ReleaseMode)
|
||
|
r := gin.New()
|
||
|
if v, ok := binding.Validator.Engine().(*validator.Validate); ok {
|
||
|
_ = v.RegisterValidation("required_if", RequiredIf)
|
||
|
}
|
||
|
r.Use(gin.Recovery(), mw.CorsHandler(), mw.GinParseOperationID())
|
||
1 year ago
|
// init rpc client here
|
||
8 months ago
|
userRpc := rpcclient.NewUser(disCov, config.Share.RpcRegisterName.User, config.Share.RpcRegisterName.MessageGateway,
|
||
|
config.Share.IMAdminUserID)
|
||
|
groupRpc := rpcclient.NewGroup(disCov, config.Share.RpcRegisterName.Group)
|
||
|
friendRpc := rpcclient.NewFriend(disCov, config.Share.RpcRegisterName.Friend)
|
||
|
messageRpc := rpcclient.NewMessage(disCov, config.Share.RpcRegisterName.Msg)
|
||
|
conversationRpc := rpcclient.NewConversation(disCov, config.Share.RpcRegisterName.Conversation)
|
||
|
authRpc := rpcclient.NewAuth(disCov, config.Share.RpcRegisterName.Auth)
|
||
|
thirdRpc := rpcclient.NewThird(disCov, config.Share.RpcRegisterName.Third, config.RpcConfig.Prometheus.GrafanaURL)
|
||
1 year ago
|
|
||
|
u := NewUserApi(*userRpc)
|
||
8 months ago
|
m := NewMessageApi(messageRpc, userRpc, config.Share.IMAdminUserID)
|
||
|
ParseToken := GinParseToken(authRpc)
|
||
1 year ago
|
userRouterGroup := r.Group("/user")
|
||
1 year ago
|
{
|
||
1 year ago
|
userRouterGroup.POST("/user_register", u.UserRegister)
|
||
|
userRouterGroup.POST("/update_user_info", ParseToken, u.UpdateUserInfo)
|
||
11 months ago
|
userRouterGroup.POST("/update_user_info_ex", ParseToken, u.UpdateUserInfoEx)
|
||
1 year ago
|
userRouterGroup.POST("/set_global_msg_recv_opt", ParseToken, u.SetGlobalRecvMessageOpt)
|
||
|
userRouterGroup.POST("/get_users_info", ParseToken, u.GetUsersPublicInfo)
|
||
|
userRouterGroup.POST("/get_all_users_uid", ParseToken, u.GetAllUsersID)
|
||
|
userRouterGroup.POST("/account_check", ParseToken, u.AccountCheck)
|
||
|
userRouterGroup.POST("/get_users", ParseToken, u.GetUsers)
|
||
|
userRouterGroup.POST("/get_users_online_status", ParseToken, u.GetUsersOnlineStatus)
|
||
1 year ago
|
userRouterGroup.POST("/get_users_online_token_detail", ParseToken, u.GetUsersOnlineTokenDetail)
|
||
1 year ago
|
userRouterGroup.POST("/subscribe_users_status", ParseToken, u.SubscriberStatus)
|
||
1 year ago
|
userRouterGroup.POST("/get_users_status", ParseToken, u.GetUserStatus)
|
||
1 year ago
|
userRouterGroup.POST("/get_subscribe_users_status", ParseToken, u.GetSubscribeUsersStatus)
|
||
12 months ago
|
|
||
|
userRouterGroup.POST("/process_user_command_add", ParseToken, u.ProcessUserCommandAdd)
|
||
|
userRouterGroup.POST("/process_user_command_delete", ParseToken, u.ProcessUserCommandDelete)
|
||
|
userRouterGroup.POST("/process_user_command_update", ParseToken, u.ProcessUserCommandUpdate)
|
||
|
userRouterGroup.POST("/process_user_command_get", ParseToken, u.ProcessUserCommandGet)
|
||
11 months ago
|
userRouterGroup.POST("/process_user_command_get_all", ParseToken, u.ProcessUserCommandGetAll)
|
||
11 months ago
|
|
||
|
userRouterGroup.POST("/add_notification_account", ParseToken, u.AddNotificationAccount)
|
||
|
userRouterGroup.POST("/update_notification_account", ParseToken, u.UpdateNotificationAccountInfo)
|
||
|
userRouterGroup.POST("/search_notification_account", ParseToken, u.SearchNotificationAccount)
|
||
1 year ago
|
}
|
||
1 year ago
|
// friend routing group
|
||
1 year ago
|
friendRouterGroup := r.Group("/friend", ParseToken)
|
||
1 year ago
|
{
|
||
1 year ago
|
f := NewFriendApi(*friendRpc)
|
||
1 year ago
|
friendRouterGroup.POST("/delete_friend", f.DeleteFriend)
|
||
|
friendRouterGroup.POST("/get_friend_apply_list", f.GetFriendApplyList)
|
||
1 year ago
|
friendRouterGroup.POST("/get_designated_friend_apply", f.GetDesignatedFriendsApply)
|
||
1 year ago
|
friendRouterGroup.POST("/get_self_friend_apply_list", f.GetSelfApplyList)
|
||
|
friendRouterGroup.POST("/get_friend_list", f.GetFriendList)
|
||
1 year ago
|
friendRouterGroup.POST("/get_designated_friends", f.GetDesignatedFriends)
|
||
1 year ago
|
friendRouterGroup.POST("/add_friend", f.ApplyToAddFriend)
|
||
|
friendRouterGroup.POST("/add_friend_response", f.RespondFriendApply)
|
||
|
friendRouterGroup.POST("/set_friend_remark", f.SetFriendRemark)
|
||
|
friendRouterGroup.POST("/add_black", f.AddBlack)
|
||
|
friendRouterGroup.POST("/get_black_list", f.GetPaginationBlacks)
|
||
|
friendRouterGroup.POST("/remove_black", f.RemoveBlack)
|
||
|
friendRouterGroup.POST("/import_friend", f.ImportFriends)
|
||
|
friendRouterGroup.POST("/is_friend", f.IsFriend)
|
||
1 year ago
|
friendRouterGroup.POST("/get_friend_id", f.GetFriendIDs)
|
||
1 year ago
|
friendRouterGroup.POST("/get_specified_friends_info", f.GetSpecifiedFriendsInfo)
|
||
11 months ago
|
friendRouterGroup.POST("/update_friends", f.UpdateFriends)
|
||
1 year ago
|
}
|
||
1 year ago
|
g := NewGroupApi(*groupRpc)
|
||
1 year ago
|
groupRouterGroup := r.Group("/group", ParseToken)
|
||
1 year ago
|
{
|
||
1 year ago
|
groupRouterGroup.POST("/create_group", g.CreateGroup)
|
||
|
groupRouterGroup.POST("/set_group_info", g.SetGroupInfo)
|
||
|
groupRouterGroup.POST("/join_group", g.JoinGroup)
|
||
|
groupRouterGroup.POST("/quit_group", g.QuitGroup)
|
||
|
groupRouterGroup.POST("/group_application_response", g.ApplicationGroupResponse)
|
||
|
groupRouterGroup.POST("/transfer_group", g.TransferGroupOwner)
|
||
|
groupRouterGroup.POST("/get_recv_group_applicationList", g.GetRecvGroupApplicationList)
|
||
1 year ago
|
groupRouterGroup.POST("/get_user_req_group_applicationList", g.GetUserReqGroupApplicationList)
|
||
1 year ago
|
groupRouterGroup.POST("/get_group_users_req_application_list", g.GetGroupUsersReqApplicationList)
|
||
1 year ago
|
groupRouterGroup.POST("/get_groups_info", g.GetGroupsInfo)
|
||
|
groupRouterGroup.POST("/kick_group", g.KickGroupMember)
|
||
|
groupRouterGroup.POST("/get_group_members_info", g.GetGroupMembersInfo)
|
||
|
groupRouterGroup.POST("/get_group_member_list", g.GetGroupMemberList)
|
||
|
groupRouterGroup.POST("/invite_user_to_group", g.InviteUserToGroup)
|
||
1 year ago
|
groupRouterGroup.POST("/get_joined_group_list", g.GetJoinedGroupList)
|
||
|
groupRouterGroup.POST("/dismiss_group", g.DismissGroup) //
|
||
|
groupRouterGroup.POST("/mute_group_member", g.MuteGroupMember)
|
||
1 year ago
|
groupRouterGroup.POST("/cancel_mute_group_member", g.CancelMuteGroupMember)
|
||
1 year ago
|
groupRouterGroup.POST("/mute_group", g.MuteGroup)
|
||
|
groupRouterGroup.POST("/cancel_mute_group", g.CancelMuteGroup)
|
||
|
groupRouterGroup.POST("/set_group_member_info", g.SetGroupMemberInfo)
|
||
|
groupRouterGroup.POST("/get_group_abstract_info", g.GetGroupAbstractInfo)
|
||
1 year ago
|
groupRouterGroup.POST("/get_groups", g.GetGroups)
|
||
1 year ago
|
groupRouterGroup.POST("/get_group_member_user_id", g.GetGroupMemberUserIDs)
|
||
1 year ago
|
}
|
||
1 year ago
|
// certificate
|
||
1 year ago
|
authRouterGroup := r.Group("/auth")
|
||
|
{
|
||
1 year ago
|
a := NewAuthApi(*authRpc)
|
||
1 year ago
|
authRouterGroup.POST("/user_token", a.UserToken)
|
||
10 months ago
|
authRouterGroup.POST("/get_user_token", ParseToken, a.GetUserToken)
|
||
1 year ago
|
authRouterGroup.POST("/parse_token", a.ParseToken)
|
||
|
authRouterGroup.POST("/force_logout", ParseToken, a.ForceLogout)
|
||
1 year ago
|
}
|
||
1 year ago
|
// Third service
|
||
1 year ago
|
thirdGroup := r.Group("/third", ParseToken)
|
||
1 year ago
|
{
|
||
1 year ago
|
t := NewThirdApi(*thirdRpc)
|
||
9 months ago
|
thirdGroup.GET("/prometheus", t.GetPrometheus)
|
||
1 year ago
|
thirdGroup.POST("/fcm_update_token", t.FcmUpdateToken)
|
||
|
thirdGroup.POST("/set_app_badge", t.SetAppBadge)
|
||
|
|
||
1 year ago
|
logs := thirdGroup.Group("/logs")
|
||
|
logs.POST("/upload", t.UploadLogs)
|
||
|
logs.POST("/delete", t.DeleteLogs)
|
||
|
logs.POST("/search", t.SearchLogs)
|
||
|
|
||
1 year ago
|
objectGroup := r.Group("/object", ParseToken)
|
||
|
|
||
|
objectGroup.POST("/part_limit", t.PartLimit)
|
||
|
objectGroup.POST("/part_size", t.PartSize)
|
||
|
objectGroup.POST("/initiate_multipart_upload", t.InitiateMultipartUpload)
|
||
|
objectGroup.POST("/auth_sign", t.AuthSign)
|
||
|
objectGroup.POST("/complete_multipart_upload", t.CompleteMultipartUpload)
|
||
|
objectGroup.POST("/access_url", t.AccessURL)
|
||
11 months ago
|
objectGroup.POST("/initiate_form_data", t.InitiateFormData)
|
||
|
objectGroup.POST("/complete_form_data", t.CompleteFormData)
|
||
1 year ago
|
objectGroup.GET("/*name", t.ObjectRedirect)
|
||
1 year ago
|
}
|
||
1 year ago
|
// Message
|
||
1 year ago
|
msgGroup := r.Group("/msg", ParseToken)
|
||
1 year ago
|
{
|
||
|
msgGroup.POST("/newest_seq", m.GetSeq)
|
||
1 year ago
|
msgGroup.POST("/search_msg", m.SearchMsg)
|
||
1 year ago
|
msgGroup.POST("/send_msg", m.SendMessage)
|
||
1 year ago
|
msgGroup.POST("/send_business_notification", m.SendBusinessNotification)
|
||
1 year ago
|
msgGroup.POST("/pull_msg_by_seq", m.PullMsgBySeqs)
|
||
|
msgGroup.POST("/revoke_msg", m.RevokeMsg)
|
||
|
msgGroup.POST("/mark_msgs_as_read", m.MarkMsgsAsRead)
|
||
|
msgGroup.POST("/mark_conversation_as_read", m.MarkConversationAsRead)
|
||
|
msgGroup.POST("/get_conversations_has_read_and_max_seq", m.GetConversationsHasReadAndMaxSeq)
|
||
|
msgGroup.POST("/set_conversation_has_read_seq", m.SetConversationHasReadSeq)
|
||
|
|
||
|
msgGroup.POST("/clear_conversation_msg", m.ClearConversationsMsg)
|
||
|
msgGroup.POST("/user_clear_all_msg", m.UserClearAllMsg)
|
||
|
msgGroup.POST("/delete_msgs", m.DeleteMsgs)
|
||
|
msgGroup.POST("/delete_msg_phsical_by_seq", m.DeleteMsgPhysicalBySeq)
|
||
|
msgGroup.POST("/delete_msg_physical", m.DeleteMsgPhysical)
|
||
|
|
||
1 year ago
|
msgGroup.POST("/batch_send_msg", m.BatchSendMsg)
|
||
1 year ago
|
msgGroup.POST("/check_msg_is_send_success", m.CheckMsgIsSendSuccess)
|
||
1 year ago
|
msgGroup.POST("/get_server_time", m.GetServerTime)
|
||
1 year ago
|
}
|
||
1 year ago
|
// Conversation
|
||
1 year ago
|
conversationGroup := r.Group("/conversation", ParseToken)
|
||
1 year ago
|
{
|
||
1 year ago
|
c := NewConversationApi(*conversationRpc)
|
||
11 months ago
|
conversationGroup.POST("/get_sorted_conversation_list", c.GetSortedConversationList)
|
||
1 year ago
|
conversationGroup.POST("/get_all_conversations", c.GetAllConversations)
|
||
|
conversationGroup.POST("/get_conversation", c.GetConversation)
|
||
|
conversationGroup.POST("/get_conversations", c.GetConversations)
|
||
|
conversationGroup.POST("/set_conversations", c.SetConversations)
|
||
1 year ago
|
conversationGroup.POST("/get_conversation_offline_push_user_ids", c.GetConversationOfflinePushUserIDs)
|
||
1 year ago
|
}
|
||
|
|
||
1 year ago
|
statisticsGroup := r.Group("/statistics", ParseToken)
|
||
1 year ago
|
{
|
||
1 year ago
|
statisticsGroup.POST("/user/register", u.UserRegisterCount)
|
||
|
statisticsGroup.POST("/user/active", m.GetActiveUser)
|
||
|
statisticsGroup.POST("/group/create", g.GroupCreateCount)
|
||
|
statisticsGroup.POST("/group/active", m.GetActiveGroup)
|
||
1 year ago
|
}
|
||
|
return r
|
||
|
}
|
||
1 year ago
|
|
||
8 months ago
|
func GinParseToken(authRPC *rpcclient.Auth) gin.HandlerFunc {
|
||
1 year ago
|
return func(c *gin.Context) {
|
||
|
switch c.Request.Method {
|
||
|
case http.MethodPost:
|
||
|
token := c.Request.Header.Get(constant.Token)
|
||
|
if token == "" {
|
||
8 months ago
|
log.ZWarn(c, "header get token error", servererrs.ErrArgs.WrapMsg("header must have token"))
|
||
|
apiresp.GinError(c, servererrs.ErrArgs.WrapMsg("header must have token"))
|
||
1 year ago
|
c.Abort()
|
||
|
return
|
||
|
}
|
||
8 months ago
|
resp, err := authRPC.ParseToken(c, token)
|
||
1 year ago
|
if err != nil {
|
||
8 months ago
|
apiresp.GinError(c, err)
|
||
1 year ago
|
c.Abort()
|
||
|
return
|
||
|
}
|
||
8 months ago
|
c.Set(constant.OpUserPlatform, constant.PlatformIDToName(int(resp.PlatformID)))
|
||
|
c.Set(constant.OpUserID, resp.UserID)
|
||
1 year ago
|
c.Next()
|
||
|
}
|
||
|
}
|
||
|
}
|