censor_bear 0.1.15 → 0.1.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/controllers/censor_bear/logs_controller.rb +17 -0
- data/app/controllers/censor_bear/mod_logs_controller.rb +5 -3
- data/app/models/censor_bear/mod_log.rb +21 -3
- data/app/views/censor_bear/home/debugger.html.haml +1 -1
- data/app/views/censor_bear/logs/index.html.haml +6 -2
- data/app/views/censor_bear/mod_logs/_mod_log.html.haml +8 -9
- data/config/locales/censor_bear.yml +2 -2
- data/config/routes.rb +3 -1
- data/db/migrate/20211129110218_create_censor_bear_mod_logs.rb +0 -1
- data/lib/censor_bear/censor.rb +13 -11
- data/lib/censor_bear/version.rb +1 -1
- 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: da82f8fafa1a258c9009099fc66621805e19ac0750662f92153eb3a1a8ba5b01
|
4
|
+
data.tar.gz: 4a51f1c4260ba69397dfc583093fb59417ba0f9b95b458243d2b28ec58087454
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0fed9c06844c55e4fca2c9d997d8f7af7a1bb04c33c0cc73f7fe1d1cbf4c1f0bce029a239f058a0eda4bd8bd11c9b670ad4019d8f3d75e9916d00f8d66a6ddf2
|
7
|
+
data.tar.gz: 11a70e93051a636a39240dd09327ef38778c82fc22af53b325e28e1635036de93f9ab85ab4b66d6cc8e78d1c04ae6b74ad31b7fa31ee5a958a75b9ac09dcccb7
|
@@ -52,6 +52,23 @@ module CensorBear
|
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
|
+
def remove_data
|
56
|
+
builder = log_scope
|
57
|
+
case params[:type]
|
58
|
+
when '3days'
|
59
|
+
builder = builder.where("created_at >= ?", (Time.now - 3.days).beginning_of_day)
|
60
|
+
when '7days'
|
61
|
+
builder = builder.where("created_at >= ?", (Time.now - 7.days).beginning_of_day)
|
62
|
+
when '30days'
|
63
|
+
builder = builder.where("created_at >= ?", (Time.now - 30.days).beginning_of_day)
|
64
|
+
when 'all'
|
65
|
+
builder
|
66
|
+
end
|
67
|
+
builder.delete_all
|
68
|
+
|
69
|
+
redirect_to logs_url, notice: "Mod log was successfully destroyed."
|
70
|
+
end
|
71
|
+
|
55
72
|
def load_logs
|
56
73
|
builder ||= log_scope
|
57
74
|
builder = builder.where("original_content ilike ?", "%#{params[:q]}%") if params[:q].present?
|
@@ -45,7 +45,6 @@ module CensorBear
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
-
|
49
48
|
def suspend
|
50
49
|
@mod_log.suspend!
|
51
50
|
|
@@ -59,8 +58,11 @@ module CensorBear
|
|
59
58
|
end
|
60
59
|
|
61
60
|
def undo
|
62
|
-
|
63
|
-
|
61
|
+
if @mod_log.passed?
|
62
|
+
@mod_log.undo_approve
|
63
|
+
elsif @mod_log.rejected?
|
64
|
+
@mod_log.undo_remove
|
65
|
+
end
|
64
66
|
|
65
67
|
redirect_to mod_logs_url, notice: 'Mod log was successfully ignored.'
|
66
68
|
end
|
@@ -5,6 +5,16 @@ module CensorBear
|
|
5
5
|
REASONS = %w(无 广告/SPAM 恶意灌水 违规内容 文不对题 重复发布 其它).freeze
|
6
6
|
belongs_to :record, polymorphic: true, required: false
|
7
7
|
|
8
|
+
validates :record_id, uniqueness: { scope: [:record_type] }
|
9
|
+
|
10
|
+
def images
|
11
|
+
return [] if record.blank?
|
12
|
+
|
13
|
+
raise NoMethodError, 'undefined censor_images for record' unless record.respond_to?(:censor_images)
|
14
|
+
|
15
|
+
record.censor_images
|
16
|
+
end
|
17
|
+
|
8
18
|
def record_path
|
9
19
|
return '#' if record.blank?
|
10
20
|
|
@@ -21,6 +31,14 @@ module CensorBear
|
|
21
31
|
reject!(reason) if ret
|
22
32
|
end
|
23
33
|
|
34
|
+
def undo_remove
|
35
|
+
return if record.blank?
|
36
|
+
raise NoMethodError unless record.respond_to?(:censor_undo_remove)
|
37
|
+
|
38
|
+
ret = record.censor_undo_remove
|
39
|
+
undo! if ret
|
40
|
+
end
|
41
|
+
|
24
42
|
def approve
|
25
43
|
return if record.blank?
|
26
44
|
raise NoMethodError unless record.respond_to?(:censor_approve)
|
@@ -29,11 +47,11 @@ module CensorBear
|
|
29
47
|
pass! if ret
|
30
48
|
end
|
31
49
|
|
32
|
-
def
|
50
|
+
def undo_approve
|
33
51
|
return if record.blank?
|
34
|
-
raise NoMethodError unless record.respond_to?(:
|
52
|
+
raise NoMethodError unless record.respond_to?(:censor_undo_approve)
|
35
53
|
|
36
|
-
ret = record.
|
54
|
+
ret = record.censor_undo_approve
|
37
55
|
undo! if ret
|
38
56
|
end
|
39
57
|
|
@@ -2,7 +2,7 @@
|
|
2
2
|
%h2{class: "text-xl font-medium text-center"} 在线调试
|
3
3
|
%div{class: "flex justify-center"}
|
4
4
|
= form_with(url: debug_path, method: :post, class: "flex flex-col items-center w-full space-y-4") do |f|
|
5
|
-
= f.select :stage, options_for_select([%w[check_text check_text], %w[
|
5
|
+
= f.select :stage, options_for_select([%w[check_text check_text], %w[aliyun_check aliyun_check], %w[check_search check_search], %w[qq_regex qq_regex], %w[wx_regex wx_regex]], params[:stage]), {}, class: "border rounded-md m py-0.5 px-1"
|
6
6
|
= f.select :type, options_for_select(CensorBear::StopWord::FIELDS.map{|f| [f.upcase, f]}, params[:type]), {}, class: "border rounded-md m py-0.5 px-1"
|
7
7
|
= f.text_area :content, value: params[:content], placeholder: "输入正文", rows: 6, class: "bg-gray-100 rounded-lg p-4 w-full"
|
8
8
|
= f.submit "检测", class: "rounded-lg px-10 py-1 bg-black text-white cursor-pointer"
|
@@ -4,11 +4,15 @@
|
|
4
4
|
= form_with(url: logs_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 :stage, options_for_select([%w[aliyun_check aliyun_check], %w[
|
7
|
+
= f.select :stage, options_for_select([%w[aliyun_check aliyun_check], %w[check_search check_search], %w[qq_regex qq_regex], %w[wx_regex wx_regex], %w[local_check local_check]], params[:stage]), {include_blank: "-- 按Stage筛选 --"}, class: "border rounded-md m py-0.5 px-1"
|
8
8
|
= f.submit "检索", class: "rounded-md px-2 py-1 text-sm bg-black text-white cursor-pointer"
|
9
9
|
= link_to "重置", logs_path, class: "text-sm"
|
10
10
|
|
11
|
-
%div{class: "
|
11
|
+
%div{class: "flex space-x-2 items-center"}
|
12
|
+
%div{class: "text-sm text-gray-600"}="共 #{@pagy.count} 条"
|
13
|
+
= form_with(url: remove_data_logs_path, method: :delete, class: "flex items-center space-x-2") do |f|
|
14
|
+
= f.select :type, options_for_select([%w[最近3天 3days], %w[最近7天 7days], %w[最近30天 30days], %w[全部 all]], params[:type]), {include_blank: "-- 选择删除范围 --"}, class: "border text-red-600 border-red-600 rounded-md m py-0.5 px-1"
|
15
|
+
= f.submit "删除日志", class: "rounded-md px-2 py-1 text-xs bg-red-600 text-white cursor-pointer"
|
12
16
|
%div
|
13
17
|
- if @logs.blank?
|
14
18
|
%div{class: "flex justify-center text-gray-500 p-8 border rounded-md"} 空空如也
|
@@ -21,21 +21,20 @@
|
|
21
21
|
%div
|
22
22
|
%span{class: "border border-pink-600 text-pink-600 rounded-lg text-xs p-0.5"}=mod_log.record.is_private ? "隐私" : "公开"
|
23
23
|
%span{class: "border border-blue-600 text-blue-600 rounded-lg text-xs p-0.5"}=mod_log.record.is_approved ? "审核通过" : "审核中..."
|
24
|
+
- unless mod_log.labels.blank?
|
25
|
+
- mod_log.labels.each do |label|
|
26
|
+
%span{class: "border border-yellow-600 text-yellow-600 rounded-lg text-xs p-0.5"}=t("censor_log.label.#{label}")
|
27
|
+
- unless mod_log.mod_words.blank?
|
28
|
+
- mod_log.mod_words.each do |word|
|
29
|
+
%span{class: "border border-red-600 text-red-600 rounded-lg text-xs p-0.5"}="##{word}"
|
24
30
|
- if mod_log.record.discarded?
|
25
31
|
%div{class: "text-gray-900 leading-relaxed"}
|
26
32
|
%del= mod_log.record.content
|
27
33
|
- else
|
28
34
|
%div{class: "text-gray-900 leading-relaxed"}= mod_log.record.content
|
29
35
|
%div
|
30
|
-
- mod_log.
|
31
|
-
= image_tag
|
32
|
-
%div
|
33
|
-
- unless mod_log.labels.blank?
|
34
|
-
- mod_log.labels.each do |label|
|
35
|
-
%span{class: "text-xs bg-gray-200 text-gray-600 py-0.5 px-1 rounded-lg"}=t("censor_log.label.#{label}")
|
36
|
-
- unless mod_log.mod_words.blank?
|
37
|
-
- mod_log.mod_words.each do |word|
|
38
|
-
%span{class: "text-sm bg-gray-100 text-gray-600 py-0.5 px-1 rounded-lg"}="##{word}"
|
36
|
+
- mod_log.images.each do |img|
|
37
|
+
= image_tag img[:src], class: "w-16 rounded-md"
|
39
38
|
%div{class: "flex space-x-2 items-center justify-end"}
|
40
39
|
- if mod_log.may_suspend?
|
41
40
|
= link_to "忽略", mod_log_suspend_path(mod_log), class: "text-yellow-600 cursor-pointer"
|
data/config/routes.rb
CHANGED
data/lib/censor_bear/censor.rb
CHANGED
@@ -115,17 +115,19 @@ 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].include?(r['label'])
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
118
|
+
# if action == 'block' && rate >= 70 && %w[politics terrorism].include?(r['label'])
|
119
|
+
# @is_mod = true
|
120
|
+
# CensorBear.info(
|
121
|
+
# d['content'], @type, 'mod', 'aliyun_check',
|
122
|
+
# filtered_content: d['filteredContent'],
|
123
|
+
# mod_words: @mod_words,
|
124
|
+
# labels: @labels,
|
125
|
+
# ip: @ip, user_id: @user_id,
|
126
|
+
# response: response
|
127
|
+
# )
|
128
|
+
# # raise NotPassedException
|
129
|
+
# elsif action == 'block' && rate >= 90
|
130
|
+
if action == 'block'
|
129
131
|
@is_mod = true
|
130
132
|
CensorBear.info(
|
131
133
|
d['content'], @type, 'mod', 'aliyun_check',
|
data/lib/censor_bear/version.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.17
|
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-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|