mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-01 07:35:58 +08:00
AUTH
This commit is contained in:
+13
-28
@@ -1,66 +1,51 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
"math/rand"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/a2r"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/mcontext"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/errs"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/third"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient"
|
||||
"github.com/gin-gonic/gin"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
func NewThird(discov discoveryregistry.SvcDiscoveryRegistry) *Third {
|
||||
conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImThirdName)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
client := third.NewThirdClient(conn)
|
||||
return &Third{discov: discov, client: client, conn: conn}
|
||||
type ThirdApi rpcclient.Third
|
||||
|
||||
func NewThirdApi(discov discoveryregistry.SvcDiscoveryRegistry) ThirdApi {
|
||||
return ThirdApi(*rpcclient.NewThird(discov))
|
||||
}
|
||||
|
||||
type Third struct {
|
||||
conn *grpc.ClientConn
|
||||
client third.ThirdClient
|
||||
discov discoveryregistry.SvcDiscoveryRegistry
|
||||
}
|
||||
|
||||
func (o *Third) Client() third.ThirdClient {
|
||||
return o.client
|
||||
}
|
||||
|
||||
func (o *Third) ApplyPut(c *gin.Context) {
|
||||
func (o *ThirdApi) ApplyPut(c *gin.Context) {
|
||||
a2r.Call(third.ThirdClient.ApplyPut, o.Client, c)
|
||||
}
|
||||
|
||||
func (o *Third) GetPut(c *gin.Context) {
|
||||
func (o *ThirdApi) GetPut(c *gin.Context) {
|
||||
a2r.Call(third.ThirdClient.GetPut, o.Client, c)
|
||||
}
|
||||
|
||||
func (o *Third) ConfirmPut(c *gin.Context) {
|
||||
func (o *ThirdApi) ConfirmPut(c *gin.Context) {
|
||||
a2r.Call(third.ThirdClient.ConfirmPut, o.Client, c)
|
||||
}
|
||||
|
||||
func (o *Third) GetHash(c *gin.Context) {
|
||||
func (o *ThirdApi) GetHash(c *gin.Context) {
|
||||
a2r.Call(third.ThirdClient.GetHashInfo, o.Client, c)
|
||||
}
|
||||
|
||||
func (o *Third) FcmUpdateToken(c *gin.Context) {
|
||||
func (o *ThirdApi) FcmUpdateToken(c *gin.Context) {
|
||||
a2r.Call(third.ThirdClient.FcmUpdateToken, o.Client, c)
|
||||
}
|
||||
|
||||
func (o *Third) SetAppBadge(c *gin.Context) {
|
||||
func (o *ThirdApi) SetAppBadge(c *gin.Context) {
|
||||
a2r.Call(third.ThirdClient.SetAppBadge, o.Client, c)
|
||||
}
|
||||
|
||||
func (o *Third) GetURL(c *gin.Context) {
|
||||
func (o *ThirdApi) GetURL(c *gin.Context) {
|
||||
if c.Request.Method == http.MethodPost {
|
||||
a2r.Call(third.ThirdClient.GetUrl, o.Client, c)
|
||||
return
|
||||
@@ -80,7 +65,7 @@ func (o *Third) GetURL(c *gin.Context) {
|
||||
}
|
||||
attachment, _ := strconv.ParseBool(c.Query("attachment"))
|
||||
c.Set(constant.OperationID, operationID)
|
||||
resp, err := o.client.GetUrl(mcontext.SetOperationID(c, operationID), &third.GetUrlReq{Name: name, Expires: expires, Attachment: attachment})
|
||||
resp, err := o.Client.GetUrl(mcontext.SetOperationID(c, operationID), &third.GetUrlReq{Name: name, Expires: expires, Attachment: attachment})
|
||||
if err != nil {
|
||||
if errs.ErrArgs.Is(err) {
|
||||
c.String(http.StatusBadRequest, err.Error())
|
||||
|
||||
Reference in New Issue
Block a user