Skip to content

Commit e00597c

Browse files
committed
Merge branch 'dev-cifile' into 'master' (merge request !49)
dev-cifile 增加文件处理接口 审核冻结参数 直播审核转存参数
2 parents c57d309 + 30100a6 commit e00597c

File tree

3 files changed

+279
-18
lines changed

3 files changed

+279
-18
lines changed

ci.go

Lines changed: 46 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,17 @@ type UserExtraInfo struct {
215215
Role string `xml:",omitempty"`
216216
}
217217

218+
// FreezeConf is auto freeze options
219+
type FreezeConf struct {
220+
PornScore string `xml:",omitempty"`
221+
IllegalScore string `xml:",omitempty"`
222+
TerrorismScore string `xml:",omitempty"`
223+
PoliticsScore string `xml:",omitempty"`
224+
AdsScore string `xml:",omitempty"`
225+
AbuseScore string `xml:",omitempty"`
226+
TeenagerScore string `xml:",omitempty"`
227+
}
228+
218229
// ImageAuditingInputOptions is the option of BatchImageAuditingOptions
219230
type ImageAuditingInputOptions struct {
220231
DataId string `xml:",omitempty"`
@@ -229,10 +240,11 @@ type ImageAuditingInputOptions struct {
229240

230241
// ImageAuditingJobConf is the config of BatchImageAuditingOptions
231242
type ImageAuditingJobConf struct {
232-
DetectType string `xml:",omitempty"`
233-
BizType string `xml:",omitempty"`
234-
Async int `xml:",omitempty"`
235-
Callback string `xml:",omitempty"`
243+
DetectType string `xml:",omitempty"`
244+
BizType string `xml:",omitempty"`
245+
Async int `xml:",omitempty"`
246+
Callback string `xml:",omitempty"`
247+
Freeze *FreezeConf `xml:",omitempty"`
236248
}
237249

238250
// BatchImageAuditingOptions is the option of BatchImageAuditing
@@ -265,6 +277,7 @@ type ImageAuditingResult struct {
265277
CompressionResult int `xml:",omitempty"`
266278
UserInfo *UserExtraInfo `xml:",omitempty"`
267279
ListInfo *UserListInfo `xml:",omitempty"`
280+
ForbidState int `xml:",omitempty"`
268281
}
269282

270283
// BatchImageAuditingJobResult is the result of BatchImageAuditing
@@ -317,6 +330,7 @@ type PutVideoAuditingJobOptions struct {
317330
InputUserInfo *UserExtraInfo `xml:"Input>UserInfo,omitempty"`
318331
Conf *VideoAuditingJobConf `xml:"Conf"`
319332
Type string `xml:"Type,omitempty"`
333+
StorageConf *StorageConf `xml:"StorageConf,omitempty"`
320334
}
321335

322336
// VideoAuditingJobConf is the config of PutVideoAuditingJobOptions
@@ -328,6 +342,7 @@ type VideoAuditingJobConf struct {
328342
CallbackType int `xml:",omitempty"`
329343
BizType string `xml:",omitempty"`
330344
DetectContent int `xml:",omitempty"`
345+
Freeze *FreezeConf `xml:",omitempty"`
331346
}
332347

333348
// PutVideoAuditingJobSnapshot is the snapshot config of VideoAuditingJobConf
@@ -337,6 +352,11 @@ type PutVideoAuditingJobSnapshot struct {
337352
TimeInterval float32 `xml:",omitempty"`
338353
}
339354

355+
// StorageConf is live video storage config of PutVideoAuditingJobOptions
356+
type StorageConf struct {
357+
Path string `xml:",omitempty"`
358+
}
359+
340360
// PutVideoAuditingJobResult is the result of PutVideoAuditingJob
341361
type PutVideoAuditingJobResult struct {
342362
XMLName xml.Name `xml:"Response"`
@@ -394,6 +414,7 @@ type AuditingJobDetail struct {
394414
UserInfo *UserExtraInfo `xml:",omitempty"`
395415
Type string `xml:",omitempty"`
396416
ListInfo *UserListInfo `xml:",omitempty"`
417+
ForbidState int `xml:",omitempty"`
397418
}
398419

399420
// GetVideoAuditingJobSnapshot is the snapshot result of AuditingJobDetail
@@ -417,6 +438,7 @@ type AudioSectionResult struct {
417438
OffsetTime int `xml:",omitempty"`
418439
Duration int `xml:",omitempty"`
419440
Label string `xml:",omitempty"`
441+
SubLabel string `xml:",omitempty"`
420442
Result int `xml:",omitempty"`
421443
PornInfo *RecognitionInfo `xml:",omitempty"`
422444
TerrorismInfo *RecognitionInfo `xml:",omitempty"`
@@ -464,11 +486,12 @@ type PutAudioAuditingJobOptions struct {
464486

465487
// AudioAuditingJobConf is the config of PutAudioAuditingJobOptions
466488
type AudioAuditingJobConf struct {
467-
DetectType string `xml:",omitempty"`
468-
Callback string `xml:",omitempty"`
469-
CallbackVersion string `xml:",omitempty"`
470-
CallbackType int `xml:",omitempty"`
471-
BizType string `xml:",omitempty"`
489+
DetectType string `xml:",omitempty"`
490+
Callback string `xml:",omitempty"`
491+
CallbackVersion string `xml:",omitempty"`
492+
CallbackType int `xml:",omitempty"`
493+
BizType string `xml:",omitempty"`
494+
Freeze *FreezeConf `xml:",omitempty"`
472495
}
473496

474497
// PutAudioAuditingJobResult is the result of PutAudioAuditingJob
@@ -517,6 +540,7 @@ type AudioAuditingJobDetail struct {
517540
Section []AudioSectionResult `xml:",omitempty"`
518541
UserInfo *UserExtraInfo `xml:",omitempty"`
519542
ListInfo *UserListInfo `xml:",omitempty"`
543+
ForbidState int `xml:",omitempty"`
520544
}
521545

522546
// LanguageResult 语种识别结果
@@ -553,11 +577,12 @@ type PutTextAuditingJobOptions struct {
553577

554578
// TextAuditingJobConf is the config of PutAudioAuditingJobOptions
555579
type TextAuditingJobConf struct {
556-
DetectType string `xml:",omitempty"`
557-
Callback string `xml:",omitempty"`
558-
CallbackVersion string `xml:",omitempty"`
559-
BizType string `xml:",omitempty"`
560-
CallbackType int `xml:",omitempty"`
580+
DetectType string `xml:",omitempty"`
581+
Callback string `xml:",omitempty"`
582+
CallbackVersion string `xml:",omitempty"`
583+
BizType string `xml:",omitempty"`
584+
CallbackType int `xml:",omitempty"`
585+
Freeze *FreezeConf `xml:",omitempty"`
561586
}
562587

563588
// PutTextAuditingJobResult is the result of PutTextAuditingJob
@@ -607,6 +632,7 @@ type TextAuditingJobDetail struct {
607632
Section []TextSectionResult `xml:",omitempty"`
608633
UserInfo *UserExtraInfo `xml:",omitempty"`
609634
ListInfo *UserListInfo `xml:",omitempty"`
635+
ForbidState int `xml:",omitempty"`
610636
}
611637

612638
// TextLibResult
@@ -666,10 +692,11 @@ type PutDocumentAuditingJobOptions struct {
666692

667693
// DocumentAuditingJobConf is the config of PutDocumentAuditingJobOptions
668694
type DocumentAuditingJobConf struct {
669-
DetectType string `xml:",omitempty"`
670-
Callback string `xml:",omitempty"`
671-
BizType string `xml:",omitempty"`
672-
CallbackType int `xml:",omitempty"`
695+
DetectType string `xml:",omitempty"`
696+
Callback string `xml:",omitempty"`
697+
BizType string `xml:",omitempty"`
698+
CallbackType int `xml:",omitempty"`
699+
Freeze *FreezeConf `xml:",omitempty"`
673700
}
674701

675702
// PutDocumentAuditingJobResult is the result of PutDocumentAuditingJob
@@ -713,6 +740,7 @@ type DocumentAuditingJobDetail struct {
713740
PageSegment *DocumentPageSegmentInfo `xml:",omitempty"`
714741
UserInfo *UserExtraInfo `xml:",omitempty"`
715742
ListInfo *UserListInfo `xml:",omitempty"`
743+
ForbidState int `xml:",omitempty"`
716744
}
717745

718746
// DocumentResultInfo

ci_fileprocess.go

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
package cos
2+
3+
import (
4+
"context"
5+
"encoding/xml"
6+
"net/http"
7+
)
8+
9+
type FileHashCodeConfig struct {
10+
Type string `xml:",omitempty"`
11+
AddToHeader bool `xml:",omitempty"`
12+
}
13+
14+
type FileHashCodeResult struct {
15+
MD5 string `xml:",omitempty"`
16+
SHA1 string `xml:",omitempty"`
17+
SHA256 string `xml:",omitempty"`
18+
FileSize int `xml:",omitempty"`
19+
LastModified string `xml:",omitempty"`
20+
Etag string `xml:",omitempty"`
21+
}
22+
23+
type FileUncompressConfig struct {
24+
Prefix string `xml:",omitempty"`
25+
PrefixReplaced string `xml:",omitempty"`
26+
}
27+
28+
type FileUncompressResult struct {
29+
Region string `xml:",omitempty"`
30+
Bucket string `xml:",omitempty"`
31+
FileCount string `xml:",omitempty"`
32+
}
33+
34+
type FileCompressConfig struct {
35+
Flatten string `xml:",omitempty"`
36+
Format string `xml:",omitempty"`
37+
UrlList string `xml:",omitempty"`
38+
Prefix string `xml:",omitempty"`
39+
Key string `xml:",omitempty"`
40+
}
41+
42+
type FileCompressResult struct {
43+
Region string `xml:",omitempty"`
44+
Bucket string `xml:",omitempty"`
45+
Object string `xml:",omitempty"`
46+
}
47+
48+
type FileProcessInput FileCompressResult
49+
type FileProcessOutput FileCompressResult
50+
51+
type FileProcessJobOperation struct {
52+
FileHashCodeConfig *FileHashCodeConfig `xml:",omitempty"`
53+
FileHashCodeResult *FileHashCodeResult `xml:",omitempty"`
54+
FileUncompressConfig *FileUncompressConfig `xml:",omitempty"`
55+
FileUncompressResult *FileUncompressResult `xml:",omitempty"`
56+
FileCompressConfig *FileCompressConfig `xml:",omitempty"`
57+
FileCompressResult *FileCompressResult `xml:",omitempty"`
58+
Output *FileProcessOutput `xml:",omitempty"`
59+
UserData string `xml:",omitempty"`
60+
}
61+
62+
type FileProcessJobOptions struct {
63+
XMLName xml.Name `xml:"Request"`
64+
Tag string `xml:",omitempty"`
65+
Input *FileProcessInput `xml:",omitempty"`
66+
Operation *FileProcessJobOperation `xml:",omitempty"`
67+
QueueId string `xml:",omitempty"`
68+
CallBackFormat string `xml:",omitempty"`
69+
CallBackType string `xml:",omitempty"`
70+
CallBack string `xml:",omitempty"`
71+
CallBackMqConfig string `xml:",omitempty"`
72+
}
73+
74+
type FileProcessJobResult struct {
75+
XMLName xml.Name `xml:"Response"`
76+
JobsDetail *FileProcessJobsDetail `xml:",omitempty"`
77+
}
78+
79+
type FileProcessJobsDetail struct {
80+
Code string `xml:",omitempty"`
81+
Message string `xml:",omitempty"`
82+
JobId string `xml:",omitempty"`
83+
Tag string `xml:",omitempty"`
84+
State string `xml:",omitempty"`
85+
CreationTime string `xml:",omitempty"`
86+
StartTime string `xml:",omitempty"`
87+
EndTime string `xml:",omitempty"`
88+
QueueId string `xml:",omitempty"`
89+
Input *FileProcessInput `xml:",omitempty"`
90+
Operation *FileProcessJobOperation `xml:",omitempty"`
91+
}
92+
93+
// 提交哈希值计算任务 https://cloud.tencent.com/document/product/436/83108
94+
// 提交文件解压任务 https://cloud.tencent.com/document/product/436/83110
95+
// 提交多文件打包压缩任务 https://cloud.tencent.com/document/product/436/83112
96+
func (s *CIService) CreateFileProcessJob(ctx context.Context, opt *FileProcessJobOptions) (*FileProcessJobResult, *Response, error) {
97+
var res FileProcessJobResult
98+
sendOpt := sendOptions{
99+
baseURL: s.client.BaseURL.CIURL,
100+
uri: "/file_jobs",
101+
method: http.MethodPost,
102+
body: opt,
103+
result: &res,
104+
}
105+
resp, err := s.client.send(ctx, &sendOpt)
106+
return &res, resp, err
107+
}
108+
109+
// 查询哈希值计算结果 https://cloud.tencent.com/document/product/436/83109
110+
// 查询文件解压结果 https://cloud.tencent.com/document/product/436/83111
111+
// 查询多文件打包压缩结果 https://cloud.tencent.com/document/product/436/83113
112+
func (s *CIService) DescribeFileProcessJob(ctx context.Context, jobid string) (*FileProcessJobResult, *Response, error) {
113+
var res FileProcessJobResult
114+
sendOpt := sendOptions{
115+
baseURL: s.client.BaseURL.CIURL,
116+
uri: "/file_jobs/" + jobid,
117+
method: http.MethodGet,
118+
result: &res,
119+
}
120+
resp, err := s.client.send(ctx, &sendOpt)
121+
return &res, resp, err
122+
}
123+
124+
// GetFileHashOptions is the option of GetFileHash
125+
type GetFileHashOptions struct {
126+
CIProcess string `url:"ci-process,omitempty"`
127+
Type string `url:"type,omitempty"`
128+
AddToHeader bool `url:"addtoheader,omitempty"`
129+
}
130+
131+
// GetFileHashResult is the result of GetFileHash
132+
type GetFileHashResult struct {
133+
XMLName xml.Name `xml:"Response"`
134+
FileHashCodeResult *FileHashCodeResult `xml:",omitempty"`
135+
Input *FileProcessInput `xml:",omitempty"`
136+
}
137+
138+
// 哈希值计算同步请求 https://cloud.tencent.com/document/product/436/83107
139+
func (s *CIService) GetFileHash(ctx context.Context, name string, opt *GetFileHashOptions) (*GetFileHashResult, *Response, error) {
140+
var res GetFileHashResult
141+
sendOpt := sendOptions{
142+
baseURL: s.client.BaseURL.BucketURL,
143+
uri: "/" + encodeURIComponent(name),
144+
method: http.MethodGet,
145+
optQuery: opt,
146+
result: &res,
147+
}
148+
resp, err := s.client.send(ctx, &sendOpt)
149+
return &res, resp, err
150+
}

ci_fileprocess_test.go

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package cos
2+
3+
import (
4+
"context"
5+
"net/http"
6+
"testing"
7+
)
8+
9+
func TestCIService_CreateFileProcessJob(t *testing.T) {
10+
setup()
11+
defer teardown()
12+
wantBody := "<Request><Tag>FileHashCode</Tag><Input><Object>294028.zip</Object></Input>" +
13+
"<Operation><FileHashCodeConfig><Type>sha1</Type><AddToHeader>true</AddToHeader>" +
14+
"</FileHashCodeConfig></Operation><QueueId>pb6a88aead4dd4fa8bc953d4ca4e04430</QueueId></Request>"
15+
16+
mux.HandleFunc("/file_jobs", func(w http.ResponseWriter, r *http.Request) {
17+
testMethod(t, r, http.MethodPost)
18+
testHeader(t, r, "Content-Type", "application/xml")
19+
testBody(t, r, wantBody)
20+
})
21+
22+
createJobOpt := &FileProcessJobOptions{
23+
Tag: "FileHashCode",
24+
Input: &FileProcessInput{
25+
Object: "294028.zip",
26+
},
27+
Operation: &FileProcessJobOperation{
28+
FileHashCodeConfig: &FileHashCodeConfig{
29+
Type: "sha1",
30+
AddToHeader: true,
31+
},
32+
},
33+
QueueId: "pb6a88aead4dd4fa8bc953d4ca4e04430",
34+
}
35+
36+
_, _, err := client.CI.CreateFileProcessJob(context.Background(), createJobOpt)
37+
if err != nil {
38+
t.Fatalf("CI.CreateFileProcessJob returned error: %v", err)
39+
}
40+
}
41+
42+
func TestCIService_DescribeFileProcessJob(t *testing.T) {
43+
setup()
44+
defer teardown()
45+
46+
jobID := "f9640f1b0874211edb47e5fa2d6bd5e47"
47+
mux.HandleFunc("/file_jobs"+"/"+jobID, func(w http.ResponseWriter, r *http.Request) {
48+
testMethod(t, r, http.MethodGet)
49+
})
50+
51+
_, _, err := client.CI.DescribeFileProcessJob(context.Background(), jobID)
52+
53+
if err != nil {
54+
t.Fatalf("CI.DescribeFileProcessJob returned error: %v", err)
55+
}
56+
}
57+
58+
func TestCIService_GetFileHash(t *testing.T) {
59+
setup()
60+
defer teardown()
61+
62+
name := "sample.pdf"
63+
mux.HandleFunc("/"+name, func(w http.ResponseWriter, r *http.Request) {
64+
testMethod(t, r, http.MethodGet)
65+
v := values{
66+
"ci-process": "filehash",
67+
"type": "sha1",
68+
"addtoheader": "true",
69+
}
70+
testFormValues(t, r, v)
71+
})
72+
73+
opt := &GetFileHashOptions{
74+
CIProcess: "filehash",
75+
Type: "sha1",
76+
AddToHeader: true,
77+
}
78+
79+
_, _, err := client.CI.GetFileHash(context.Background(), name, opt)
80+
if err != nil {
81+
t.Fatalf("CI.GetFileHash returned error: %v", err)
82+
}
83+
}

0 commit comments

Comments
 (0)