mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-03 00:25:59 +08:00
api rpc third
This commit is contained in:
+15
-12
@@ -3,7 +3,6 @@ package api
|
||||
import (
|
||||
"OpenIM/internal/api/manage"
|
||||
"OpenIM/internal/api/msg"
|
||||
"OpenIM/internal/api/third"
|
||||
"OpenIM/pkg/common/config"
|
||||
"OpenIM/pkg/common/log"
|
||||
"OpenIM/pkg/common/middleware"
|
||||
@@ -106,20 +105,24 @@ func NewGinRouter() *gin.Engine {
|
||||
authRouterGroup.POST("/parse_token", a.ParseToken) //1
|
||||
authRouterGroup.POST("/force_logout", a.ForceLogout) //1
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
*/
|
||||
|
||||
////Third service
|
||||
thirdGroup := r.Group("/third")
|
||||
{
|
||||
thirdGroup.POST("/tencent_cloud_storage_credential", third.TencentCloudStorageCredential)
|
||||
thirdGroup.POST("/ali_oss_credential", third.AliOSSCredential)
|
||||
thirdGroup.POST("/minio_storage_credential", third.MinioStorageCredential)
|
||||
thirdGroup.POST("/minio_upload", third.MinioUploadFile)
|
||||
thirdGroup.POST("/upload_update_app", third.UploadUpdateApp)
|
||||
thirdGroup.POST("/get_download_url", third.GetDownloadURL)
|
||||
thirdGroup.POST("/get_rtc_invitation_info", third.GetRTCInvitationInfo)
|
||||
thirdGroup.POST("/get_rtc_invitation_start_app", third.GetRTCInvitationInfoStartApp)
|
||||
thirdGroup.POST("/fcm_update_token", third.FcmUpdateToken)
|
||||
thirdGroup.POST("/aws_storage_credential", third.AwsStorageCredential)
|
||||
thirdGroup.POST("/set_app_badge", third.SetAppBadge)
|
||||
t := NewThird(zk)
|
||||
|
||||
thirdGroup.POST("/get_rtc_invitation_info", t.GetSignalInvitationInfo)
|
||||
thirdGroup.POST("/get_rtc_invitation_start_app", t.GetSignalInvitationInfoStartApp)
|
||||
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)
|
||||
}
|
||||
////Message
|
||||
chatGroup := r.Group("/msg")
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"OpenIM/internal/api/a2r"
|
||||
"OpenIM/pkg/common/config"
|
||||
"OpenIM/pkg/proto/third"
|
||||
"context"
|
||||
"github.com/OpenIMSDK/openKeeper"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
var _ context.Context // 解决goland编辑器bug
|
||||
|
||||
func NewThird(zk *openKeeper.ZkClient) *Third {
|
||||
return &Third{zk: zk}
|
||||
}
|
||||
|
||||
type Third struct {
|
||||
zk *openKeeper.ZkClient
|
||||
}
|
||||
|
||||
func (o *Third) client() (third.ThirdClient, error) {
|
||||
conn, err := o.zk.GetConn(config.Config.RpcRegisterName.OpenImThirdName)
|
||||
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)
|
||||
}
|
||||
@@ -1,101 +0,0 @@
|
||||
package third
|
||||
|
||||
import (
|
||||
api "OpenIM/pkg/apistruct"
|
||||
"OpenIM/pkg/common/config"
|
||||
"OpenIM/pkg/common/constant"
|
||||
"OpenIM/pkg/common/log"
|
||||
"OpenIM/pkg/common/tokenverify"
|
||||
"fmt"
|
||||
openapi "github.com/alibabacloud-go/darabonba-openapi/client"
|
||||
sts20150401 "github.com/alibabacloud-go/sts-20150401/client"
|
||||
"github.com/alibabacloud-go/tea/tea"
|
||||
"github.com/fatih/structs"
|
||||
|
||||
//"github.com/fatih/structs"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
var stsClient *sts20150401.Client
|
||||
|
||||
/**
|
||||
* 使用AK&SK初始化账号Client
|
||||
* @param accessKeyId
|
||||
* @param accessKeySecret
|
||||
* @return Client
|
||||
* @throws Exception
|
||||
*/
|
||||
func getStsClient() *sts20150401.Client {
|
||||
if stsClient != nil {
|
||||
return stsClient
|
||||
}
|
||||
conf := &openapi.Config{
|
||||
// 您的AccessKey ID
|
||||
AccessKeyId: tea.String(config.Config.Credential.Ali.AccessKeyID),
|
||||
// 您的AccessKey Secret
|
||||
AccessKeySecret: tea.String(config.Config.Credential.Ali.AccessKeySecret),
|
||||
// Endpoint
|
||||
Endpoint: tea.String(config.Config.Credential.Ali.StsEndpoint),
|
||||
}
|
||||
result, err := sts20150401.NewClient(conf)
|
||||
if err != nil {
|
||||
log.NewError("", "alists client初始化失败 ", err)
|
||||
}
|
||||
stsClient = result
|
||||
return stsClient
|
||||
}
|
||||
|
||||
func AliOSSCredential(c *gin.Context) {
|
||||
req := api.OSSCredentialReq{}
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
log.NewError("0", "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
var ok bool
|
||||
var userID string
|
||||
var errInfo string
|
||||
ok, userID, errInfo = tokenverify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
|
||||
if !ok {
|
||||
errMsg := req.OperationID + " " + "GetUserIDFromToken failed " + errInfo + " token:" + c.Request.Header.Get("token")
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
|
||||
log.NewInfo(req.OperationID, "AliOSSCredential args ", userID)
|
||||
|
||||
stsResp, err := getStsClient().AssumeRole(&sts20150401.AssumeRoleRequest{
|
||||
DurationSeconds: tea.Int64(config.Config.Credential.Ali.StsDurationSeconds),
|
||||
Policy: nil,
|
||||
RoleArn: tea.String(config.Config.Credential.Ali.OssRoleArn),
|
||||
RoleSessionName: tea.String(fmt.Sprintf("%s-%d", userID, time.Now().Unix())),
|
||||
})
|
||||
|
||||
resp := api.OSSCredentialResp{}
|
||||
if err != nil {
|
||||
resp.ErrCode = constant.ErrTencentCredential.ErrCode
|
||||
resp.ErrMsg = err.Error()
|
||||
} else {
|
||||
resp = api.OSSCredentialResp{
|
||||
CommResp: api.CommResp{},
|
||||
OssData: api.OSSCredentialRespData{
|
||||
Endpoint: config.Config.Credential.Ali.OssEndpoint,
|
||||
AccessKeyId: *stsResp.Body.Credentials.AccessKeyId,
|
||||
AccessKeySecret: *stsResp.Body.Credentials.AccessKeySecret,
|
||||
Token: *stsResp.Body.Credentials.SecurityToken,
|
||||
Bucket: config.Config.Credential.Ali.Bucket,
|
||||
FinalHost: config.Config.Credential.Ali.FinalHost,
|
||||
},
|
||||
Data: nil,
|
||||
}
|
||||
}
|
||||
|
||||
resp.Data = structs.Map(&resp.OssData)
|
||||
log.NewInfo(req.OperationID, "AliOSSCredential return ", resp)
|
||||
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
@@ -1,76 +0,0 @@
|
||||
package third
|
||||
|
||||
import (
|
||||
api "OpenIM/pkg/apistruct"
|
||||
"OpenIM/pkg/common/config"
|
||||
"OpenIM/pkg/common/constant"
|
||||
"OpenIM/pkg/common/log"
|
||||
"OpenIM/pkg/common/tokenverify"
|
||||
"OpenIM/pkg/utils"
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/aws"
|
||||
awsConfig "github.com/aws/aws-sdk-go-v2/config"
|
||||
"github.com/aws/aws-sdk-go-v2/credentials"
|
||||
"github.com/aws/aws-sdk-go-v2/service/sts"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func AwsStorageCredential(c *gin.Context) {
|
||||
var (
|
||||
req api.AwsStorageCredentialReq
|
||||
resp api.AwsStorageCredentialResp
|
||||
)
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
log.NewError("0", utils.GetSelfFuncName(), "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req)
|
||||
var ok bool
|
||||
var errInfo string
|
||||
ok, _, errInfo = tokenverify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
|
||||
if !ok {
|
||||
errMsg := req.OperationID + " " + "GetUserIDFromToken failed " + errInfo + " token:" + c.Request.Header.Get("token")
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
//原始帐号信息
|
||||
awsSourceConfig, err := awsConfig.LoadDefaultConfig(context.TODO(), awsConfig.WithRegion(config.Config.Credential.Aws.Region),
|
||||
awsConfig.WithCredentialsProvider(credentials.StaticCredentialsProvider{
|
||||
Value: aws.Credentials{
|
||||
AccessKeyID: config.Config.Credential.Aws.AccessKeyID,
|
||||
SecretAccessKey: config.Config.Credential.Aws.AccessKeySecret,
|
||||
Source: "Open IM OSS",
|
||||
},
|
||||
}))
|
||||
if err != nil {
|
||||
errMsg := req.OperationID + " " + "Init AWS S3 Credential failed " + err.Error() + " token:" + c.Request.Header.Get("token")
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
//帐号转化
|
||||
awsStsClient := sts.NewFromConfig(awsSourceConfig)
|
||||
StsRole, err := awsStsClient.AssumeRole(context.Background(), &sts.AssumeRoleInput{
|
||||
RoleArn: aws.String(config.Config.Credential.Aws.RoleArn),
|
||||
DurationSeconds: aws.Int32(constant.AwsDurationTimes),
|
||||
RoleSessionName: aws.String(config.Config.Credential.Aws.RoleSessionName),
|
||||
ExternalId: aws.String(config.Config.Credential.Aws.ExternalId),
|
||||
})
|
||||
if err != nil {
|
||||
errMsg := req.OperationID + " " + "AWS S3 AssumeRole failed " + err.Error() + " token:" + c.Request.Header.Get("token")
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
resp.CosData.AccessKeyId = string(*StsRole.Credentials.AccessKeyId)
|
||||
resp.CosData.SecretAccessKey = string(*StsRole.Credentials.SecretAccessKey)
|
||||
resp.CosData.SessionToken = string(*StsRole.Credentials.SessionToken)
|
||||
resp.CosData.Bucket = config.Config.Credential.Aws.Bucket
|
||||
resp.CosData.RegionID = config.Config.Credential.Aws.Region
|
||||
resp.CosData.FinalHost = config.Config.Credential.Aws.FinalHost
|
||||
c.JSON(http.StatusOK, gin.H{"errCode": 0, "errMsg": "", "data": resp})
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
package third
|
||||
|
||||
import (
|
||||
api "OpenIM/pkg/apistruct"
|
||||
"OpenIM/pkg/common/log"
|
||||
"OpenIM/pkg/common/tokenverify"
|
||||
"OpenIM/pkg/utils"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func FcmUpdateToken(c *gin.Context) {
|
||||
var (
|
||||
req api.FcmUpdateTokenReq
|
||||
resp api.FcmUpdateTokenResp
|
||||
)
|
||||
if err := c.Bind(&req); err != nil {
|
||||
log.NewError("0", utils.GetSelfFuncName(), "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), req)
|
||||
|
||||
ok, UserId, errInfo := tokenverify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
|
||||
if !ok {
|
||||
errMsg := req.OperationID + " " + "GetUserIDFromToken failed " + errInfo + " token:" + c.Request.Header.Get("token")
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
resp.ErrCode = 500
|
||||
resp.ErrMsg = errMsg
|
||||
c.JSON(http.StatusInternalServerError, resp)
|
||||
return
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), req, UserId)
|
||||
//逻辑处理开始
|
||||
err := db.DB.SetFcmToken(UserId, req.Platform, req.FcmToken, 0)
|
||||
if err != nil {
|
||||
errMsg := req.OperationID + " " + "SetFcmToken failed " + err.Error() + " token:" + c.Request.Header.Get("token")
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
resp.ErrCode = 500
|
||||
resp.ErrMsg = errMsg
|
||||
c.JSON(http.StatusInternalServerError, resp)
|
||||
return
|
||||
}
|
||||
//逻辑处理完毕
|
||||
c.JSON(http.StatusOK, resp)
|
||||
return
|
||||
}
|
||||
@@ -1,101 +0,0 @@
|
||||
package third
|
||||
|
||||
import (
|
||||
"OpenIM/pkg/common/config"
|
||||
"OpenIM/pkg/common/log"
|
||||
"OpenIM/pkg/utils"
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/minio/minio-go/v7"
|
||||
"github.com/minio/minio-go/v7/pkg/credentials"
|
||||
url2 "net/url"
|
||||
)
|
||||
|
||||
var (
|
||||
MinioClient *minio.Client
|
||||
)
|
||||
|
||||
func MinioInit() {
|
||||
operationID := utils.OperationIDGenerator()
|
||||
log.NewInfo(operationID, utils.GetSelfFuncName(), "minio config: ", config.Config.Credential.Minio)
|
||||
var initUrl string
|
||||
if config.Config.Credential.Minio.EndpointInnerEnable {
|
||||
initUrl = config.Config.Credential.Minio.EndpointInner
|
||||
} else {
|
||||
initUrl = config.Config.Credential.Minio.Endpoint
|
||||
}
|
||||
log.NewInfo(operationID, utils.GetSelfFuncName(), "use initUrl: ", initUrl)
|
||||
minioUrl, err := url2.Parse(initUrl)
|
||||
if err != nil {
|
||||
log.NewError(operationID, utils.GetSelfFuncName(), "parse failed, please check config/config.yaml", err.Error())
|
||||
return
|
||||
}
|
||||
opts := &minio.Options{
|
||||
Creds: credentials.NewStaticV4(config.Config.Credential.Minio.AccessKeyID, config.Config.Credential.Minio.SecretAccessKey, ""),
|
||||
//Region: config.Config.Credential.Minio.Location,
|
||||
}
|
||||
if minioUrl.Scheme == "http" {
|
||||
opts.Secure = false
|
||||
} else if minioUrl.Scheme == "https" {
|
||||
opts.Secure = true
|
||||
}
|
||||
log.NewInfo(operationID, utils.GetSelfFuncName(), "Parse ok ", config.Config.Credential.Minio)
|
||||
MinioClient, err = minio.New(minioUrl.Host, opts)
|
||||
log.NewInfo(operationID, utils.GetSelfFuncName(), "new ok ", config.Config.Credential.Minio)
|
||||
if err != nil {
|
||||
log.NewError(operationID, utils.GetSelfFuncName(), "init minio client failed", err.Error())
|
||||
return
|
||||
}
|
||||
opt := minio.MakeBucketOptions{
|
||||
Region: config.Config.Credential.Minio.Location,
|
||||
}
|
||||
if config.Config.Credential.Minio.IsDistributedMod == true {
|
||||
opt.ObjectLocking = true
|
||||
}
|
||||
err = MinioClient.MakeBucket(context.Background(), config.Config.Credential.Minio.Bucket, opt)
|
||||
if err != nil {
|
||||
log.NewInfo(operationID, utils.GetSelfFuncName(), "MakeBucket failed ", err.Error())
|
||||
exists, err := MinioClient.BucketExists(context.Background(), config.Config.Credential.Minio.Bucket)
|
||||
if err == nil && exists {
|
||||
log.NewInfo(operationID, utils.GetSelfFuncName(), "We already own ", config.Config.Credential.Minio.Bucket)
|
||||
} else {
|
||||
if err != nil {
|
||||
log.NewInfo(operationID, utils.GetSelfFuncName(), err.Error())
|
||||
}
|
||||
log.NewInfo(operationID, utils.GetSelfFuncName(), "create bucket failed and bucket not exists")
|
||||
return
|
||||
}
|
||||
}
|
||||
// make app bucket
|
||||
err = MinioClient.MakeBucket(context.Background(), config.Config.Credential.Minio.AppBucket, opt)
|
||||
if err != nil {
|
||||
log.NewInfo(operationID, utils.GetSelfFuncName(), "MakeBucket failed ", err.Error())
|
||||
exists, err := MinioClient.BucketExists(context.Background(), config.Config.Credential.Minio.Bucket)
|
||||
if err == nil && exists {
|
||||
log.NewInfo(operationID, utils.GetSelfFuncName(), "We already own ", config.Config.Credential.Minio.Bucket)
|
||||
} else {
|
||||
if err != nil {
|
||||
log.NewInfo(operationID, utils.GetSelfFuncName(), err.Error())
|
||||
}
|
||||
log.NewInfo(operationID, utils.GetSelfFuncName(), "create bucket failed and bucket not exists")
|
||||
return
|
||||
}
|
||||
}
|
||||
policy, err := MinioClient.GetBucketPolicy(context.Background(), config.Config.Credential.Minio.Bucket)
|
||||
log.NewInfo("", utils.GetSelfFuncName(), policy)
|
||||
|
||||
// 自动化桶public的代码
|
||||
policyJsonString := fmt.Sprintf(`{"Version": "2012-10-17","Statement": [{"Action": ["s3:GetObject","s3:PutObject"],
|
||||
"Effect": "Allow","Principal": {"AWS": ["*"]},"Resource": ["arn:aws:s3:::%s/*"],"Sid": ""}]}`, config.Config.Credential.Minio.Bucket)
|
||||
err = MinioClient.SetBucketPolicy(context.Background(), config.Config.Credential.Minio.Bucket, policyJsonString)
|
||||
if err != nil {
|
||||
log.NewInfo("", utils.GetSelfFuncName(), "SetBucketPolicy failed please set in web", err.Error())
|
||||
}
|
||||
policyJsonString = fmt.Sprintf(`{"Version": "2012-10-17","Statement": [{"Action": ["s3:GetObject","s3:PutObject"],
|
||||
"Effect": "Allow","Principal": {"AWS": ["*"]},"Resource": ["arn:aws:s3:::%s/*"],"Sid": ""}]}`, config.Config.Credential.Minio.AppBucket)
|
||||
err = MinioClient.SetBucketPolicy(context.Background(), config.Config.Credential.Minio.AppBucket, policyJsonString)
|
||||
if err != nil {
|
||||
log.NewInfo("", utils.GetSelfFuncName(), "SetBucketPolicy failed please set in web", err.Error())
|
||||
}
|
||||
log.NewInfo(operationID, utils.GetSelfFuncName(), "minio create and set policy success")
|
||||
}
|
||||
@@ -1,276 +0,0 @@
|
||||
package third
|
||||
|
||||
import (
|
||||
api "OpenIM/pkg/apistruct"
|
||||
"OpenIM/pkg/common/config"
|
||||
"OpenIM/pkg/common/constant"
|
||||
"OpenIM/pkg/common/log"
|
||||
"OpenIM/pkg/common/tokenverify"
|
||||
_ "OpenIM/pkg/common/tokenverify"
|
||||
"OpenIM/pkg/utils"
|
||||
"context"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/minio/minio-go/v7"
|
||||
_ "github.com/minio/minio-go/v7"
|
||||
cr "github.com/minio/minio-go/v7/pkg/credentials"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// @Summary minio上传文件(web api)
|
||||
// @Description minio上传文件(web api), 请注意本api请求为form并非json
|
||||
// @Tags 第三方服务相关
|
||||
// @ID MinioUploadFile
|
||||
// @Accept json
|
||||
// @Param token header string true "im token"
|
||||
// @Param file formData file true "要上传的文件文件"
|
||||
// @Param fileType formData int true "文件类型"
|
||||
// @Param operationID formData string true "操作唯一ID"
|
||||
// @Produce json
|
||||
// @Success 0 {object} api.MinioUploadFileResp ""
|
||||
// @Failure 500 {object} api.Swagger500Resp "errCode为500 一般为服务器内部错误"
|
||||
// @Failure 400 {object} api.Swagger400Resp "errCode为400 一般为参数输入错误, token未带上等"
|
||||
// @Router /third/minio_upload [post]
|
||||
func MinioUploadFile(c *gin.Context) {
|
||||
var (
|
||||
req api.MinioUploadFileReq
|
||||
resp api.MinioUploadFile
|
||||
)
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), r)
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "missing file or snapShot args"})
|
||||
return
|
||||
}
|
||||
}()
|
||||
if err := c.Bind(&req); err != nil {
|
||||
log.NewError("0", utils.GetSelfFuncName(), "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), req)
|
||||
var ok bool
|
||||
var errInfo string
|
||||
ok, _, errInfo = tokenverify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
|
||||
if !ok {
|
||||
errMsg := req.OperationID + " " + "GetUserIDFromToken failed " + errInfo + " token:" + c.Request.Header.Get("token")
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), req)
|
||||
switch req.FileType {
|
||||
// videoType upload snapShot
|
||||
case constant.VideoType:
|
||||
snapShotFile, err := c.FormFile("snapShot")
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "missing snapshot arg: " + err.Error()})
|
||||
return
|
||||
}
|
||||
snapShotFileObj, err := snapShotFile.Open()
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "Open file error", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
snapShotNewName, snapShotNewType := utils.GetNewFileNameAndContentType(snapShotFile.Filename, constant.ImageType)
|
||||
log.Debug(req.OperationID, utils.GetSelfFuncName(), snapShotNewName, snapShotNewType)
|
||||
_, err = MinioClient.PutObject(context.Background(), config.Config.Credential.Minio.Bucket, snapShotNewName, snapShotFileObj, snapShotFile.Size, minio.PutObjectOptions{ContentType: snapShotNewType})
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "PutObject snapShotFile error", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
resp.SnapshotURL = config.Config.Credential.Minio.Endpoint + "/" + config.Config.Credential.Minio.Bucket + "/" + snapShotNewName
|
||||
resp.SnapshotNewName = snapShotNewName
|
||||
}
|
||||
file, err := c.FormFile("file")
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "FormFile failed", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "missing file arg: " + err.Error()})
|
||||
return
|
||||
}
|
||||
fileObj, err := file.Open()
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "Open file error", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "invalid file path" + err.Error()})
|
||||
return
|
||||
}
|
||||
newName, newType := utils.GetNewFileNameAndContentType(file.Filename, req.FileType)
|
||||
log.Debug(req.OperationID, utils.GetSelfFuncName(), config.Config.Credential.Minio.Bucket, newName, fileObj, file.Size, newType, MinioClient.EndpointURL())
|
||||
_, err = MinioClient.PutObject(context.Background(), config.Config.Credential.Minio.Bucket, newName, fileObj, file.Size, minio.PutObjectOptions{ContentType: newType})
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "upload file error", err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "upload file error" + err.Error()})
|
||||
return
|
||||
}
|
||||
resp.NewName = newName
|
||||
resp.URL = config.Config.Credential.Minio.Endpoint + "/" + config.Config.Credential.Minio.Bucket + "/" + newName
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
|
||||
c.JSON(http.StatusOK, gin.H{"errCode": 0, "errMsg": "", "data": resp})
|
||||
return
|
||||
}
|
||||
|
||||
func MinioStorageCredential(c *gin.Context) {
|
||||
var (
|
||||
req api.MinioStorageCredentialReq
|
||||
resp api.MiniostorageCredentialResp
|
||||
)
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
log.NewError("0", utils.GetSelfFuncName(), "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req)
|
||||
var ok bool
|
||||
var errInfo string
|
||||
ok, _, errInfo = tokenverify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
|
||||
if !ok {
|
||||
errMsg := req.OperationID + " " + "GetUserIDFromToken failed " + errInfo + " token:" + c.Request.Header.Get("token")
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
|
||||
var stsOpts cr.STSAssumeRoleOptions
|
||||
stsOpts.AccessKey = config.Config.Credential.Minio.AccessKeyID
|
||||
stsOpts.SecretKey = config.Config.Credential.Minio.SecretAccessKey
|
||||
stsOpts.DurationSeconds = constant.MinioDurationTimes
|
||||
var endpoint string
|
||||
if config.Config.Credential.Minio.EndpointInnerEnable {
|
||||
endpoint = config.Config.Credential.Minio.EndpointInner
|
||||
} else {
|
||||
endpoint = config.Config.Credential.Minio.Endpoint
|
||||
}
|
||||
li, err := cr.NewSTSAssumeRole(endpoint, stsOpts)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "NewSTSAssumeRole failed", err.Error(), stsOpts, config.Config.Credential.Minio.Endpoint)
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
v, err := li.Get()
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "li.Get error", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
resp.SessionToken = v.SessionToken
|
||||
resp.SecretAccessKey = v.SecretAccessKey
|
||||
resp.AccessKeyID = v.AccessKeyID
|
||||
resp.BucketName = config.Config.Credential.Minio.Bucket
|
||||
resp.StsEndpointURL = config.Config.Credential.Minio.Endpoint
|
||||
resp.StorageTime = config.Config.Credential.Minio.StorageTime
|
||||
resp.IsDistributedMod = config.Config.Credential.Minio.IsDistributedMod
|
||||
c.JSON(http.StatusOK, gin.H{"errCode": 0, "errMsg": "", "data": resp})
|
||||
}
|
||||
|
||||
func UploadUpdateApp(c *gin.Context) {
|
||||
var (
|
||||
req api.UploadUpdateAppReq
|
||||
resp api.UploadUpdateAppResp
|
||||
)
|
||||
if err := c.Bind(&req); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req)
|
||||
|
||||
var yamlName string
|
||||
if req.Yaml == nil {
|
||||
yamlName = ""
|
||||
} else {
|
||||
yamlName = req.Yaml.Filename
|
||||
}
|
||||
fileObj, err := req.File.Open()
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "Open file error", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "Open file error" + err.Error()})
|
||||
return
|
||||
}
|
||||
_, err = MinioClient.PutObject(context.Background(), config.Config.Credential.Minio.AppBucket, req.File.Filename, fileObj, req.File.Size, minio.PutObjectOptions{})
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "PutObject file error")
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "PutObject file error" + err.Error()})
|
||||
return
|
||||
}
|
||||
if yamlName != "" {
|
||||
yamlObj, err := req.Yaml.Open()
|
||||
if err == nil {
|
||||
_, err = MinioClient.PutObject(context.Background(), config.Config.Credential.Minio.AppBucket, yamlName, yamlObj, req.Yaml.Size, minio.PutObjectOptions{})
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "PutObject yaml error")
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "PutObject yaml error" + err.Error()})
|
||||
return
|
||||
}
|
||||
} else {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error())
|
||||
}
|
||||
}
|
||||
if err := imdb.UpdateAppVersion(req.Type, req.Version, req.ForceUpdate, req.File.Filename, yamlName, req.UpdateLog); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "UpdateAppVersion error", err.Error())
|
||||
resp.ErrCode = http.StatusInternalServerError
|
||||
resp.ErrMsg = err.Error()
|
||||
c.JSON(http.StatusInternalServerError, resp)
|
||||
return
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName())
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func version2Int(version string) (int, error) {
|
||||
versions := strings.Split(version, ".")
|
||||
s := strings.Join(versions, "")
|
||||
versionInt, err := strconv.Atoi(s)
|
||||
return versionInt, err
|
||||
}
|
||||
|
||||
func GetDownloadURL(c *gin.Context) {
|
||||
var (
|
||||
req api.GetDownloadURLReq
|
||||
resp api.GetDownloadURLResp
|
||||
)
|
||||
defer func() {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
|
||||
}()
|
||||
if err := c.Bind(&req); err != nil {
|
||||
log.NewError("0", utils.GetSelfFuncName(), "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req)
|
||||
app, err := imdb.GetNewestVersion(req.Type)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "getNewestVersion failed", err.Error())
|
||||
}
|
||||
log.Debug(req.OperationID, utils.GetSelfFuncName(), "app: ", app)
|
||||
if app != nil {
|
||||
appVersion, err := version2Int(app.Version)
|
||||
reqVersion, err := version2Int(req.Version)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), "req version", req.Version, "app version", app.Version)
|
||||
}
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "req version:", reqVersion, "app version:", appVersion)
|
||||
if appVersion > reqVersion && app.Version != "" {
|
||||
resp.Data.HasNewVersion = true
|
||||
if app.ForceUpdate == true {
|
||||
resp.Data.ForceUpdate = true
|
||||
}
|
||||
if app.YamlName != "" {
|
||||
resp.Data.YamlURL = config.Config.Credential.Minio.Endpoint + "/" + config.Config.Credential.Minio.AppBucket + "/" + app.YamlName
|
||||
}
|
||||
resp.Data.FileURL = config.Config.Credential.Minio.Endpoint + "/" + config.Config.Credential.Minio.AppBucket + "/" + app.FileName
|
||||
resp.Data.Version = app.Version
|
||||
resp.Data.UpdateLog = app.UpdateLog
|
||||
c.JSON(http.StatusOK, resp)
|
||||
return
|
||||
} else {
|
||||
resp.Data.HasNewVersion = false
|
||||
c.JSON(http.StatusOK, resp)
|
||||
return
|
||||
}
|
||||
}
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 0, "errMsg": "not found app version"})
|
||||
}
|
||||
@@ -1,95 +0,0 @@
|
||||
package third
|
||||
|
||||
import (
|
||||
api "OpenIM/pkg/apistruct"
|
||||
"OpenIM/pkg/common/log"
|
||||
"OpenIM/pkg/common/tokenverify"
|
||||
"OpenIM/pkg/utils"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func GetRTCInvitationInfo(c *gin.Context) {
|
||||
var (
|
||||
req api.GetRTCInvitationInfoReq
|
||||
resp api.GetRTCInvitationInfoResp
|
||||
)
|
||||
if err := c.Bind(&req); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req)
|
||||
ok, userID, errInfo := tokenverify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
|
||||
if !ok {
|
||||
errMsg := req.OperationID + " " + "GetUserIDFromToken failed " + errInfo + " token:" + c.Request.Header.Get("token")
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
var err error
|
||||
invitationInfo, err := db.DB.GetSignalInfoFromCacheByClientMsgID(req.ClientMsgID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetSignalInfoFromCache", err.Error(), req)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
if err := db.DB.DelUserSignalList(userID); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "DelUserSignalList result:", err.Error())
|
||||
}
|
||||
|
||||
resp.Data.OpUserID = invitationInfo.OpUserID
|
||||
resp.Data.Invitation.RoomID = invitationInfo.Invitation.RoomID
|
||||
resp.Data.Invitation.SessionType = invitationInfo.Invitation.SessionType
|
||||
resp.Data.Invitation.GroupID = invitationInfo.Invitation.GroupID
|
||||
resp.Data.Invitation.InviterUserID = invitationInfo.Invitation.InviterUserID
|
||||
resp.Data.Invitation.InviteeUserIDList = invitationInfo.Invitation.InviteeUserIDList
|
||||
resp.Data.Invitation.MediaType = invitationInfo.Invitation.MediaType
|
||||
resp.Data.Invitation.Timeout = invitationInfo.Invitation.Timeout
|
||||
resp.Data.Invitation.InitiateTime = invitationInfo.Invitation.InitiateTime
|
||||
resp.Data.Invitation.PlatformID = invitationInfo.Invitation.PlatformID
|
||||
resp.Data.Invitation.CustomData = invitationInfo.Invitation.CustomData
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func GetRTCInvitationInfoStartApp(c *gin.Context) {
|
||||
var (
|
||||
req api.GetRTCInvitationInfoStartAppReq
|
||||
resp api.GetRTCInvitationInfoStartAppResp
|
||||
)
|
||||
if err := c.Bind(&req); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req)
|
||||
var ok bool
|
||||
var errInfo string
|
||||
ok, userID, errInfo := tokenverify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
|
||||
if !ok {
|
||||
errMsg := req.OperationID + " " + "GetUserIDFromToken failed " + errInfo + " token:" + c.Request.Header.Get("token")
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
|
||||
invitationInfo, err := db.DB.GetAvailableSignalInvitationInfo(userID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetSignalInfoFromCache", err.Error(), req)
|
||||
c.JSON(http.StatusOK, gin.H{"errCode": 0, "errMsg": err.Error(), "data": struct{}{}})
|
||||
return
|
||||
}
|
||||
resp.Data.OpUserID = invitationInfo.OpUserID
|
||||
resp.Data.Invitation.RoomID = invitationInfo.Invitation.RoomID
|
||||
resp.Data.Invitation.SessionType = invitationInfo.Invitation.SessionType
|
||||
resp.Data.Invitation.GroupID = invitationInfo.Invitation.GroupID
|
||||
resp.Data.Invitation.InviterUserID = invitationInfo.Invitation.InviterUserID
|
||||
resp.Data.Invitation.InviteeUserIDList = invitationInfo.Invitation.InviteeUserIDList
|
||||
resp.Data.Invitation.MediaType = invitationInfo.Invitation.MediaType
|
||||
resp.Data.Invitation.Timeout = invitationInfo.Invitation.Timeout
|
||||
resp.Data.Invitation.InitiateTime = invitationInfo.Invitation.InitiateTime
|
||||
resp.Data.Invitation.PlatformID = invitationInfo.Invitation.PlatformID
|
||||
resp.Data.Invitation.CustomData = invitationInfo.Invitation.CustomData
|
||||
c.JSON(http.StatusOK, resp)
|
||||
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
package third
|
||||
|
||||
import (
|
||||
api "OpenIM/pkg/apistruct"
|
||||
"OpenIM/pkg/common/log"
|
||||
"OpenIM/pkg/common/tokenverify"
|
||||
"OpenIM/pkg/utils"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func SetAppBadge(c *gin.Context) {
|
||||
var (
|
||||
req api.SetAppBadgeReq
|
||||
resp api.SetAppBadgeResp
|
||||
)
|
||||
if err := c.Bind(&req); err != nil {
|
||||
log.NewError("0", utils.GetSelfFuncName(), "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), req)
|
||||
|
||||
var ok bool
|
||||
var errInfo, opUserID string
|
||||
ok, opUserID, errInfo = tokenverify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
|
||||
if !ok {
|
||||
errMsg := req.OperationID + " " + "GetUserIDFromToken failed " + errInfo + " token:" + c.Request.Header.Get("token")
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
if !tokenverify.CheckAccess(c, opUserID, req.FromUserID) {
|
||||
log.NewError(req.OperationID, "CheckAccess false ", opUserID, req.FromUserID)
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "no permission"})
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), req, opUserID)
|
||||
err := db.DB.SetUserBadgeUnreadCountSum(req.FromUserID, int(req.AppUnreadCount))
|
||||
if err != nil {
|
||||
errMsg := req.OperationID + " " + "SetUserBadgeUnreadCountSum failed " + err.Error() + " token:" + c.Request.Header.Get("token")
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
resp.ErrCode = 500
|
||||
resp.ErrMsg = errMsg
|
||||
c.JSON(http.StatusInternalServerError, resp)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
return
|
||||
}
|
||||
@@ -1,78 +0,0 @@
|
||||
package third
|
||||
|
||||
import (
|
||||
api "OpenIM/pkg/apistruct"
|
||||
"OpenIM/pkg/common/config"
|
||||
"OpenIM/pkg/common/constant"
|
||||
"OpenIM/pkg/common/log"
|
||||
"OpenIM/pkg/common/tokenverify"
|
||||
"github.com/fatih/structs"
|
||||
|
||||
//"github.com/fatih/structs"
|
||||
"github.com/gin-gonic/gin"
|
||||
sts "github.com/tencentyun/qcloud-cos-sts-sdk/go"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TencentCloudStorageCredential(c *gin.Context) {
|
||||
req := api.TencentCloudStorageCredentialReq{}
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
log.NewError("0", "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
var ok bool
|
||||
var userID string
|
||||
var errInfo string
|
||||
ok, userID, errInfo = tokenverify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
|
||||
if !ok {
|
||||
errMsg := req.OperationID + " " + "GetUserIDFromToken failed " + errInfo + " token:" + c.Request.Header.Get("token")
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
|
||||
log.NewInfo(req.OperationID, "TencentCloudStorageCredential args ", userID)
|
||||
|
||||
cli := sts.NewClient(
|
||||
config.Config.Credential.Tencent.SecretID,
|
||||
config.Config.Credential.Tencent.SecretKey,
|
||||
nil,
|
||||
)
|
||||
|
||||
opt := &sts.CredentialOptions{
|
||||
DurationSeconds: int64(time.Hour.Seconds()),
|
||||
Region: config.Config.Credential.Tencent.Region,
|
||||
Policy: &sts.CredentialPolicy{
|
||||
Statement: []sts.CredentialPolicyStatement{
|
||||
{
|
||||
Action: []string{
|
||||
"name/cos:PostObject",
|
||||
"name/cos:PutObject",
|
||||
},
|
||||
Effect: "allow",
|
||||
Resource: []string{
|
||||
"qcs::cos:" + config.Config.Credential.Tencent.Region + ":uid/" + config.Config.Credential.Tencent.AppID + ":" + config.Config.Credential.Tencent.Bucket + "/*",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
res, err := cli.GetCredential(opt)
|
||||
resp := api.TencentCloudStorageCredentialResp{}
|
||||
if err != nil {
|
||||
resp.ErrCode = constant.ErrTencentCredential.ErrCode
|
||||
resp.ErrMsg = err.Error()
|
||||
} else {
|
||||
resp.CosData.Bucket = config.Config.Credential.Tencent.Bucket
|
||||
resp.CosData.Region = config.Config.Credential.Tencent.Region
|
||||
resp.CosData.CredentialResult = res
|
||||
}
|
||||
|
||||
resp.Data = structs.Map(&resp.CosData)
|
||||
log.NewInfo(req.OperationID, "TencentCloudStorageCredential return ", resp)
|
||||
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
Reference in New Issue
Block a user