7
0

oss包新增分片任务初始化接口 & 获取APK包版本接口

This commit is contained in:
余 欣怀 2024-07-17 14:50:29 +08:00
parent afb120c6f4
commit 897a719154
4 changed files with 147 additions and 0 deletions

View File

@ -0,0 +1,36 @@
package oss
import (
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/requests"
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/responses"
)
type GetApkVersionRequest struct {
*requests.JsonRequest
Filepath string `position:"Body" field:"filepath"`
}
type GetApkVersionResponse struct {
*responses.BaseResponse
Code int `json:"code"`
Msg string `json:"msg"`
Data struct {
VersionCode string `json:"versionCode"`
VersionName string `json:"versionName"`
} `json:"data"`
}
func CreateGetApkVersionRequest() (req *GetApkVersionRequest) {
req = &GetApkVersionRequest{
JsonRequest: &requests.JsonRequest{},
}
req.InitWithApiInfo(HOST, VERSION, "/api/apk/version")
req.Method = requests.POST
return
}
func CreateGetApkVersionResponse() *GetApkVersionResponse {
return &GetApkVersionResponse{
BaseResponse: &responses.BaseResponse{},
}
}

View File

@ -3,6 +3,8 @@ package oss
import ( import (
"errors" "errors"
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk" "golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk"
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/auth"
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/auth/credentials"
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/requests" "golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/requests"
) )
@ -24,6 +26,10 @@ func NewClient() (client *Client, err error) {
return return
} }
func NewClientWithSts() {
}
func (c *Client) PutOss(req *PutOssRequest) (resp *PutOssResponse, err error) { func (c *Client) PutOss(req *PutOssRequest) (resp *PutOssResponse, err error) {
if req.BucketName == "" { if req.BucketName == "" {
err = errors.New("bucket name is empty") err = errors.New("bucket name is empty")
@ -44,3 +50,16 @@ func (c *Client) DelOss(req *DelOssRequest) (resp *DelOssResponse, err error) {
err = c.DoAction(req, resp) err = c.DoAction(req, resp)
return return
} }
func (c *Client) InitMultipartUpload(req *InitMultipartUploadRequest) (resp *InitMultipartUploadResponse, err error) {
resp = CreateInitMultipartUploadResponse()
err = c.DoAction(req, resp)
return
}
func (c *Client) GetApkVersion(req *GetApkVersionRequest) (resp *GetApkVersionResponse, err error) {
resp = CreateGetApkVersionResponse()
sign, err := auth.NewSignerWithCredential(credentials.NewStsTokenCredential("", "ccc", ""), nil)
err = c.DoActionWithSigner(req, resp, sign)
return
}

View File

@ -39,3 +39,37 @@ func TestUpload_Del(t *testing.T) {
} }
t.Log(resp.Code) t.Log(resp.Code)
} }
func TestCreateInitMultipartUpload(t *testing.T) {
req := CreateInitMultipartUploadRequest()
req.Filepath = "test.jpg"
req.TargetType = "oss"
req.TargetName = "image"
client, err := NewClient()
if err != nil {
t.Error(err)
return
}
resp, err := client.InitMultipartUpload(req)
if err != nil {
t.Error(err)
return
}
t.Log(resp)
}
func TestClient_GetApkVersion(t *testing.T) {
req := CreateGetApkVersionRequest()
req.Filepath = "36c55c4c3a2f4c79e3917b989d580496.zip"
client, err := NewClient()
if err != nil {
t.Error(err)
return
}
resp, err := client.GetApkVersion(req)
if err != nil {
t.Error(err)
return
}
t.Log(resp.Data.VersionCode, resp.Data.VersionName)
}

View File

@ -0,0 +1,58 @@
package oss
import (
"crypto/md5"
"encoding/hex"
"fmt"
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/requests"
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/responses"
"time"
)
const (
multipartUploadKeys = "b4471b940d98"
)
type InitMultipartUploadRequest struct {
*requests.JsonRequest
Filepath string `position:"Body" field:"filepath"`
TargetType string `position:"Body" field:"target_type"`
TargetName string `position:"Body" field:"target_name"`
FileHash string `position:"Body" field:"file_hash"`
}
type InitMultipartUploadResponse struct {
*responses.BaseResponse
Code int `json:"code"`
Msg string `json:"msg"`
Data struct {
FileUploaded bool `json:"file_uploaded"`
UploadId string `json:"upload_id,omitempty"`
Links []Link `json:"links,omitempty"`
} `json:"data"`
}
type Link struct {
Href string `json:"href"`
Rel string `json:"rel"`
Method string `json:"method"`
}
func CreateInitMultipartUploadRequest() (req *InitMultipartUploadRequest) {
ts := fmt.Sprintf("%d", time.Now().Unix())
m := md5.Sum([]byte(ts + multipartUploadKeys))
sign := hex.EncodeToString(m[:])
req = &InitMultipartUploadRequest{
JsonRequest: &requests.JsonRequest{},
}
req.InitWithApiInfo(HOST, VERSION, "/api/upload/multipart/init?ts="+ts+"&sign="+sign)
return
}
func CreateInitMultipartUploadResponse() (resp *InitMultipartUploadResponse) {
resp = &InitMultipartUploadResponse{
BaseResponse: &responses.BaseResponse{},
}
return resp
}