Skip to content

Commit 067d968

Browse files
author
aldoli
committed
Merge branch 'mark-dev' into 'master' (merge request !39)
mark-dev
2 parents 76b012e + c68e276 commit 067d968

29 files changed

+1246
-30
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [5.6.55]
9+
- add batch image auditing api
10+
- add DocumentAuditing api
11+
- update CI Auditing api
12+
713
## [5.6.54]
814
- default use https request
915
- use strict sign

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<dependency>
99
<groupId>com.qcloud</groupId>
1010
<artifactId>cos_api</artifactId>
11-
<version>5.6.52</version>
11+
<version>5.6.55</version>
1212
</dependency>
1313
```
1414

src/main/java/com/qcloud/cos/COS.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
import com.qcloud.cos.model.*;
3535
import com.qcloud.cos.model.ciModel.auditing.AudioAuditingRequest;
3636
import com.qcloud.cos.model.ciModel.auditing.AudioAuditingResponse;
37+
import com.qcloud.cos.model.ciModel.auditing.DocumentAuditingRequest;
38+
import com.qcloud.cos.model.ciModel.auditing.DocumentAuditingResponse;
3739
import com.qcloud.cos.model.ciModel.auditing.ImageAuditingRequest;
3840
import com.qcloud.cos.model.ciModel.auditing.ImageAuditingResponse;
3941
import com.qcloud.cos.model.ciModel.auditing.TextAuditingRequest;
@@ -2899,6 +2901,18 @@ SelectObjectContentResult selectObjectContent(SelectObjectContentRequest selectR
28992901
* DescribeAuditingTextJob 查询文本审核任务结果 https://cloud.tencent.com/document/product/436/56288
29002902
*/
29012903
TextAuditingResponse describeAuditingTextJob(TextAuditingRequest request);
2904+
2905+
/**
2906+
* CreateAuditingDocumentJobs 提交文档审核任务 https://cloud.tencent.com/document/product/460/59380
2907+
*/
2908+
DocumentAuditingResponse createAuditingDocumentJobs(DocumentAuditingRequest request);
2909+
2910+
/**
2911+
* DescribeAuditingDocumentJobs 提交文档审核任务 https://cloud.tencent.com/document/product/460/59383
2912+
*/
2913+
DocumentAuditingResponse describeAuditingDocumentJob(DocumentAuditingRequest request);
2914+
2915+
29022916
}
29032917

29042918

src/main/java/com/qcloud/cos/COSClient.java

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@
9797
import com.qcloud.cos.model.*;
9898
import com.qcloud.cos.model.ciModel.auditing.AudioAuditingRequest;
9999
import com.qcloud.cos.model.ciModel.auditing.AudioAuditingResponse;
100+
import com.qcloud.cos.model.ciModel.auditing.DocumentAuditingRequest;
101+
import com.qcloud.cos.model.ciModel.auditing.DocumentAuditingResponse;
100102
import com.qcloud.cos.model.ciModel.auditing.ImageAuditingRequest;
101103
import com.qcloud.cos.model.ciModel.auditing.ImageAuditingResponse;
102104
import com.qcloud.cos.model.ciModel.auditing.TextAuditingRequest;
@@ -3838,10 +3840,13 @@ public ImageAuditingResponse imageAuditing(ImageAuditingRequest imageAuditingReq
38383840
"The imageAuditingRequest parameter must be specified setting the object tags");
38393841
rejectNull(imageAuditingRequest.getBucketName(),
38403842
"The bucketName parameter must be specified setting the object tags");
3841-
rejectNull(imageAuditingRequest.getDetectType(), "The detectType parameter must be specified setting the object tags");
3843+
String detectType = imageAuditingRequest.getDetectType();
3844+
rejectNull(detectType, "The detectType parameter must be specified setting the object tags");
38423845
CosHttpRequest<ImageAuditingRequest> request = createRequest(imageAuditingRequest.getBucketName(), imageAuditingRequest.getObjectKey(), imageAuditingRequest, HttpMethodName.GET);
38433846
request.addParameter("ci-process", "sensitive-content-recognition");
3844-
addParameterIfNotNull(request, "detect-type", imageAuditingRequest.getDetectType());
3847+
if ("all".equalsIgnoreCase(detectType))
3848+
detectType = "porn,terrorist,politics,ads";
3849+
addParameterIfNotNull(request, "detect-type", detectType);
38453850
addParameterIfNotNull(request, "interval", Integer.toString(imageAuditingRequest.getInterval()));
38463851
addParameterIfNotNull(request, "max-frames", Integer.toString(imageAuditingRequest.getMaxFrames()));
38473852
addParameterIfNotNull(request, "biz-type", imageAuditingRequest.getBizType());
@@ -3927,6 +3932,24 @@ public TextAuditingResponse describeAuditingTextJob(TextAuditingRequest textAudi
39273932
return invoke(request, new Unmarshallers.TextAuditingDescribeJobUnmarshaller());
39283933
}
39293934

3935+
@Override
3936+
public DocumentAuditingResponse createAuditingDocumentJobs(DocumentAuditingRequest documentAuditingRequest) {
3937+
this.checkCIRequestCommon(documentAuditingRequest);
3938+
this.rejectStartWith(documentAuditingRequest.getConf().getCallback(), "http", "The Conf.CallBack parameter mush start with http or https");
3939+
CosHttpRequest<DocumentAuditingRequest> request = createRequest(documentAuditingRequest.getBucketName(), "/document/auditing", documentAuditingRequest, HttpMethodName.POST);
3940+
this.setContent(request, RequestXmlFactory.convertToXmlByteArray(documentAuditingRequest), "application/xml", false);
3941+
return invoke(request, new Unmarshallers.DocumentAuditingJobUnmarshaller());
3942+
}
3943+
3944+
@Override
3945+
public DocumentAuditingResponse describeAuditingDocumentJob(DocumentAuditingRequest documentAuditingRequest) {
3946+
this.checkCIRequestCommon(documentAuditingRequest);
3947+
rejectNull(documentAuditingRequest.getJobId(),
3948+
"The jobId parameter must be specified setting the object tags");
3949+
CosHttpRequest<DocumentAuditingRequest> request = createRequest(documentAuditingRequest.getBucketName(), "/document/auditing/" + documentAuditingRequest.getJobId(), documentAuditingRequest, HttpMethodName.GET);
3950+
return invoke(request, new Unmarshallers.DocumentAuditingDescribeJobUnmarshaller());
3951+
}
3952+
39303953
private void checkAuditingRequest(ImageAuditingRequest request) {
39313954
rejectNull(request.getDetectType(), "The detectType parameter must be specified setting the object tags");
39323955
rejectNull(request.getObjectKey(), "The objectKey parameter must be specified setting the object tags");
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package com.qcloud.cos.demo.ci;
2+
3+
import com.qcloud.cos.COSClient;
4+
import com.qcloud.cos.model.ciModel.auditing.DocumentAuditingRequest;
5+
import com.qcloud.cos.model.ciModel.auditing.DocumentAuditingResponse;
6+
7+
8+
/**
9+
* 内容审核 文档审核接口相关demo 详情见https://cloud.tencent.com/document/product/460/59380
10+
*/
11+
public class DocumentAuditingJobDemo {
12+
13+
public static void main(String[] args) {
14+
// 1 初始化用户身份信息(secretId, secretKey)。
15+
COSClient client = ClientUtils.getTestClient();
16+
// 2 调用要使用的方法。
17+
describeAuditingDocumentJob(client);
18+
}
19+
20+
/**
21+
* createAuditingTextJobs 接口用于创建文档审核任务。
22+
*/
23+
public static void createAuditingDocumentJobs(COSClient client) {
24+
//1.创建任务请求对象
25+
DocumentAuditingRequest request = new DocumentAuditingRequest();
26+
//2.添加请求参数 参数详情请见api接口文档
27+
request.setBucketName("markjrzhang-1251704708");
28+
//2.1.1设置对象地址
29+
// request.getInput().setObject("1.txt");
30+
//2.1.2或直接设置请求内容,文本内容的Base64编码
31+
request.getInput().setUrl("https://markjrzhang-1251704708.cos.ap-chongqing.myqcloud.com/%E9%97%AE%E9%A2%98%E6%B1%87%E6%80%BB.pptx");
32+
//2.2设置审核类型参数
33+
request.getConf().setDetectType("all");
34+
//2.3设置审核模板(可选)
35+
// request.getConf().setBizType("aa3e9d84a6a079556b0109a935c*****");
36+
//3.调用接口,获取任务响应对象
37+
DocumentAuditingResponse response = client.createAuditingDocumentJobs(request);
38+
}
39+
40+
/**
41+
* DescribeAuditingTextJob 接口用于查询文档审核任务。
42+
*
43+
* @param client
44+
*/
45+
public static void describeAuditingDocumentJob(COSClient client) {
46+
//1.创建任务请求对象
47+
DocumentAuditingRequest request = new DocumentAuditingRequest();
48+
//2.添加请求参数 参数详情请见api接口文档
49+
request.setBucketName("markjrzhang-1251704708");
50+
request.setJobId("sdd5d1cc630fdc11ecb3fa525400946f76");
51+
//3.调用接口,获取任务响应对象
52+
DocumentAuditingResponse response = client.describeAuditingDocumentJob(request);
53+
}
54+
}

src/main/java/com/qcloud/cos/demo/ci/ImageAuditingDemo.java

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,26 @@
44
import com.qcloud.cos.model.ciModel.auditing.AuditingInfo;
55
import com.qcloud.cos.model.ciModel.auditing.ImageAuditingRequest;
66
import com.qcloud.cos.model.ciModel.auditing.ImageAuditingResponse;
7+
import com.qcloud.cos.transfer.ImageAuditingImpl;
8+
import com.qcloud.cos.transfer.MultipleImageAuditingImpl;
9+
import com.qcloud.cos.transfer.TransferManager;
710

11+
import java.util.ArrayList;
812
import java.util.List;
13+
import java.util.concurrent.ExecutorService;
14+
import java.util.concurrent.Executors;
915

1016
/**
1117
* 内容审核 图片审核接口相关demo 详情见https://cloud.tencent.com/document/product/460/37318
1218
*/
1319
public class ImageAuditingDemo {
1420

15-
public static void main(String[] args) {
21+
public static void main(String[] args) throws InterruptedException {
1622
// 1 初始化用户身份信息(secretId, secretKey)。
1723
COSClient client = ClientUtils.getTestClient();
1824
// 2 调用要使用的方法。
19-
imageAuditing(client);
25+
// imageAuditing(client);
26+
batchPostImageAuditing(client);
2027
}
2128

2229
/**
@@ -31,12 +38,45 @@ public static void imageAuditing(COSClient client) {
3138
//2.1设置请求bucket
3239
request.setBucketName("demo-123456789");
3340
//2.2设置审核类型
34-
request.setDetectType("porn,terrorist,politics,ads");
41+
request.setDetectType("porn");
3542
//2.3设置bucket中的图片位置
36-
request.setObjectKey("1.png");
43+
request.setObjectKey("1.jpg");
3744
//3.调用接口,获取任务响应对象
3845
ImageAuditingResponse response = client.imageAuditing(request);
3946
//4调用工具类,获取各审核类型详情集合 (也可自行根据业务解析)
4047
List<AuditingInfo> imageInfoList = AuditingResultUtil.getImageInfoList(response);
48+
System.out.println(response);
49+
}
50+
51+
/**
52+
* 批量发送图片审核任务
53+
*/
54+
public static void batchPostImageAuditing(COSClient client) throws InterruptedException {
55+
List<ImageAuditingRequest> requestList = new ArrayList<>();
56+
ImageAuditingRequest request = new ImageAuditingRequest();
57+
request.setBucketName("demo-123456789");
58+
request.setObjectKey("1.png");
59+
request.setDetectType("all");
60+
requestList.add(request);
61+
62+
request = new ImageAuditingRequest();
63+
request.setBucketName("demo-123456789");
64+
request.setObjectKey("1.jpg");
65+
request.setDetectType("all");
66+
requestList.add(request);
67+
68+
// 传入一个threadpool, 若不传入线程池, 默认TransferManager中会生成一个单线程的线程池。
69+
ExecutorService threadPool = Executors.newFixedThreadPool(4);
70+
TransferManager transferManager = new TransferManager(client, threadPool);
71+
MultipleImageAuditingImpl multipleImageAuditing = transferManager.batchPostImageAuditing(requestList);
72+
multipleImageAuditing.waitForCompletion();
73+
List<ImageAuditingImpl> imageAuditingList = multipleImageAuditing.getImageAuditingList();
74+
for (ImageAuditingImpl imageAuditing : imageAuditingList) {
75+
System.out.println(imageAuditing.getState());
76+
System.out.println(imageAuditing.getResponse());
77+
System.out.println(imageAuditing.getErrMsg());
78+
}
79+
transferManager.shutdownNow();
80+
client.shutdown();
4181
}
4282
}

src/main/java/com/qcloud/cos/demo/ci/ImageLabelDemo.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
import com.qcloud.cos.COSClient;
66
import com.qcloud.cos.model.ciModel.image.ImageLabelRequest;
77
import com.qcloud.cos.model.ciModel.image.ImageLabelResponse;
8-
import com.qcloud.cos.model.ciModel.image.ImageLabelV2Request;
9-
import com.qcloud.cos.model.ciModel.image.ImageLabelV2Response;
108

119
/**
1210
* 图片标签接口使用demo https://cloud.tencent.com/document/product/460/39082

src/main/java/com/qcloud/cos/demo/ci/TextAuditingJobDemo.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ public static void createAuditingTextJobs(COSClient client) {
2626
//1.创建任务请求对象
2727
TextAuditingRequest request = new TextAuditingRequest();
2828
//2.添加请求参数 参数详情请见api接口文档
29-
request.setBucketName("demo-123456789");
29+
request.setBucketName("demo-1234567898");
3030
//2.1.1设置对象地址
3131
// request.getInput().setObject("1.txt");
3232
//2.1.2或直接设置请求内容,文本内容的Base64编码
3333
request.getInput().setContent("Base64Str");
3434
//2.2设置审核类型参数
3535
request.getConf().setDetectType("all");
3636
//2.3设置审核模板(可选)
37-
request.getConf().setBizType("aa3e9d84a6a079556b0109a935c*****");
37+
// request.getConf().setBizType("aa3e9d84a6a079556b0109a935c*****");
3838
//3.调用接口,获取任务响应对象
3939
TextAuditingResponse response = client.createAuditingTextJobs(request);
4040
//4.调用工具类,获取各审核类型详情集合 (也可自行根据业务解析)

src/main/java/com/qcloud/cos/demo/ci/VideoAuditingJobDemo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public static void main(String[] args) {
1616
// 1 初始化用户身份信息(secretId, secretKey)。
1717
COSClient client = ClientUtils.getTestClient();
1818
// 2 调用要使用的方法。
19-
describeAuditingJob(client);
19+
createVideoAuditingJob(client);
2020
}
2121

2222
/**

src/main/java/com/qcloud/cos/http/DefaultCosHttpClient.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,6 @@
1919
package com.qcloud.cos.http;
2020

2121

22-
import java.io.BufferedInputStream;
23-
import java.io.FileInputStream;
24-
import java.io.IOException;
25-
import java.io.InputStream;
26-
import java.net.URI;
27-
import java.net.URISyntaxException;
28-
import java.util.HashMap;
29-
import java.util.List;
30-
import java.util.Map;
31-
import java.util.Map.Entry;
32-
3322
import com.qcloud.cos.ClientConfig;
3423
import com.qcloud.cos.Headers;
3524
import com.qcloud.cos.event.ProgressInputStream;
@@ -49,7 +38,6 @@
4938
import com.qcloud.cos.utils.ExceptionUtils;
5039
import com.qcloud.cos.utils.UrlEncoderUtils;
5140
import com.qcloud.cos.utils.ValidationUtils;
52-
5341
import org.apache.commons.codec.binary.Base64;
5442
import org.apache.http.Header;
5543
import org.apache.http.HttpHost;
@@ -74,6 +62,17 @@
7462
import org.slf4j.Logger;
7563
import org.slf4j.LoggerFactory;
7664

65+
import java.io.BufferedInputStream;
66+
import java.io.FileInputStream;
67+
import java.io.IOException;
68+
import java.io.InputStream;
69+
import java.net.URI;
70+
import java.net.URISyntaxException;
71+
import java.util.HashMap;
72+
import java.util.List;
73+
import java.util.Map;
74+
import java.util.Map.Entry;
75+
7776

7877
public class DefaultCosHttpClient implements CosHttpClient {
7978

0 commit comments

Comments
 (0)