oss包新增分片任务初始化接口 & 获取APK包版本接口
This commit is contained in:
parent
afb120c6f4
commit
897a719154
36
services/oss/ApkVersion_get.go
Normal file
36
services/oss/ApkVersion_get.go
Normal 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{},
|
||||
}
|
||||
}
|
@ -3,6 +3,8 @@ package oss
|
||||
import (
|
||||
"errors"
|
||||
"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"
|
||||
)
|
||||
|
||||
@ -24,6 +26,10 @@ func NewClient() (client *Client, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func NewClientWithSts() {
|
||||
|
||||
}
|
||||
|
||||
func (c *Client) PutOss(req *PutOssRequest) (resp *PutOssResponse, err error) {
|
||||
if req.BucketName == "" {
|
||||
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)
|
||||
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
|
||||
}
|
||||
|
@ -39,3 +39,37 @@ func TestUpload_Del(t *testing.T) {
|
||||
}
|
||||
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)
|
||||
}
|
||||
|
58
services/oss/multipart_init.go
Normal file
58
services/oss/multipart_init.go
Normal 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
|
||||
}
|
Loading…
Reference in New Issue
Block a user