Files
open-im-server/internal/api/third.go
T

90 lines
2.2 KiB
Go
Raw Normal View History

2023-03-03 17:20:36 +08:00
package api
import (
"context"
2023-03-17 11:27:34 +08:00
"github.com/OpenIMSDK/Open-IM-Server/pkg/a2r"
2023-03-16 10:46:06 +08:00
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
"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"
2023-03-03 17:20:36 +08:00
"github.com/gin-gonic/gin"
2023-03-14 19:33:44 +08:00
"net/http"
2023-03-03 17:20:36 +08:00
)
var _ context.Context // 解决goland编辑器bug
2023-03-08 17:29:03 +08:00
func NewThird(c discoveryregistry.SvcDiscoveryRegistry) *Third {
return &Third{c: c}
2023-03-03 17:20:36 +08:00
}
type Third struct {
2023-03-08 17:29:03 +08:00
c discoveryregistry.SvcDiscoveryRegistry
2023-03-03 17:20:36 +08:00
}
func (o *Third) client() (third.ThirdClient, error) {
2023-03-08 17:29:03 +08:00
conn, err := o.c.GetConn(config.Config.RpcRegisterName.OpenImThirdName)
2023-03-03 17:20:36 +08:00
if err != nil {
return nil, err
}
return third.NewThirdClient(conn), nil
}
func (o *Third) ApplyPut(c *gin.Context) {
a2r.Call(third.ThirdClient.ApplyPut, o.client, c)
}
func (o *Third) GetPut(c *gin.Context) {
a2r.Call(third.ThirdClient.GetPut, o.client, c)
}
func (o *Third) ConfirmPut(c *gin.Context) {
a2r.Call(third.ThirdClient.ConfirmPut, o.client, c)
}
func (o *Third) GetSignalInvitationInfo(c *gin.Context) {
a2r.Call(third.ThirdClient.GetSignalInvitationInfo, o.client, c)
}
func (o *Third) GetSignalInvitationInfoStartApp(c *gin.Context) {
a2r.Call(third.ThirdClient.GetSignalInvitationInfoStartApp, o.client, c)
}
func (o *Third) FcmUpdateToken(c *gin.Context) {
a2r.Call(third.ThirdClient.FcmUpdateToken, o.client, c)
}
func (o *Third) SetAppBadge(c *gin.Context) {
a2r.Call(third.ThirdClient.SetAppBadge, o.client, c)
}
2023-03-14 19:33:44 +08:00
func (o *Third) GetURL(c *gin.Context) {
if c.Request.Method == http.MethodPost {
a2r.Call(third.ThirdClient.GetUrl, o.client, c)
return
}
name := c.Query("name")
if name == "" {
c.String(http.StatusBadRequest, "name is empty")
return
}
client, err := o.client()
if err != nil {
c.String(http.StatusInternalServerError, err.Error())
return
}
resp, err := client.GetUrl(c, &third.GetUrlReq{Name: name})
if err != nil {
if errs.ErrArgs.Is(err) {
c.String(http.StatusBadRequest, err.Error())
return
}
if errs.ErrRecordNotFound.Is(err) {
c.String(http.StatusNotFound, err.Error())
return
}
c.String(http.StatusInternalServerError, err.Error())
return
}
c.Redirect(http.StatusTemporaryRedirect, resp.Url)
}