censor_bear 0.1.9 → 0.1.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/censor_bear/mod_logs_controller.rb +1 -1
- data/app/controllers/censor_bear/stop_words_controller.rb +11 -2
- data/app/models/censor_bear/mod_log.rb +4 -0
- data/app/views/censor_bear/logs/_log.html.haml +1 -2
- data/app/views/censor_bear/logs/index.html.haml +1 -1
- data/app/views/censor_bear/mod_logs/_mod_log.html.haml +2 -2
- data/app/views/censor_bear/mod_logs/index.html.haml +1 -1
- data/app/views/censor_bear/stop_words/index.html.haml +2 -1
- data/app/views/layouts/censor_bear/application.html.haml +2 -2
- data/config/locales/censor_bear.yml +6 -5
- data/lib/censor_bear/censor.rb +11 -9
- data/lib/censor_bear/configuration.rb +2 -0
- data/lib/censor_bear/version.rb +1 -1
- data/lib/censor_bear.rb +2 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a3bf3dd6d88b6f7ece7434deabf56aa6322c305536e44d5ead4bae5c1aa94111
|
4
|
+
data.tar.gz: 9484d90389880990a519229d851394f7a484455972316f90f3d9891dda32851d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e283297831488e216fe57089166d37084725ef93a387ea615d6897298d95616b181880af06c19e1ce3caf536ac29bdaedf1a25408f7392719390da40d721be8d
|
7
|
+
data.tar.gz: 11568a082cc47a024aecb4bd7a2b1f09e785b7690e88bba1bb6acb5445b7eb31ac4f4834f4a63c5429fe8a2c1c40ae6e6c72c21efd130903d3cdb4df81a25d16
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require_dependency
|
1
|
+
require_dependency 'censor_bear/application_controller'
|
2
2
|
|
3
3
|
module CensorBear
|
4
4
|
class StopWordsController < ApplicationController
|
@@ -46,7 +46,16 @@ module CensorBear
|
|
46
46
|
|
47
47
|
def load_stop_words
|
48
48
|
builder ||= stop_word_scope
|
49
|
-
builder = builder.where(
|
49
|
+
builder = builder.where('key ilike ?', "%#{params[:q]}%") if params[:q].present?
|
50
|
+
case params[:filter]
|
51
|
+
when 'size_one'
|
52
|
+
builder = builder.where('length(key) = 1')
|
53
|
+
when 'size_two'
|
54
|
+
builder = builder.where('length(key) = 2')
|
55
|
+
when 'size_three'
|
56
|
+
builder = builder.where('length(key) = 3')
|
57
|
+
end
|
58
|
+
builder = builder.where('key ilike ?', "%#{params[:q]}%")
|
50
59
|
builder = builder.order(id: :desc)
|
51
60
|
|
52
61
|
@pagy, @stop_words = pagy(builder)
|
@@ -10,6 +10,8 @@ module CensorBear
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def delete(reason)
|
13
|
+
return if record.blank?
|
14
|
+
return if record.discarded?
|
13
15
|
# ugc内容需要开软删,便于撤销&查看统计,可以定时删除统计并删除软删内容,类似回收站机制
|
14
16
|
raise NoMethodError.new("undefined censor_delete for record") unless record.respond_to?(:censor_delete)
|
15
17
|
|
@@ -18,6 +20,7 @@ module CensorBear
|
|
18
20
|
end
|
19
21
|
|
20
22
|
def approve
|
23
|
+
return if record.blank?
|
21
24
|
raise NoMethodError unless record.respond_to?(:censor_approve)
|
22
25
|
|
23
26
|
ret = record.censor_approve
|
@@ -25,6 +28,7 @@ module CensorBear
|
|
25
28
|
end
|
26
29
|
|
27
30
|
def ban_user
|
31
|
+
return if record.blank?
|
28
32
|
raise NoMethodError unless record.respond_to?(:censor_ban_user)
|
29
33
|
|
30
34
|
ret = record.censor_ban_user
|
@@ -16,7 +16,6 @@
|
|
16
16
|
- unless log.labels.blank?
|
17
17
|
- log.labels.each do |label|
|
18
18
|
%span{class: "text-sm bg-red-100 text-red-600 py-1 px-2 rounded-lg"}=t("censor_log.label.#{label}")
|
19
|
-
|
20
19
|
%span{class: "text-sm bg-gray-100 text-gray-600 py-1 px-2 rounded-lg"}= log.created_at
|
21
20
|
%div{class: "flex space-x-2 items-center"}
|
22
21
|
%span
|
@@ -33,5 +32,5 @@
|
|
33
32
|
%div{class: "text-yellow-500 font-meidum text-xl"}
|
34
33
|
- log.mod_words.each do |word|
|
35
34
|
%span [
|
36
|
-
%span= link_to word, stop_words_path(q: word)
|
35
|
+
%span= link_to word, stop_words_path(q: word), data: { turbo: false }
|
37
36
|
%span ]
|
@@ -7,7 +7,7 @@
|
|
7
7
|
= f.submit "检索", class: "rounded-md px-2 py-1 text-sm bg-black text-white cursor-pointer"
|
8
8
|
= link_to "重置", logs_path, class: "text-sm"
|
9
9
|
|
10
|
-
%div="共 #{@pagy.count} 条"
|
10
|
+
%div{class: "text-sm text-gray-600"}="共 #{@pagy.count} 条"
|
11
11
|
%div
|
12
12
|
- if @logs.blank?
|
13
13
|
%div{class: "flex justify-center text-gray-500 p-8 border rounded-md"} 空空如也
|
@@ -3,7 +3,7 @@
|
|
3
3
|
%div{class: "border rounded-md mb-2 p-2 flex flex-col space-y-1"}
|
4
4
|
%div{class: "flex justify-between"}
|
5
5
|
%div{class: ""}
|
6
|
-
= link_to mod_log.record_path do
|
6
|
+
= link_to mod_log.record_path, data: { turbo: false }, target: "_blank" do
|
7
7
|
%span{class: "text-sm bg-indigo-100 text-indigo-600 py-1 px-2 rounded-lg"}="#{mod_log.record_type.upcase}##{mod_log.record_id}"
|
8
8
|
- unless mod_log.labels.blank?
|
9
9
|
- mod_log.labels.each do |label|
|
@@ -24,7 +24,7 @@
|
|
24
24
|
- if mod_log.status == 2
|
25
25
|
= "暂缓"
|
26
26
|
%span
|
27
|
-
= link_to "详情", mod_log
|
27
|
+
= link_to "详情", mod_log, data: { turbo: false }, target: "_blank"
|
28
28
|
%span
|
29
29
|
= button_to '删除', mod_log, method: :delete, data: { confirm: 'Are you sure?'}, class: "text-red-600 rounded-md px-2 py-0.5"
|
30
30
|
%div{class: "flex justify-between items-center"}
|
@@ -7,7 +7,7 @@
|
|
7
7
|
= f.submit "检索", class: "rounded-md px-2 py-1 text-sm bg-black text-white cursor-pointer"
|
8
8
|
= link_to "重置", mod_logs_path, class: "text-sm"
|
9
9
|
|
10
|
-
%div="共 #{@pagy.count} 条"
|
10
|
+
%div{class: "text-sm text-gray-600"}="共 #{@pagy.count} 条"
|
11
11
|
%div
|
12
12
|
- if @mod_logs.blank?
|
13
13
|
%div{class: "flex justify-center text-gray-500 p-8 border rounded-md"} 空空如也
|
@@ -4,10 +4,11 @@
|
|
4
4
|
= form_with(url: stop_words_path, method: :get, class: "flex items-center") do |f|
|
5
5
|
%div{class: "space-x-0.5"}
|
6
6
|
= f.text_field :q, value: params[:q], placeholder: "关键词", class: "border rounded-md m py-0.5 px-1"
|
7
|
+
= f.select :filter, options_for_select([%w[长度为1 size_one], %w[长度为2 size_two], %w[长度为3 size_three]], params[:filter]), {include_blank: "-- 按敏感词长度筛选 --"}, class: "border rounded-md m py-0.5 px-1"
|
7
8
|
= f.submit "检索", class: "rounded-md px-2 py-1 text-sm bg-black text-white cursor-pointer"
|
8
9
|
= link_to "重置", stop_words_path, class: "text-sm"
|
9
|
-
|
10
10
|
%div
|
11
|
+
%span{class: "text-sm text-gray-600"}="共 #{@pagy.count} 条"
|
11
12
|
= link_to '批量导入', "#", class: "text-sm"
|
12
13
|
= link_to '新增', new_stop_word_path, class: "rounded-md px-2 py-1 text-sm bg-black text-white cursor-pointer"
|
13
14
|
%div
|
@@ -10,9 +10,9 @@
|
|
10
10
|
%body{class: "flex flex-col space-y-6 p-4"}
|
11
11
|
%ul{class: "flex justify-end items-center space-x-2 text-blue-600"}
|
12
12
|
%li= link_to "审查(#{CensorBear::ModLog.pending.count})", mod_logs_path
|
13
|
-
%li= link_to "敏感词", stop_words_path
|
14
13
|
%li= link_to "日志", logs_path
|
15
|
-
%li= link_to "
|
14
|
+
%li= link_to "敏感词", stop_words_path
|
15
|
+
%li= link_to "控制台", main_app.send(CensorBear.config.main_app_root_path_method.to_sym)
|
16
16
|
%li= current_user.email
|
17
17
|
%div
|
18
18
|
= yield
|
@@ -9,11 +9,12 @@ en:
|
|
9
9
|
pass: 忽略
|
10
10
|
review: 审核
|
11
11
|
stage:
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
12
|
+
check_search: 搜索检查
|
13
|
+
aliyun_check: 阿里云检查
|
14
|
+
tencent_check: 腾讯云检查
|
15
|
+
local_check: 本地检查
|
16
|
+
qq_regex: QQ正则检查
|
17
|
+
wechat_regex: 微信正则检查
|
17
18
|
label:
|
18
19
|
normal: 正常文本
|
19
20
|
spam: 含垃圾信息
|
data/lib/censor_bear/censor.rb
CHANGED
@@ -30,15 +30,15 @@ module CensorBear
|
|
30
30
|
return Result.new(@content) unless CensorBear::StopWord::FIELDS.include?(@type)
|
31
31
|
|
32
32
|
# 正则过滤
|
33
|
-
if @content.match(QQ_REG)
|
34
|
-
|
35
|
-
|
36
|
-
end
|
33
|
+
# if @content.match(QQ_REG)
|
34
|
+
# CensorBear.info(@content, @type, 'BANNED', 'qq_regex', ip: @ip, user_id: @user_id)
|
35
|
+
# raise NotPassedException
|
36
|
+
# end
|
37
37
|
|
38
|
-
if @content.match(WX_REG)
|
39
|
-
|
40
|
-
|
41
|
-
end
|
38
|
+
# if @content.match(WX_REG)
|
39
|
+
# CensorBear.info(@content, @type, 'BANNED', 'wx_regex', ip: @ip, user_id: @user_id)
|
40
|
+
# raise NotPassedException
|
41
|
+
# end
|
42
42
|
|
43
43
|
# 本地自定义词库粗查
|
44
44
|
local_check
|
@@ -115,7 +115,7 @@ module CensorBear
|
|
115
115
|
rate = r['rate']
|
116
116
|
@mod_words = concat_words(r['details'])
|
117
117
|
@labels = concat_labels(r['details'])
|
118
|
-
if action == 'block' && rate >= 70 && %w[politics terrorism
|
118
|
+
if action == 'block' && rate >= 70 && %w[politics terrorism].include?(r['label'])
|
119
119
|
CensorBear.info(
|
120
120
|
d['content'], @type, action, 'aliyun_check',
|
121
121
|
filtered_content: d['filteredContent'],
|
@@ -148,6 +148,7 @@ module CensorBear
|
|
148
148
|
private
|
149
149
|
|
150
150
|
def concat_labels(data)
|
151
|
+
return [] if data.blank?
|
151
152
|
labels = []
|
152
153
|
data.map do |d|
|
153
154
|
next if d['label'].blank?
|
@@ -158,6 +159,7 @@ module CensorBear
|
|
158
159
|
end
|
159
160
|
|
160
161
|
def concat_words(data)
|
162
|
+
return [] if data.blank?
|
161
163
|
words = []
|
162
164
|
data.each do |d|
|
163
165
|
next if d['contexts'].blank?
|
data/lib/censor_bear/version.rb
CHANGED
data/lib/censor_bear.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: censor_bear
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- 42up
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-12-
|
11
|
+
date: 2021-12-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|