11 changed files with 231 additions and 172 deletions
@ -1,94 +0,0 @@ |
|||
package com.epmet.utils; |
|||
|
|||
import com.alibaba.nacos.client.utils.StringUtils; |
|||
import com.epmet.commons.tools.constant.NumConstant; |
|||
import com.epmet.commons.tools.exception.EpmetErrorCode; |
|||
import com.epmet.commons.tools.exception.RenException; |
|||
import com.epmet.commons.tools.scan.param.ImgScanParamDTO; |
|||
import com.epmet.commons.tools.scan.param.ImgTaskDTO; |
|||
import com.epmet.commons.tools.scan.param.TextScanParamDTO; |
|||
import com.epmet.commons.tools.scan.param.TextTaskDTO; |
|||
import com.epmet.commons.tools.scan.result.SyncScanResult; |
|||
import com.epmet.commons.tools.utils.Result; |
|||
import com.epmet.commons.tools.utils.ScanContentUtils; |
|||
import org.springframework.beans.factory.annotation.Value; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
|
|||
import java.util.List; |
|||
import java.util.UUID; |
|||
|
|||
/** |
|||
* 文字、图片合法性校验 |
|||
* |
|||
* @author zhangyong |
|||
* @date 2020-07-15 14:26 |
|||
*/ |
|||
@Slf4j |
|||
public class ValidityVerification { |
|||
|
|||
@Value("${openapi.scan.server.url}") |
|||
private String scanApiUrl; |
|||
@Value("${openapi.scan.method.textSyncScan}") |
|||
private String textSyncScanMethod; |
|||
@Value("${openapi.scan.method.imgSyncScan}") |
|||
private String imgSyncScanMethod; |
|||
|
|||
/** |
|||
* 文本校验 |
|||
* @param context 被校验的文本,,不能超过10000 |
|||
* @param businessEnum 业务枚举,定义校验失败后,输出的日志信息 |
|||
* @return void |
|||
* @auther zhangyong |
|||
* @Date 14:42 2020-07-15 |
|||
**/ |
|||
public void textScanVerification(String context, String businessEnum){ |
|||
if (StringUtils.isNotBlank(context)) { |
|||
TextScanParamDTO textScanParamDTO = new TextScanParamDTO(); |
|||
TextTaskDTO taskDTO = new TextTaskDTO(); |
|||
taskDTO.setContent(context); |
|||
taskDTO.setDataId(UUID.randomUUID().toString().replace("-", "")); |
|||
textScanParamDTO.getTasks().add(taskDTO); |
|||
Result<SyncScanResult> textSyncScanResult = ScanContentUtils.textSyncScan(scanApiUrl.concat(textSyncScanMethod), textScanParamDTO); |
|||
if (!textSyncScanResult.success()) { |
|||
throw new RenException(EpmetErrorCode.SERVER_ERROR.getCode()); |
|||
} else { |
|||
if (!textSyncScanResult.getData().isAllPass()) { |
|||
// 业务枚举:例如:评论话题失败,评论内容为:%s"
|
|||
log.error(String.format(businessEnum, context)); |
|||
throw new RenException(EpmetErrorCode.TEXT_SCAN_FAILED.getCode()); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 图片列表校验 |
|||
* @param imgList 被校验的图片列表 |
|||
* @param businessEnum 业务枚举,定义校验失败后,输出的日志信息 |
|||
* |
|||
* @return void |
|||
* @auther zhangyong |
|||
* @Date 14:42 2020-07-15 |
|||
**/ |
|||
public void imgScanVerification(List<String> imgList, String businessEnum){ |
|||
if (null != imgList && NumConstant.ZERO != imgList.size()){ |
|||
ImgScanParamDTO imgScanParamDTO = new ImgScanParamDTO(); |
|||
imgList.forEach(url -> { |
|||
ImgTaskDTO task = new ImgTaskDTO(); |
|||
task.setDataId(UUID.randomUUID().toString().replace("-", "")); |
|||
task.setUrl(url); |
|||
imgScanParamDTO.getTasks().add(task); |
|||
}); |
|||
Result<SyncScanResult> imgScanResult = ScanContentUtils.imgSyncScan(scanApiUrl.concat(imgSyncScanMethod), imgScanParamDTO); |
|||
if (!imgScanResult.success()){ |
|||
throw new RenException(EpmetErrorCode.SERVER_ERROR.getCode()); |
|||
} else { |
|||
if (!imgScanResult.getData().isAllPass()) { |
|||
// 业务枚举:例如:评论话题失败,评论内容为:%s"
|
|||
log.error(String.format(businessEnum)); |
|||
throw new RenException(EpmetErrorCode.IMG_SCAN_FAILED.getCode()); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
Loading…
Reference in new issue