Skip to content

Commit

Permalink
feat: add batch content moderation api
Browse files Browse the repository at this point in the history
添加主动批量审核 api
  • Loading branch information
yanglbme committed Oct 31, 2023
1 parent dfc56fe commit b53414d
Show file tree
Hide file tree
Showing 8 changed files with 467 additions and 2 deletions.
38 changes: 36 additions & 2 deletions src/main/java/io/github/doocs/im/core/Audit.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
package io.github.doocs.im.core;

import io.github.doocs.im.ImClient;
import io.github.doocs.im.model.request.*;
import io.github.doocs.im.model.response.*;
import io.github.doocs.im.model.request.AddCloudAuditKeywordsRequest;
import io.github.doocs.im.model.request.AddLocalAuditKeywordsRequest;
import io.github.doocs.im.model.request.BatchContentModerationRequest;
import io.github.doocs.im.model.request.ContentModerationRequest;
import io.github.doocs.im.model.request.DeleteCloudAuditKeywordsRequest;
import io.github.doocs.im.model.request.DeleteLocalAuditKeywordsRequest;
import io.github.doocs.im.model.request.GetCloudAuditKeyWordsIdsRequest;
import io.github.doocs.im.model.request.GetCloudAuditKeyWordsRequest;
import io.github.doocs.im.model.request.GetLocalAuditKeywordsRequest;
import io.github.doocs.im.model.response.AddCloudAuditKeywordsResult;
import io.github.doocs.im.model.response.AddLocalAuditKeywordsResult;
import io.github.doocs.im.model.response.BatchContentModerationResult;
import io.github.doocs.im.model.response.ContentModerationResult;
import io.github.doocs.im.model.response.DeleteCloudAuditKeywordsResult;
import io.github.doocs.im.model.response.DeleteLocalAuditKeywordsResult;
import io.github.doocs.im.model.response.GetCloudAuditKeywordsIdsResult;
import io.github.doocs.im.model.response.GetCloudAuditKeywordsResult;
import io.github.doocs.im.model.response.GetLocalAuditKeywordsResult;
import io.github.doocs.im.util.HttpUtil;

import java.io.IOException;
Expand Down Expand Up @@ -31,6 +47,7 @@ public class Audit {
* 云端审核
*/
public static final String CONTENT_MODERATION_COMMAND = "content_moderation";
public static final String BATCH_CONTENT_MODERATION_COMMAND = "batch_content_moderation";
public static final String GET_CLOUD_AUDIT_KEYWORDS_IDS_COMMAND = "get_cloud_audit_keywords_ids";
public static final String GET_CLOUD_AUDIT_KEYWORDS_COMMAND = "get_cloud_audit_keywords";
public static final String ADD_CLOUD_AUDIT_KEYWORDS_COMMAND = "add_cloud_audit_keywords";
Expand Down Expand Up @@ -110,6 +127,23 @@ public ContentModerationResult contentModeration(ContentModerationRequest conten
return HttpUtil.post(url, contentModerationRequest, ContentModerationResult.class, imClient.getConfig());
}

/**
* 云端审核批量审核
*
* @param batchContentModerationRequest 请求参数
* @return 结果
* @throws IOException 异常
*/
public BatchContentModerationResult batchContentModeration(BatchContentModerationRequest batchContentModerationRequest) throws IOException {
String url = imClient.getUrl(SERVICE_NAME, BATCH_CONTENT_MODERATION_COMMAND);
return HttpUtil.post(url, batchContentModerationRequest, BatchContentModerationResult.class, imClient.getConfig());
}

public BatchContentModerationResult batchContentModeration(BatchContentModerationRequest batchContentModerationRequest, long random) throws IOException {
String url = imClient.getUrl(SERVICE_NAME, BATCH_CONTENT_MODERATION_COMMAND, random);
return HttpUtil.post(url, batchContentModerationRequest, BatchContentModerationResult.class, imClient.getConfig());
}

/**
* 云端审核获取词库列表
*
Expand Down
111 changes: 111 additions & 0 deletions src/main/java/io/github/doocs/im/model/request/AuditContentItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package io.github.doocs.im.model.request;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;

import java.io.Serializable;

/**
* 云端审核主动批量审核内容项
*
* @author bingo
* @since 2023/10/31 10:25
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
public class AuditContentItem implements Serializable {
private static final long serialVersionUID = -4862840041361119218L;

/**
* 必填
* 内容 ID,数组里各个成员,不能重复的 ContentId。
*/
@JsonProperty("ContentId")
private Integer contentId;

/**
* 必填
* 送审类型,批量审核接口里,限制取值:Text/Image,音视频送审请参见 主动审核接口
* {@link io.github.doocs.im.constant.AuditContentType}
*/
@JsonProperty("ContentType")
private String contentType;

/**
* 必填
* 送审内容,最大限制8KB,当审核文件时,填对应 URL。其中图片审核最大不超过5MB。
*/
@JsonProperty("Content")
private String content;

public AuditContentItem() {
}

public AuditContentItem(Integer contentId, String contentType, String content) {
this.contentId = contentId;
this.contentType = contentType;
this.content = content;
}

private AuditContentItem(Builder builder) {
this.contentId = builder.contentId;
this.contentType = builder.contentType;
this.content = builder.content;
}

public static Builder builder() {
return new Builder();
}

public Integer getContentId() {
return contentId;
}

public void setContentId(Integer contentId) {
this.contentId = contentId;
}

public String getContentType() {
return contentType;
}

public void setContentType(String contentType) {
this.contentType = contentType;
}

public String getContent() {
return content;
}

public void setContent(String content) {
this.content = content;
}


public static final class Builder {
private Integer contentId;
private String contentType;
private String content;

private Builder() {
}

public AuditContentItem build() {
return new AuditContentItem(this);
}

public Builder contentId(Integer contentId) {
this.contentId = contentId;
return this;
}

public Builder contentType(String contentType) {
this.contentType = contentType;
return this;
}

public Builder content(String content) {
this.content = content;
return this;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package io.github.doocs.im.model.request;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;

import java.io.Serializable;
import java.util.List;

/**
* 云端审核主动批量审核-请求参数
*
* @author bingo
* @since 2023/10/31 10:25
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
public class BatchContentModerationRequest extends GenericRequest implements Serializable {
private static final long serialVersionUID = 1971966887350107478L;

/**
* 表明送审策略,取值:C2C/Group/UserInfo/GroupInfo/GroupMemberInfo/RelationChain
* {@link io.github.doocs.im.constant.AuditNameType}
*/
@JsonProperty("AuditName")
private String auditName;

/**
* 批量送审数组,最多支持10个内容批量送审。
*/
@JsonProperty("Contents")
private List<AuditContentItem> contents;

public BatchContentModerationRequest() {
}

public BatchContentModerationRequest(String auditName, List<AuditContentItem> contents) {
this.auditName = auditName;
this.contents = contents;
}

private BatchContentModerationRequest(Builder builder) {
this.auditName = builder.auditName;
this.contents = builder.contents;
}

public static Builder builder() {
return new Builder();
}

public String getAuditName() {
return auditName;
}

public void setAuditName(String auditName) {
this.auditName = auditName;
}

public List<AuditContentItem> getContents() {
return contents;
}

public void setContents(List<AuditContentItem> contents) {
this.contents = contents;
}


public static final class Builder {
private String auditName;
private List<AuditContentItem> contents;

private Builder() {
}

public BatchContentModerationRequest build() {
return new BatchContentModerationRequest(this);
}

public Builder auditName(String auditName) {
this.auditName = auditName;
return this;
}

public Builder contents(List<AuditContentItem> contents) {
this.contents = contents;
return this;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class ContentModerationRequest extends GenericRequest implements Serializ

/**
* 表明送审策略
* {@link io.github.doocs.im.constant.AuditNameType}
*/
@JsonProperty("AuditName")
private String auditName;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package io.github.doocs.im.model.response;

import com.fasterxml.jackson.annotation.JsonProperty;

import java.io.Serializable;
import java.util.List;

/**
* 云端审核主动批量审核结果
*
* @author bingo
* @since 2023/10/31 10:25
*/
public class BatchContentModerationResult extends GenericResult implements Serializable {
private static final long serialVersionUID = 2158637502606683308L;

@JsonProperty("AuditResults")
private List<BatchContentModerationResultItem> auditResults;

public List<BatchContentModerationResultItem> getAuditResults() {
return auditResults;
}

public void setAuditResults(List<BatchContentModerationResultItem> auditResults) {
this.auditResults = auditResults;
}

@Override
public String toString() {
return "BatchContentModerationResult{" +
"auditResults=" + auditResults +
", actionStatus='" + actionStatus + '\'' +
", errorInfo='" + errorInfo + '\'' +
", errorCode=" + errorCode +
'}';
}
}
Loading

0 comments on commit b53414d

Please sign in to comment.