@@ -4,49 +4,49 @@ import (
44 "context"
55 "encoding/json"
66 "encoding/xml"
7- "io"
87 "net/http"
98)
109
10+ type CIService service
11+
1112type PicOperations struct {
1213 IsPicInfo int `json:"is_pic_info,omitempty"`
1314 Rules []PicOperationsRules `json:"rules,omitemtpy"`
1415}
15-
1616type PicOperationsRules struct {
1717 Bucket string `json:"bucket,omitempty"`
1818 FileId string `json:"fileid"`
1919 Rule string `json:"rule"`
2020}
2121
2222func EncodePicOperations (pic * PicOperations ) string {
23+ if pic == nil {
24+ return ""
25+ }
2326 bs , err := json .Marshal (pic )
2427 if err != nil {
2528 return ""
2629 }
2730 return string (bs )
2831}
2932
30- type CloudImageReuslt struct {
33+ type ImageProcessResult struct {
3134 XMLName xml.Name `xml:"UploadResult"`
3235 OriginalInfo * PicOriginalInfo `xml:"OriginalInfo,omitempty"`
3336 ProcessObject * PicProcessObject `xml:"ProcessResults>Object,omitempty"`
3437}
35-
3638type PicOriginalInfo struct {
3739 Key string `xml:"Key,omitempty"`
3840 Location string `xml:"Location,omitempty"`
3941 ImageInfo * PicImageInfo `xml:"ImageInfo,omitempty"`
4042}
41-
4243type PicImageInfo struct {
4344 Format string `xml:"Format,omitempty"`
4445 Width int `xml:"Width,omitempty"`
4546 Height int `xml:"Height,omitempty"`
4647 Size int `xml:"Size,omitempty"`
4748 Quality int `xml:"Quality,omitempty"`
4849}
49-
5050type PicProcessObject struct {
5151 Key string `xml:"Key,omitempty"`
5252 Location string `xml:"Location,omitempty"`
@@ -57,24 +57,42 @@ type PicProcessObject struct {
5757 Quality int `xml:"Quality,omitempty"`
5858}
5959
60- type CloudImageOptions struct {
60+ type picOperationsHeader struct {
6161 PicOperations string `header:"Pic-Operations" xml:"-" url:"-"`
6262}
6363
64- func (s * ObjectService ) PostCI (ctx context.Context , name string , opt * CloudImageOptions ) (* CloudImageReuslt , * Response , error ) {
65- var res CloudImageReuslt
64+ type ImageProcessOptions = PicOperations
65+
66+ // 云上数据处理 https://cloud.tencent.com/document/product/460/18147
67+ func (s * CIService ) ImageProcess (ctx context.Context , name string , opt * ImageProcessOptions ) (* ImageProcessResult , * Response , error ) {
68+ header := & picOperationsHeader {
69+ PicOperations : EncodePicOperations (opt ),
70+ }
71+ var res ImageProcessResult
6672 sendOpt := sendOptions {
6773 baseURL : s .client .BaseURL .BucketURL ,
6874 uri : "/" + encodeURIComponent (name ) + "?image_process" ,
6975 method : http .MethodPost ,
70- optHeader : opt ,
76+ optHeader : header ,
7177 result : & res ,
7278 }
7379 resp , err := s .client .send (ctx , & sendOpt )
7480 return & res , resp , err
7581}
7682
77- type CloudImageRecognitionInfo struct {
83+ type ImageRecognitionOptions struct {
84+ CIProcess string `url:"ci-process,omitempty"`
85+ DetectType string `url:"detect-type,omitempty"`
86+ }
87+
88+ type ImageRecognitionResult struct {
89+ XMLName xml.Name `xml:"RecognitionResult"`
90+ PornInfo * RecognitionInfo `xml:"PornInfo,omitempty"`
91+ TerroristInfo * RecognitionInfo `xml:"TerroristInfo,omitempty"`
92+ PoliticsInfo * RecognitionInfo `xml:"PoliticsInfo,omitempty"`
93+ AdsInfo * RecognitionInfo `xml:"AdsInfo,omitempty"`
94+ }
95+ type RecognitionInfo struct {
7896 Code int `xml:"Code,omitempty"`
7997 Msg string `xml:"Msg,omitempty"`
8098 HitFlag int `xml:"HitFlag,omitempty"`
@@ -83,18 +101,99 @@ type CloudImageRecognitionInfo struct {
83101 Count int `xml:"Count,omitempty"`
84102}
85103
86- type CloudImageRecognitionResult struct {
87- PornInfo * CloudImageRecognitionInfo `xml:"PornInfo,omitempty"`
88- TerroristInfo * CloudImageRecognitionInfo `xml:"TerroristInfo,omitempty"`
89- PoliticsInfo * CloudImageRecognitionInfo `xml:"PoliticsInfo,omitempty"`
90- AdsInfo * CloudImageRecognitionInfo `xml:"AdsInfo,omitempty"`
104+ // 图片审核 https://cloud.tencent.com/document/product/460/37318
105+ func (s * CIService ) ImageRecognition (ctx context.Context , name string , opt * ImageRecognitionOptions ) (* ImageRecognitionResult , * Response , error ) {
106+ if opt != nil && opt .CIProcess == "" {
107+ opt .CIProcess = "sensitive-content-recognition"
108+ }
109+ var res ImageRecognitionResult
110+ sendOpt := sendOptions {
111+ baseURL : s .client .BaseURL .BucketURL ,
112+ uri : "/" + encodeURIComponent (name ),
113+ method : http .MethodGet ,
114+ optQuery : opt ,
115+ result : & res ,
116+ }
117+ resp , err := s .client .send (ctx , & sendOpt )
118+ return & res , resp , err
119+ }
120+
121+ type PutVideoAuditingJobOptions struct {
122+ XMLName xml.Name `xml:"Request"`
123+ InputObject string `xml:"Input>Object"`
124+ Conf * VideoAuditingJobConf `xml:"Conf"`
125+ }
126+ type VideoAuditingJobConf struct {
127+ DetectType string `xml:",omitempty"`
128+ Snapshot * PutVideoAuditingJobSnapshot `xml:",omitempty"`
129+ Callback string `xml:",omitempty"`
130+ }
131+ type PutVideoAuditingJobSnapshot struct {
132+ Mode string `xml:",omitempty"`
133+ Count int `xml:",omitempty"`
134+ TimeInterval float32 `xml:",omitempty"`
135+ Start float32 `xml:",omitempty"`
136+ }
137+
138+ type PutVideoAuditingJobResult struct {
139+ XMLName xml.Name `xml:"Response"`
140+ JobsDetail struct {
141+ JobId string `xml:"JobId,omitempty"`
142+ State string `xml:"State,omitempty"`
143+ CreationTime string `xml:"CreationTime,omitempty"`
144+ Object string `xml:"Object,omitempty"`
145+ } `xml:"JobsDetail,omitempty"`
146+ }
147+
148+ func (s * CIService ) PutVideoAuditingJob (ctx context.Context , opt * PutVideoAuditingJobOptions ) (* PutVideoAuditingJobResult , * Response , error ) {
149+ var res PutVideoAuditingJobResult
150+ sendOpt := sendOptions {
151+ baseURL : s .client .BaseURL .CIURL ,
152+ uri : "/video/auditing" ,
153+ method : http .MethodPost ,
154+ body : opt ,
155+ result : & res ,
156+ }
157+ resp , err := s .client .send (ctx , & sendOpt )
158+ return & res , resp , err
159+ }
160+
161+ type GetVideoAuditingJobResult struct {
162+ XMLName xml.Name `xml:"Response"`
163+ JobsDetail * VideoAuditingJobDetail `xml:",omitempty"`
164+ NonExistJobIds string `xml:",omitempty"`
165+ }
166+ type VideoAuditingJobDetail struct {
167+ Code string `xml:",omitempty"`
168+ Message string `xml:",omitempty"`
169+ JobId string `xml:",omitempty"`
170+ State string `xml:",omitempty"`
171+ CreationTime string `xml:",omitempty"`
172+ Object string `xml:",omitempty"`
173+ SnapshotCount string `xml:",omitempty"`
174+ result int `xml:",omitempty"`
175+ PornInfo * RecognitionInfo `xml:",omitempty"`
176+ TerrorismInfo * RecognitionInfo `xml:",omitempty"`
177+ PoliticsInfo * RecognitionInfo `xml:",omitempty"`
178+ AdsInfo * RecognitionInfo `xml:",omitempty"`
179+ Snapshot * GetVideoAuditingJobSnapshot `xml:",omitempty"`
180+ }
181+ type GetVideoAuditingJobSnapshot struct {
182+ Url string `xml:",omitempty"`
183+ PornInfo * RecognitionInfo `xml:",omitempty"`
184+ TerrorismInfo * RecognitionInfo `xml:",omitempty"`
185+ PoliticsInfo * RecognitionInfo `xml:",omitempty"`
186+ AdsInfo * RecognitionInfo `xml:",omitempty"`
91187}
92188
93- func GetRecognitionResult (body io.ReadCloser ) * CloudImageRecognitionResult {
94- var res CloudImageRecognitionResult
95- err := xml .NewDecoder (body ).Decode (& res )
96- if err != nil && err != io .EOF {
97- return nil
189+ func (s * CIService ) GetVideoAuditingJob (ctx context.Context , jobid string ) (* GetVideoAuditingJobResult , * Response , error ) {
190+ var res GetVideoAuditingJobResult
191+ sendOpt := sendOptions {
192+ baseURL : s .client .BaseURL .CIURL ,
193+ uri : "/video/auditing/" + jobid ,
194+ method : http .MethodGet ,
195+ result : & res ,
98196 }
99- return & res
197+ resp , err := s .client .send (ctx , & sendOpt )
198+ return & res , resp , err
100199}
0 commit comments