mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-04 09:05:59 +08:00
s3 minio, cos, oss support
This commit is contained in:
@@ -109,12 +109,14 @@ func NewGinRouter(discov discoveryregistry.SvcDiscoveryRegistry, rdb redis.Unive
|
||||
thirdGroup.POST("/fcm_update_token", t.FcmUpdateToken)
|
||||
thirdGroup.POST("/set_app_badge", t.SetAppBadge)
|
||||
|
||||
thirdGroup.POST("/apply_put", t.ApplyPut)
|
||||
thirdGroup.POST("/get_put", t.GetPut)
|
||||
thirdGroup.POST("/confirm_put", t.ConfirmPut)
|
||||
thirdGroup.POST("/get_hash", t.GetHash)
|
||||
thirdGroup.POST("/object", t.GetURL)
|
||||
thirdGroup.GET("/object", t.GetURL)
|
||||
objectGroup := r.Group("/object", ParseToken)
|
||||
|
||||
objectGroup.POST("/part_size", t.PartSize)
|
||||
objectGroup.POST("/initiateMultipartUpload", t.InitiateMultipartUpload)
|
||||
objectGroup.POST("/authSign", t.AuthSign)
|
||||
objectGroup.POST("/completeMultipartUpload", t.CompleteMultipartUpload)
|
||||
objectGroup.POST("/accessURL", t.AccessURL)
|
||||
objectGroup.GET("/object/*name", t.ObjectRedirect)
|
||||
}
|
||||
//Message
|
||||
msgGroup := r.Group("/msg", ParseToken)
|
||||
|
||||
+30
-39
@@ -1,18 +1,16 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/a2r"
|
||||
"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"
|
||||
"math/rand"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type ThirdApi rpcclient.Third
|
||||
@@ -21,22 +19,6 @@ func NewThirdApi(discov discoveryregistry.SvcDiscoveryRegistry) ThirdApi {
|
||||
return ThirdApi(*rpcclient.NewThird(discov))
|
||||
}
|
||||
|
||||
func (o *ThirdApi) ApplyPut(c *gin.Context) {
|
||||
a2r.Call(third.ThirdClient.ApplyPut, o.Client, c)
|
||||
}
|
||||
|
||||
func (o *ThirdApi) GetPut(c *gin.Context) {
|
||||
a2r.Call(third.ThirdClient.GetPut, o.Client, c)
|
||||
}
|
||||
|
||||
func (o *ThirdApi) ConfirmPut(c *gin.Context) {
|
||||
a2r.Call(third.ThirdClient.ConfirmPut, o.Client, c)
|
||||
}
|
||||
|
||||
func (o *ThirdApi) GetHash(c *gin.Context) {
|
||||
a2r.Call(third.ThirdClient.GetHashInfo, o.Client, c)
|
||||
}
|
||||
|
||||
func (o *ThirdApi) FcmUpdateToken(c *gin.Context) {
|
||||
a2r.Call(third.ThirdClient.FcmUpdateToken, o.Client, c)
|
||||
}
|
||||
@@ -45,27 +27,36 @@ func (o *ThirdApi) SetAppBadge(c *gin.Context) {
|
||||
a2r.Call(third.ThirdClient.SetAppBadge, o.Client, c)
|
||||
}
|
||||
|
||||
func (o *ThirdApi) 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
|
||||
}
|
||||
// #################### s3 ####################
|
||||
|
||||
func (o *ThirdApi) PartSize(c *gin.Context) {
|
||||
a2r.Call(third.ThirdClient.PartSize, o.Client, c)
|
||||
}
|
||||
|
||||
func (o *ThirdApi) InitiateMultipartUpload(c *gin.Context) {
|
||||
a2r.Call(third.ThirdClient.InitiateMultipartUpload, o.Client, c)
|
||||
}
|
||||
|
||||
func (o *ThirdApi) AuthSign(c *gin.Context) {
|
||||
a2r.Call(third.ThirdClient.AuthSign, o.Client, c)
|
||||
}
|
||||
|
||||
func (o *ThirdApi) CompleteMultipartUpload(c *gin.Context) {
|
||||
a2r.Call(third.ThirdClient.CompleteMultipartUpload, o.Client, c)
|
||||
}
|
||||
|
||||
func (o *ThirdApi) AccessURL(c *gin.Context) {
|
||||
a2r.Call(third.ThirdClient.AccessURL, o.Client, c)
|
||||
}
|
||||
|
||||
func (o *ThirdApi) ObjectRedirect(c *gin.Context) {
|
||||
name := c.Param("name")
|
||||
operationID := c.Query("operationID")
|
||||
if operationID == "" {
|
||||
operationID = "auto_" + strconv.Itoa(rand.Int())
|
||||
operationID = strconv.Itoa(rand.Int())
|
||||
}
|
||||
expires, _ := strconv.ParseInt(c.Query("expires"), 10, 64)
|
||||
if expires <= 0 {
|
||||
expires = 3600 * 1000
|
||||
}
|
||||
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})
|
||||
ctx := mcontext.SetOperationID(c, operationID)
|
||||
resp, err := o.Client.AccessURL(ctx, &third.AccessURLReq{Name: name})
|
||||
if err != nil {
|
||||
if errs.ErrArgs.Is(err) {
|
||||
c.String(http.StatusBadRequest, err.Error())
|
||||
|
||||
Reference in New Issue
Block a user