|
|
@ -4,15 +4,15 @@ import ( |
|
|
|
"context" |
|
|
|
"encoding/json" |
|
|
|
"encoding/xml" |
|
|
|
"io" |
|
|
|
"net/http" |
|
|
|
) |
|
|
|
|
|
|
|
type CIService service |
|
|
|
|
|
|
|
type PicOperations struct { |
|
|
|
IsPicInfo int `json:"is_pic_info,omitempty"` |
|
|
|
Rules []PicOperationsRules `json:"rules,omitemtpy"` |
|
|
|
} |
|
|
|
|
|
|
|
type PicOperationsRules struct { |
|
|
|
Bucket string `json:"bucket,omitempty"` |
|
|
|
FileId string `json:"fileid"` |
|
|
@ -20,6 +20,9 @@ type PicOperationsRules struct { |
|
|
|
} |
|
|
|
|
|
|
|
func EncodePicOperations(pic *PicOperations) string { |
|
|
|
if pic == nil { |
|
|
|
return "" |
|
|
|
} |
|
|
|
bs, err := json.Marshal(pic) |
|
|
|
if err != nil { |
|
|
|
return "" |
|
|
@ -27,18 +30,16 @@ func EncodePicOperations(pic *PicOperations) string { |
|
|
|
return string(bs) |
|
|
|
} |
|
|
|
|
|
|
|
type CloudImageReuslt struct { |
|
|
|
type ImageProcessResult struct { |
|
|
|
XMLName xml.Name `xml:"UploadResult"` |
|
|
|
OriginalInfo *PicOriginalInfo `xml:"OriginalInfo,omitempty"` |
|
|
|
ProcessObject *PicProcessObject `xml:"ProcessResults>Object,omitempty"` |
|
|
|
} |
|
|
|
|
|
|
|
type PicOriginalInfo struct { |
|
|
|
Key string `xml:"Key,omitempty"` |
|
|
|
Location string `xml:"Location,omitempty"` |
|
|
|
ImageInfo *PicImageInfo `xml:"ImageInfo,omitempty"` |
|
|
|
} |
|
|
|
|
|
|
|
type PicImageInfo struct { |
|
|
|
Format string `xml:"Format,omitempty"` |
|
|
|
Width int `xml:"Width,omitempty"` |
|
|
@ -46,7 +47,6 @@ type PicImageInfo struct { |
|
|
|
Size int `xml:"Size,omitempty"` |
|
|
|
Quality int `xml:"Quality,omitempty"` |
|
|
|
} |
|
|
|
|
|
|
|
type PicProcessObject struct { |
|
|
|
Key string `xml:"Key,omitempty"` |
|
|
|
Location string `xml:"Location,omitempty"` |
|
|
@ -57,24 +57,42 @@ type PicProcessObject struct { |
|
|
|
Quality int `xml:"Quality,omitempty"` |
|
|
|
} |
|
|
|
|
|
|
|
type CloudImageOptions struct { |
|
|
|
type picOperationsHeader struct { |
|
|
|
PicOperations string `header:"Pic-Operations" xml:"-" url:"-"` |
|
|
|
} |
|
|
|
|
|
|
|
func (s *ObjectService) PostCI(ctx context.Context, name string, opt *CloudImageOptions) (*CloudImageReuslt, *Response, error) { |
|
|
|
var res CloudImageReuslt |
|
|
|
type ImageProcessOptions = PicOperations |
|
|
|
|
|
|
|
// 云上数据处理 https://cloud.tencent.com/document/product/460/18147
|
|
|
|
func (s *CIService) ImageProcess(ctx context.Context, name string, opt *ImageProcessOptions) (*ImageProcessResult, *Response, error) { |
|
|
|
header := &picOperationsHeader{ |
|
|
|
PicOperations: EncodePicOperations(opt), |
|
|
|
} |
|
|
|
var res ImageProcessResult |
|
|
|
sendOpt := sendOptions{ |
|
|
|
baseURL: s.client.BaseURL.BucketURL, |
|
|
|
uri: "/" + encodeURIComponent(name) + "?image_process", |
|
|
|
method: http.MethodPost, |
|
|
|
optHeader: opt, |
|
|
|
optHeader: header, |
|
|
|
result: &res, |
|
|
|
} |
|
|
|
resp, err := s.client.send(ctx, &sendOpt) |
|
|
|
return &res, resp, err |
|
|
|
} |
|
|
|
|
|
|
|
type CloudImageRecognitionInfo struct { |
|
|
|
type ImageRecognitionOptions struct { |
|
|
|
CIProcess string `url:"ci-process,omitempty"` |
|
|
|
DetectType string `url:"detect-type,omitempty"` |
|
|
|
} |
|
|
|
|
|
|
|
type ImageRecognitionResult struct { |
|
|
|
XMLName xml.Name `xml:"RecognitionResult"` |
|
|
|
PornInfo *RecognitionInfo `xml:"PornInfo,omitempty"` |
|
|
|
TerroristInfo *RecognitionInfo `xml:"TerroristInfo,omitempty"` |
|
|
|
PoliticsInfo *RecognitionInfo `xml:"PoliticsInfo,omitempty"` |
|
|
|
AdsInfo *RecognitionInfo `xml:"AdsInfo,omitempty"` |
|
|
|
} |
|
|
|
type RecognitionInfo struct { |
|
|
|
Code int `xml:"Code,omitempty"` |
|
|
|
Msg string `xml:"Msg,omitempty"` |
|
|
|
HitFlag int `xml:"HitFlag,omitempty"` |
|
|
@ -83,18 +101,99 @@ type CloudImageRecognitionInfo struct { |
|
|
|
Count int `xml:"Count,omitempty"` |
|
|
|
} |
|
|
|
|
|
|
|
type CloudImageRecognitionResult struct { |
|
|
|
PornInfo *CloudImageRecognitionInfo `xml:"PornInfo,omitempty"` |
|
|
|
TerroristInfo *CloudImageRecognitionInfo `xml:"TerroristInfo,omitempty"` |
|
|
|
PoliticsInfo *CloudImageRecognitionInfo `xml:"PoliticsInfo,omitempty"` |
|
|
|
AdsInfo *CloudImageRecognitionInfo `xml:"AdsInfo,omitempty"` |
|
|
|
// 图片审核 https://cloud.tencent.com/document/product/460/37318
|
|
|
|
func (s *CIService) ImageRecognition(ctx context.Context, name string, opt *ImageRecognitionOptions) (*ImageRecognitionResult, *Response, error) { |
|
|
|
if opt != nil && opt.CIProcess == "" { |
|
|
|
opt.CIProcess = "sensitive-content-recognition" |
|
|
|
} |
|
|
|
var res ImageRecognitionResult |
|
|
|
sendOpt := sendOptions{ |
|
|
|
baseURL: s.client.BaseURL.BucketURL, |
|
|
|
uri: "/" + encodeURIComponent(name), |
|
|
|
method: http.MethodGet, |
|
|
|
optQuery: opt, |
|
|
|
result: &res, |
|
|
|
} |
|
|
|
resp, err := s.client.send(ctx, &sendOpt) |
|
|
|
return &res, resp, err |
|
|
|
} |
|
|
|
|
|
|
|
type PutVideoAuditingJobOptions struct { |
|
|
|
XMLName xml.Name `xml:"Request"` |
|
|
|
InputObject string `xml:"Input>Object"` |
|
|
|
Conf *VideoAuditingJobConf `xml:"Conf"` |
|
|
|
} |
|
|
|
type VideoAuditingJobConf struct { |
|
|
|
DetectType string `xml:",omitempty"` |
|
|
|
Snapshot *PutVideoAuditingJobSnapshot `xml:",omitempty"` |
|
|
|
Callback string `xml:",omitempty"` |
|
|
|
} |
|
|
|
type PutVideoAuditingJobSnapshot struct { |
|
|
|
Mode string `xml:",omitempty"` |
|
|
|
Count int `xml:",omitempty"` |
|
|
|
TimeInterval float32 `xml:",omitempty"` |
|
|
|
Start float32 `xml:",omitempty"` |
|
|
|
} |
|
|
|
|
|
|
|
type PutVideoAuditingJobResult struct { |
|
|
|
XMLName xml.Name `xml:"Response"` |
|
|
|
JobsDetail struct { |
|
|
|
JobId string `xml:"JobId,omitempty"` |
|
|
|
State string `xml:"State,omitempty"` |
|
|
|
CreationTime string `xml:"CreationTime,omitempty"` |
|
|
|
Object string `xml:"Object,omitempty"` |
|
|
|
} `xml:"JobsDetail,omitempty"` |
|
|
|
} |
|
|
|
|
|
|
|
func (s *CIService) PutVideoAuditingJob(ctx context.Context, opt *PutVideoAuditingJobOptions) (*PutVideoAuditingJobResult, *Response, error) { |
|
|
|
var res PutVideoAuditingJobResult |
|
|
|
sendOpt := sendOptions{ |
|
|
|
baseURL: s.client.BaseURL.CIURL, |
|
|
|
uri: "/video/auditing", |
|
|
|
method: http.MethodPost, |
|
|
|
body: opt, |
|
|
|
result: &res, |
|
|
|
} |
|
|
|
resp, err := s.client.send(ctx, &sendOpt) |
|
|
|
return &res, resp, err |
|
|
|
} |
|
|
|
|
|
|
|
type GetVideoAuditingJobResult struct { |
|
|
|
XMLName xml.Name `xml:"Response"` |
|
|
|
JobsDetail *VideoAuditingJobDetail `xml:",omitempty"` |
|
|
|
NonExistJobIds string `xml:",omitempty"` |
|
|
|
} |
|
|
|
type VideoAuditingJobDetail struct { |
|
|
|
Code string `xml:",omitempty"` |
|
|
|
Message string `xml:",omitempty"` |
|
|
|
JobId string `xml:",omitempty"` |
|
|
|
State string `xml:",omitempty"` |
|
|
|
CreationTime string `xml:",omitempty"` |
|
|
|
Object string `xml:",omitempty"` |
|
|
|
SnapshotCount string `xml:",omitempty"` |
|
|
|
result int `xml:",omitempty"` |
|
|
|
PornInfo *RecognitionInfo `xml:",omitempty"` |
|
|
|
TerrorismInfo *RecognitionInfo `xml:",omitempty"` |
|
|
|
PoliticsInfo *RecognitionInfo `xml:",omitempty"` |
|
|
|
AdsInfo *RecognitionInfo `xml:",omitempty"` |
|
|
|
Snapshot *GetVideoAuditingJobSnapshot `xml:",omitempty"` |
|
|
|
} |
|
|
|
type GetVideoAuditingJobSnapshot struct { |
|
|
|
Url string `xml:",omitempty"` |
|
|
|
PornInfo *RecognitionInfo `xml:",omitempty"` |
|
|
|
TerrorismInfo *RecognitionInfo `xml:",omitempty"` |
|
|
|
PoliticsInfo *RecognitionInfo `xml:",omitempty"` |
|
|
|
AdsInfo *RecognitionInfo `xml:",omitempty"` |
|
|
|
} |
|
|
|
|
|
|
|
func GetRecognitionResult(body io.ReadCloser) *CloudImageRecognitionResult { |
|
|
|
var res CloudImageRecognitionResult |
|
|
|
err := xml.NewDecoder(body).Decode(&res) |
|
|
|
if err != nil && err != io.EOF { |
|
|
|
return nil |
|
|
|
func (s *CIService) GetVideoAuditingJob(ctx context.Context, jobid string) (*GetVideoAuditingJobResult, *Response, error) { |
|
|
|
var res GetVideoAuditingJobResult |
|
|
|
sendOpt := sendOptions{ |
|
|
|
baseURL: s.client.BaseURL.CIURL, |
|
|
|
uri: "/video/auditing/" + jobid, |
|
|
|
method: http.MethodGet, |
|
|
|
result: &res, |
|
|
|
} |
|
|
|
return &res |
|
|
|
resp, err := s.client.send(ctx, &sendOpt) |
|
|
|
return &res, resp, err |
|
|
|
} |