增加敏感词检测

This commit is contained in:
2025-08-11 19:56:50 +08:00
parent 5291e774ad
commit bf4cf82d4d
6 changed files with 135 additions and 13 deletions

View File

@@ -0,0 +1,44 @@
package com.onekeycall.videotablet.config;
import com.github.houbb.sensitive.word.bs.SensitiveWordBs;
import com.github.houbb.sensitive.word.support.ignore.SensitiveWordCharIgnores;
import com.github.houbb.sensitive.word.support.resultcondition.WordResultConditions;
import com.github.houbb.sensitive.word.support.tag.WordTags;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* 配置类,用于设置敏感词过滤器的自定义过滤策略
* 更多配置见 https://github.com/houbb/sensitive-word
*/
@Configuration
public class SensitiveWordConfig {
/**
* 初始化引导类
* @return 初始化引导类
* @since 1.0.0
*/
@Bean
public SensitiveWordBs sensitiveWordBs() {
SensitiveWordBs wordBs = SensitiveWordBs.newInstance()
.ignoreCase(true) // 忽略大小写默认值为true
.ignoreWidth(true) // 忽略半角圆角默认值为true
.ignoreNumStyle(true) // 忽略数字的写法默认值为true
.ignoreChineseStyle(true) // 忽略中文的书写格式默认值为true
.ignoreEnglishStyle(true) // 忽略英文的书写格式默认值为true
.ignoreRepeat(false) // 忽略重复词默认值为false
.enableNumCheck(false) // 是否启用数字检测默认值为false
.enableEmailCheck(false) // 是有启用邮箱检测默认值为false
.enableUrlCheck(false) // 是否启用链接检测默认值为false
.enableIpv4Check(false) // 是否启用IPv4检测默认值为false
.enableWordCheck(true) // 是否启用敏感单词检测默认值为true
.numCheckLen(8) // 数字检测自定义指定长度默认值为8
.wordTag(WordTags.none()) // 词对应的标签默认值为none
.charIgnore(SensitiveWordCharIgnores.defaults()) // 忽略的字符默认值为none
.wordResultCondition(WordResultConditions.alwaysTrue()) // 针对匹配的敏感词额外加工,比如可以限制英文单词必须全匹配,默认恒为真
.init();
return wordBs;
}
}