Skip to content

Commit 800d433

Browse files
author
branshchen
committed
Merge branch 'master' into dev/metainsight-2.3
2 parents c1895a3 + 4bf6e48 commit 800d433

File tree

5 files changed

+414
-30
lines changed

5 files changed

+414
-30
lines changed

ci_media.go

Lines changed: 146 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1448,10 +1448,18 @@ type GetMediaInfoResult struct {
14481448
// 媒体信息接口 https://cloud.tencent.com/document/product/436/55672
14491449
func (s *CIService) GetMediaInfo(ctx context.Context, name string, opt *ObjectGetOptions, id ...string) (*GetMediaInfoResult, *Response, error) {
14501450
var u string
1451+
1452+
// 兼容 name 以 / 开头的情况
1453+
if strings.HasPrefix(name, "/") {
1454+
name = encodeURIComponent("/") + encodeURIComponent(name[1:], []byte{'/'})
1455+
} else {
1456+
name = encodeURIComponent(name, []byte{'/'})
1457+
}
1458+
14511459
if len(id) == 1 {
1452-
u = fmt.Sprintf("/%s?versionId=%s&ci-process=videoinfo", encodeURIComponent(name, []byte{'/'}), id[0])
1460+
u = fmt.Sprintf("/%s?versionId=%s&ci-process=videoinfo", name, id[0])
14531461
} else if len(id) == 0 {
1454-
u = fmt.Sprintf("/%s?ci-process=videoinfo", encodeURIComponent(name, []byte{'/'}))
1462+
u = fmt.Sprintf("/%s?ci-process=videoinfo", name)
14551463
} else {
14561464
return nil, nil, fmt.Errorf("wrong params")
14571465
}
@@ -4184,3 +4192,139 @@ func (s *CIService) CreateMultiGeneratePlayListJobs(ctx context.Context, opt *Cr
41844192
resp, err := s.client.send(ctx, &sendOpt)
41854193
return &res, resp, err
41864194
}
4195+
4196+
type VocabularyWeight struct {
4197+
Vocabulary string `xml:"Vocabulary,omitempty"`
4198+
Weight int `xml:"Weight,omitempty"`
4199+
}
4200+
4201+
// CreateAsrVocabularyTableOptions TODO
4202+
type CreateAsrVocabularyTableOptions struct {
4203+
XMLName xml.Name `xml:"Request"`
4204+
TableName string `xml:"TableName,omitempty"`
4205+
TableDescription string `xml:"TableDescription,omitempty"`
4206+
VocabularyWeights []VocabularyWeight `xml:"VocabularyWeights,omitempty"`
4207+
VocabularyWeightStr string `xml:"VocabularyWeightStr,omitempty"`
4208+
}
4209+
4210+
// CreateAsrVocabularyTableResult TODO
4211+
type CreateAsrVocabularyTableResult struct {
4212+
XMLName xml.Name `xml:"Response"`
4213+
Code string `xml:"Code,omitempty"`
4214+
Message string `xml:"Message,omitempty"`
4215+
TableId string `xml:"TableId,omitempty"`
4216+
RequestId string `xml:"RequestId,omitempty"`
4217+
}
4218+
4219+
func (s *CIService) CreateAsrVocabularyTable(ctx context.Context, opt *CreateAsrVocabularyTableOptions) (*CreateAsrVocabularyTableResult, *Response, error) {
4220+
var res CreateAsrVocabularyTableResult
4221+
sendOpt := sendOptions{
4222+
baseURL: s.client.BaseURL.CIURL,
4223+
uri: "/asrhotvocabtable",
4224+
method: http.MethodPost,
4225+
body: opt,
4226+
result: &res,
4227+
}
4228+
resp, err := s.client.send(ctx, &sendOpt)
4229+
return &res, resp, err
4230+
}
4231+
4232+
// DeleteAsrVocabularyTable TODO
4233+
func (s *CIService) DeleteAsrVocabularyTable(ctx context.Context, tableId string) (*Response, error) {
4234+
sendOpt := sendOptions{
4235+
baseURL: s.client.BaseURL.CIURL,
4236+
uri: "/asrhotvocabtable/" + tableId,
4237+
method: http.MethodDelete,
4238+
}
4239+
resp, err := s.client.send(ctx, &sendOpt)
4240+
return resp, err
4241+
}
4242+
4243+
// CreateAsrVocabularyTableOptions TODO
4244+
type UpdateAsrVocabularyTableOptions struct {
4245+
XMLName xml.Name `xml:"Request"`
4246+
TableId string `xml:"TableId,omitempty"`
4247+
TableName string `xml:"TableName,omitempty"`
4248+
TableDescription string `xml:"TableDescription,omitempty"`
4249+
VocabularyWeights []VocabularyWeight `xml:"VocabularyWeights,omitempty"`
4250+
VocabularyWeightStr string `xml:"VocabularyWeightStr,omitempty"`
4251+
}
4252+
4253+
type UpdateAsrVocabularyTableResult CreateAsrVocabularyTableResult
4254+
4255+
// UpdateAsrVocabularyTable TODO
4256+
func (s *CIService) UpdateAsrVocabularyTable(ctx context.Context, opt *UpdateAsrVocabularyTableOptions) (*UpdateAsrVocabularyTableResult, *Response, error) {
4257+
var res UpdateAsrVocabularyTableResult
4258+
sendOpt := sendOptions{
4259+
baseURL: s.client.BaseURL.CIURL,
4260+
uri: "/asrhotvocabtable",
4261+
method: http.MethodPut,
4262+
body: opt,
4263+
result: &res,
4264+
}
4265+
resp, err := s.client.send(ctx, &sendOpt)
4266+
return &res, resp, err
4267+
}
4268+
4269+
type VocabularyTable struct {
4270+
TableId string `xml:"TableId,omitempty"`
4271+
TableName string `xml:"TableName,omitempty"`
4272+
TableDescription string `xml:"TableDescription,omitempty"`
4273+
VocabularyWeights []VocabularyWeight `xml:"VocabularyWeights,omitempty"`
4274+
VocabularyWeightStr string `xml:"VocabularyWeightStr,omitempty"`
4275+
CreateTime string `xml:"CreateTime,omitempty"`
4276+
UpdateTime string `xml:"UpdateTime,omitempty"`
4277+
}
4278+
4279+
// DescribeAsrVocabularyTableResult TODO
4280+
type DescribeAsrVocabularyTableResult struct {
4281+
XMLName xml.Name `xml:"Response"`
4282+
RequestId string `xml:"RequestId,omitempty"`
4283+
TableId string `xml:"TableId,omitempty"`
4284+
TableName string `xml:"TableName,omitempty"`
4285+
TableDescription string `xml:"TableDescription,omitempty"`
4286+
VocabularyWeights []VocabularyWeight `xml:"VocabularyWeights,omitempty"`
4287+
VocabularyWeightStr string `xml:"VocabularyWeightStr,omitempty"`
4288+
CreateTime string `xml:"CreateTime,omitempty"`
4289+
UpdateTime string `xml:"UpdateTime,omitempty"`
4290+
}
4291+
4292+
// DescribeAsrVocabularyTable 查询指定的语音识别热词表
4293+
func (s *CIService) DescribeAsrVocabularyTable(ctx context.Context, tableId string) (*DescribeAsrVocabularyTableResult, *Response, error) {
4294+
var res DescribeAsrVocabularyTableResult
4295+
sendOpt := sendOptions{
4296+
baseURL: s.client.BaseURL.CIURL,
4297+
uri: "/asrhotvocabtable/" + tableId,
4298+
method: http.MethodGet,
4299+
result: &res,
4300+
}
4301+
resp, err := s.client.send(ctx, &sendOpt)
4302+
return &res, resp, err
4303+
}
4304+
4305+
// DescribeAsrVocabularyTablesOptions TODO
4306+
type DescribeAsrVocabularyTablesOptions struct {
4307+
Offset int `url:"offset,omitempty"`
4308+
Limit int `url:"limit,omitempty"`
4309+
}
4310+
4311+
type DescribeAsrVocabularyTablesResult struct {
4312+
XMLName xml.Name `xml:"Response"`
4313+
RequestId string `xml:"RequestId,omitempty"`
4314+
TotalCount string `xml:"TotalCount,omitempty"`
4315+
VocabularyTable []VocabularyTable `xml:"VocabularyTable,omitempty"`
4316+
}
4317+
4318+
// DescribeAsrVocabularyTables 查询语音识别热词表列表
4319+
func (s *CIService) DescribeAsrVocabularyTables(ctx context.Context, opt *DescribeAsrVocabularyTablesOptions) (*DescribeAsrVocabularyTablesResult, *Response, error) {
4320+
var res DescribeAsrVocabularyTablesResult
4321+
sendOpt := sendOptions{
4322+
baseURL: s.client.BaseURL.CIURL,
4323+
uri: "/asrhotvocabtable",
4324+
optQuery: opt,
4325+
method: http.MethodGet,
4326+
result: &res,
4327+
}
4328+
resp, err := s.client.send(ctx, &sendOpt)
4329+
return &res, resp, err
4330+
}

ci_media_test.go

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3728,3 +3728,103 @@ func TestCIService_CreateMultiGeneratePlayListJobs(t *testing.T) {
37283728
t.Fatalf("CI.CreateMultiGeneratePlayListJobs returned errors: %v", err)
37293729
}
37303730
}
3731+
3732+
func TestCIService_CreateAsrVocabularyTable(t *testing.T) {
3733+
setup()
3734+
defer teardown()
3735+
3736+
mux.HandleFunc("/asrhotvocabtable", func(w http.ResponseWriter, r *http.Request) {
3737+
testMethod(t, r, http.MethodPost)
3738+
})
3739+
3740+
opt := &CreateAsrVocabularyTableOptions{
3741+
TableName: "test",
3742+
TableDescription: "test",
3743+
VocabularyWeights: []VocabularyWeight{
3744+
{
3745+
Vocabulary: "test",
3746+
Weight: 10,
3747+
},
3748+
},
3749+
VocabularyWeightStr: "",
3750+
}
3751+
_, _, err := client.CI.CreateAsrVocabularyTable(context.Background(), opt)
3752+
if err != nil {
3753+
t.Fatalf("CI.CreateAsrVocabularyTable returned error: %v", err)
3754+
}
3755+
}
3756+
3757+
func TestCIService_DeleteAsrVocabularyTable(t *testing.T) {
3758+
setup()
3759+
defer teardown()
3760+
3761+
tableId := "123"
3762+
mux.HandleFunc(fmt.Sprintf("/asrhotvocabtable/%s", tableId), func(w http.ResponseWriter, r *http.Request) {
3763+
testMethod(t, r, http.MethodDelete)
3764+
})
3765+
3766+
_, err := client.CI.DeleteAsrVocabularyTable(context.Background(), tableId)
3767+
if err != nil {
3768+
t.Fatalf("CI.DeleteAsrVocabularyTable returned error: %v", err)
3769+
}
3770+
}
3771+
3772+
func TestCIService_UpdateAsrVocabularyTable(t *testing.T) {
3773+
setup()
3774+
defer teardown()
3775+
3776+
mux.HandleFunc("/asrhotvocabtable", func(w http.ResponseWriter, r *http.Request) {
3777+
testMethod(t, r, http.MethodPut)
3778+
})
3779+
3780+
opt := &UpdateAsrVocabularyTableOptions{
3781+
TableId: "123",
3782+
TableName: "test",
3783+
TableDescription: "test",
3784+
VocabularyWeights: []VocabularyWeight{
3785+
{
3786+
Vocabulary: "test",
3787+
Weight: 10,
3788+
},
3789+
},
3790+
VocabularyWeightStr: "",
3791+
}
3792+
_, _, err := client.CI.UpdateAsrVocabularyTable(context.Background(), opt)
3793+
if err != nil {
3794+
t.Fatalf("CI.UpdateAsrVocabularyTable returned error: %v", err)
3795+
}
3796+
}
3797+
3798+
func TestCIService_DescribeAsrVocabularyTable(t *testing.T) {
3799+
setup()
3800+
defer teardown()
3801+
3802+
tableId := "123"
3803+
mux.HandleFunc(fmt.Sprintf("/asrhotvocabtable/%s", tableId), func(w http.ResponseWriter, r *http.Request) {
3804+
testMethod(t, r, http.MethodGet)
3805+
})
3806+
3807+
_, _, err := client.CI.DescribeAsrVocabularyTable(context.Background(), tableId)
3808+
if err != nil {
3809+
t.Fatalf("CI.DescribeAsrVocabularyTable returned error: %v", err)
3810+
}
3811+
}
3812+
3813+
func TestCIService_DescribeAsrVocabularyTables(t *testing.T) {
3814+
setup()
3815+
defer teardown()
3816+
3817+
mux.HandleFunc("/asrhotvocabtable", func(w http.ResponseWriter, r *http.Request) {
3818+
testMethod(t, r, http.MethodGet)
3819+
})
3820+
3821+
opt := &DescribeAsrVocabularyTablesOptions{
3822+
Offset: 0,
3823+
Limit: 100,
3824+
}
3825+
3826+
_, _, err := client.CI.DescribeAsrVocabularyTables(context.Background(), opt)
3827+
if err != nil {
3828+
t.Fatalf("CI.DescribeAsrVocabularyTables returned error: %v", err)
3829+
}
3830+
}

cos.go

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626

2727
const (
2828
// Version current go sdk version
29-
Version = "0.7.57"
29+
Version = "0.7.59"
3030
UserAgent = "cos-go-sdk-v5/" + Version
3131
contentTypeXML = "application/xml"
3232
defaultServiceBaseURL = "http://service.cos.myqcloud.com"
@@ -48,11 +48,9 @@ var (
4848
regionChecker = regexp.MustCompile(`^[a-z-1]+$`)
4949

5050
// 校验传入的url
51-
domainSuffix = regexp.MustCompile(`^.*\.(myqcloud\.com(:[0-9]+){0,1}|tencentcos\.cn(:[0-9]+){0,1})$`)
52-
bucketDomainChecker = regexp.MustCompile(`^(http://|https://){0,1}([a-z0-9-]+-[0-9]+\.){0,1}((cos|cos-internal|cos-website|ci)\.[a-z-1]+|file)\.(myqcloud\.com|tencentcos\.cn)(:[0-9]+){0,1}$`)
53-
serviceDomainChecker = regexp.MustCompile(`^(http://|https://){0,1}((service.cos.myqcloud.com|service.cos-internal.tencentcos.cn|service.cos.tencentcos.cn)|(cos|cos-internal)\.[a-z-1]+\.(myqcloud\.com|tencentcos\.cn))(:[0-9]+){0,1}$`)
54-
batchDomainChecker = regexp.MustCompile(`^(http://|https://){0,1}([0-9]+\.){1}cos-control\.[a-z-1]+\.(myqcloud\.com|tencentcos\.cn)(:[0-9]+){0,1}$`)
55-
invalidBucketErr = fmt.Errorf("invalid bucket format, please check your cos.BaseURL")
51+
domainSuffix = regexp.MustCompile(`^.*\.(myqcloud\.com(:[0-9]+){0,1}|tencentcos\.cn(:[0-9]+){0,1})$`)
52+
bucketDomainChecker = regexp.MustCompile(`^(http://|https://){0,1}([a-z0-9-]+\.)+(myqcloud\.com|tencentcos\.cn)(:[0-9]+){0,1}$`)
53+
invalidBucketErr = fmt.Errorf("invalid bucket format, please check your cos.BaseURL")
5654

5755
switchHost = regexp.MustCompile(`([a-z0-9-]+-[0-9]+\.)(cos\.[a-z-1]+)\.(myqcloud\.com)(:[0-9]+){0,1}$`)
5856
accelerateDomainSuffix = "accelerate.myqcloud.com"
@@ -86,19 +84,14 @@ func (*BaseURL) innerCheck(u *url.URL, reg *regexp.Regexp) bool {
8684
if !strings.HasPrefix(urlStr, "https://") && !strings.HasPrefix(urlStr, "http://") {
8785
return false
8886
}
89-
if strings.Count(urlStr, "/") > 2 {
90-
return false
91-
}
9287
if domainSuffix.MatchString(urlStr) && !reg.MatchString(urlStr) {
9388
return false
9489
}
9590
return true
9691
}
9792

9893
func (u *BaseURL) Check() bool {
99-
return u.innerCheck(u.BucketURL, bucketDomainChecker) &&
100-
(u.innerCheck(u.ServiceURL, serviceDomainChecker) || u.innerCheck(u.ServiceURL, bucketDomainChecker)) &&
101-
(u.innerCheck(u.BatchURL, batchDomainChecker) || u.innerCheck(u.BatchURL, bucketDomainChecker))
94+
return u.innerCheck(u.BucketURL, bucketDomainChecker) && u.innerCheck(u.ServiceURL, bucketDomainChecker) && u.innerCheck(u.BatchURL, bucketDomainChecker)
10295
}
10396

10497
// NewBucketURL 生成 BaseURL 所需的 BucketURL
@@ -232,6 +225,10 @@ func NewClient(uri *BaseURL, httpClient *http.Client) *Client {
232225
return c
233226
}
234227

228+
func (c *Client) DisableURLCheck() {
229+
c.invalidURL = false
230+
}
231+
235232
type Credential struct {
236233
SecretID string
237234
SecretKey string
@@ -347,7 +344,7 @@ func (c *Client) doAPI(ctx context.Context, req *http.Request, result interface{
347344
ctx, cancel = context.WithCancel(ctx)
348345
defer cancel()
349346
}
350-
//req = req.WithContext(ctx)
347+
req = req.WithContext(ctx)
351348

352349
resp, err := c.client.Do(req)
353350
if err != nil {

cos_test.go

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,15 @@ func Test_BaseURL(t *testing.T) {
278278
if !(&BaseURL{BucketURL: u, ServiceURL: u, BatchURL: u}).Check() {
279279
t.Errorf("BaseURL check failed: %v", u)
280280
}
281-
u, _ = url.Parse("https://example-125000000.cos-internal.accelerate.tencentcos.cn:443")
281+
u, _ = url.Parse("https://cluster-1.cos-2.ap-guangzhou.myqcloud.com")
282+
if !(&BaseURL{BucketURL: u, ServiceURL: u, BatchURL: u}).Check() {
283+
t.Errorf("BaseURL check failed: %v", u)
284+
}
285+
u, _ = url.Parse("https://test-1250000.global.tencentcos.cn")
286+
if !(&BaseURL{BucketURL: u, ServiceURL: u, BatchURL: u}).Check() {
287+
t.Errorf("BaseURL check failed: %v", u)
288+
}
289+
u, _ = url.Parse("http://1.cos-c-internal.ap-singapore.tencentcos.cn")
282290
if !(&BaseURL{BucketURL: u, ServiceURL: u, BatchURL: u}).Check() {
283291
t.Errorf("BaseURL check failed: %v", u)
284292
}
@@ -291,7 +299,7 @@ func Test_BaseURL(t *testing.T) {
291299
if (&BaseURL{BucketURL: u, ServiceURL: u, BatchURL: u}).Check() {
292300
t.Errorf("BaseURL check failed: %v", u)
293301
}
294-
u, _ = url.Parse("https://example-125000000.cos.ap-chengdu@123.com/myqcloud.com")
302+
u, _ = url.Parse("https://example-125000000.cos.ap-chengdu@123.com/.myqcloud.com")
295303
if (&BaseURL{BucketURL: u, ServiceURL: u, BatchURL: u}).Check() {
296304
t.Errorf("BaseURL check failed: %v", u)
297305
}
@@ -341,17 +349,4 @@ func Test_BaseURL(t *testing.T) {
341349
if !(&BaseURL{BatchURL: u}).Check() {
342350
t.Errorf("BaseURL check failed: %v", u)
343351
}
344-
u, _ = url.Parse("http://cos-control.ap-guangzhou.tencentcos.cn")
345-
if (&BaseURL{BatchURL: u}).Check() {
346-
t.Errorf("BaseURL check failed: %v", u)
347-
}
348-
u, _ = url.Parse("http://cos-control.ap-guangzhou.myqcloud.com")
349-
if (&BaseURL{BatchURL: u}).Check() {
350-
t.Errorf("BaseURL check failed: %v", u)
351-
}
352-
u, _ = url.Parse("http://cos-control.ap-guangzhou.myqcloud.com/www.com")
353-
if (&BaseURL{BatchURL: u}).Check() {
354-
t.Errorf("BaseURL check failed: %v", u)
355-
}
356-
357352
}

0 commit comments

Comments
 (0)