censor_bear 0.1.10 → 0.1.14
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/assets/stylesheets/censor_bear/home.css +4 -0
- data/app/controllers/censor_bear/home_controller.rb +31 -0
- data/app/controllers/censor_bear/logs_controller.rb +1 -0
- data/app/controllers/censor_bear/mod_logs_controller.rb +1 -1
- data/app/controllers/censor_bear/stop_words_controller.rb +11 -2
- data/app/helpers/censor_bear/home_helper.rb +4 -0
- data/app/models/censor_bear/log.rb +18 -0
- data/app/models/censor_bear/mod_log.rb +4 -0
- data/app/models/censor_bear/stop_word.rb +2 -2
- data/app/views/censor_bear/home/debug.turbo_stream.haml +8 -0
- data/app/views/censor_bear/home/debugger.html.haml +9 -0
- data/app/views/censor_bear/home/index.html.erb +2 -0
- data/app/views/censor_bear/logs/_log.html.haml +8 -2
- data/app/views/censor_bear/logs/index.html.haml +2 -1
- data/app/views/censor_bear/logs/show.html.haml +29 -0
- 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 +3 -2
- data/config/locales/censor_bear.yml +1 -0
- data/config/routes.rb +5 -1
- data/db/migrate/20211209093050_add_response_to_censor_bear_logs.rb +5 -0
- data/lib/censor_bear/censor.rb +30 -16
- data/lib/censor_bear/configuration.rb +2 -0
- data/lib/censor_bear/version.rb +1 -1
- data/lib/censor_bear.rb +4 -0
- metadata +10 -3
- data/app/views/censor_bear/logs/show.html.erb +0 -34
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: e8f5e80bfe3be4dc22e9c8fc14932f6c830a87efc0ee15d5588bd258f0311e0e
         | 
| 4 | 
            +
              data.tar.gz: bc47827fb4f09f2cd875d20db1c4593168917709b0174d0780237c503c156e5e
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: fc58e6353da8c5697b92f2c4857a7dcaa948a6e03c367d14aed8960b015c0809cc33094628efc1983f07865f270ae646bbf05c942dda7a58b425db54f3434f00
         | 
| 7 | 
            +
              data.tar.gz: d080b530b575ece289451d58079a40e3a85ad0f7721e8707cac299d141ea066047f5b36c13a9a5a7a133edf0e70707d28b85ea622ea4fe20f5309cc5be132462
         | 
| @@ -0,0 +1,31 @@ | |
| 1 | 
            +
            require_dependency 'censor_bear/application_controller'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module CensorBear
         | 
| 4 | 
            +
              class HomeController < ApplicationController
         | 
| 5 | 
            +
                def index; end
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                def debugger; end
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                def debug
         | 
| 10 | 
            +
                  content = params[:content]
         | 
| 11 | 
            +
                  type = params[:type]
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                  case params[:stage]
         | 
| 14 | 
            +
                  when 'aliyun_check'
         | 
| 15 | 
            +
                    @r = AliyunGreen::Text.scan(content)
         | 
| 16 | 
            +
                  when 'check_text'
         | 
| 17 | 
            +
                    @r = CensorBear.check_text(content, type.to_sym)
         | 
| 18 | 
            +
                  when 'check_search'
         | 
| 19 | 
            +
                    # TODO: 搜索前置检查
         | 
| 20 | 
            +
                    @r = {}
         | 
| 21 | 
            +
                  when 'check_image'
         | 
| 22 | 
            +
                    # TODO: 检查图片
         | 
| 23 | 
            +
                    @r = {}
         | 
| 24 | 
            +
                  when 'qq_regex'
         | 
| 25 | 
            +
                    @r = content.match(Censor::QQ_REG)
         | 
| 26 | 
            +
                  when 'wx_regex'
         | 
| 27 | 
            +
                    @r = content.match(Censor::WX_REG)
         | 
| 28 | 
            +
                  end
         | 
| 29 | 
            +
                end
         | 
| 30 | 
            +
              end
         | 
| 31 | 
            +
            end
         | 
| @@ -55,6 +55,7 @@ module CensorBear | |
| 55 55 | 
             
                def load_logs
         | 
| 56 56 | 
             
                  builder ||= log_scope
         | 
| 57 57 | 
             
                  builder = builder.where("original_content ilike ?", "%#{params[:q]}%") if params[:q].present?
         | 
| 58 | 
            +
                  builder = builder.where(stage: params[:stage]) if params[:stage].present?
         | 
| 58 59 | 
             
                  builder = builder.order(id: :desc)
         | 
| 59 60 |  | 
| 60 61 | 
             
                  @pagy, @logs = pagy(builder)
         | 
| @@ -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)
         | 
| @@ -1,5 +1,23 @@ | |
| 1 1 | 
             
            module CensorBear
         | 
| 2 2 | 
             
              class Log < ApplicationRecord
         | 
| 3 3 | 
             
                belongs_to :user, class_name: CensorBear.config.user_class, optional: true
         | 
| 4 | 
            +
             | 
| 5 | 
            +
                def suggestion
         | 
| 6 | 
            +
                  return nil if response.blank?
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                  response['data']&.first['results']&.first['suggestion']
         | 
| 9 | 
            +
                end
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                def rate
         | 
| 12 | 
            +
                  return nil if response.blank?
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                  response['data']&.first['results']&.first['rate']
         | 
| 15 | 
            +
                end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                def label
         | 
| 18 | 
            +
                  return nil if response.blank?
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                  response['data']&.first['results']&.first['label']
         | 
| 21 | 
            +
                end
         | 
| 4 22 | 
             
              end
         | 
| 5 23 | 
             
            end
         | 
| @@ -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
         | 
| @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            module CensorBear
         | 
| 2 2 | 
             
              class StopWord < ApplicationRecord
         | 
| 3 | 
            -
                FIELDS = %w(ugc username nickname signature dialog)
         | 
| 4 | 
            -
                ACTIONS_MAP = %w(ignore mod banned replace)
         | 
| 3 | 
            +
                FIELDS = %w(ugc username nickname signature dialog).freeze
         | 
| 4 | 
            +
                ACTIONS_MAP = %w(ignore mod banned replace).freeze
         | 
| 5 5 | 
             
                belongs_to :user, class_name: CensorBear.config.user_class
         | 
| 6 6 | 
             
              end
         | 
| 7 7 | 
             
            end
         | 
| @@ -0,0 +1,8 @@ | |
| 1 | 
            +
            = turbo_stream.update(:result) do
         | 
| 2 | 
            +
              %h3{class: "text-lg"} 检测结果
         | 
| 3 | 
            +
              %div{class: "bg-yellow-100 text-yellow-700 p-4 rounded-lg"}
         | 
| 4 | 
            +
                %pre{class: "whitespace-pre-wrap"}
         | 
| 5 | 
            +
                  - if @r.is_a?(MatchData)
         | 
| 6 | 
            +
                    = @r.pretty_inspect
         | 
| 7 | 
            +
                  - else
         | 
| 8 | 
            +
                    = JSON.pretty_generate(@r.is_a?(CensorBear::Result) ? JSON.parse(@r.to_json) : @r)
         | 
| @@ -0,0 +1,9 @@ | |
| 1 | 
            +
            %div{class: "flex flex-col space-y-2 rounded-lg border p-4"}
         | 
| 2 | 
            +
              %h2{class: "text-xl font-medium text-center"} 在线调试
         | 
| 3 | 
            +
              %div{class: "flex justify-center"}
         | 
| 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[check_search check_search], %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 | 
            +
                  = 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 | 
            +
                  = f.text_area :content, value: params[:content], placeholder: "输入正文", rows: 6, class: "bg-gray-100 rounded-lg p-4 w-full"
         | 
| 8 | 
            +
                  = f.submit "检测", class: "rounded-lg px-10 py-1 bg-black text-white cursor-pointer"
         | 
| 9 | 
            +
              #result
         | 
| @@ -9,6 +9,12 @@ | |
| 9 9 | 
             
                        %span{class: "text-sm bg-pink-100 text-pink-600 py-1 px-2 rounded-lg"}=t("censor_log.stage.#{log.stage}")
         | 
| 10 10 | 
             
                      - unless log.action.blank?
         | 
| 11 11 | 
             
                        %span{class: "text-sm bg-yellow-100 text-yellow-600 py-1 px-2 rounded-lg"}=t("censor_log.action.#{log.action.downcase}")
         | 
| 12 | 
            +
                      - unless log.suggestion.blank?
         | 
| 13 | 
            +
                        %span{class: "text-sm bg-green-100 text-green-600 py-1 px-2 rounded-lg"}=log.suggestion.upcase
         | 
| 14 | 
            +
                      - unless log.rate.blank?
         | 
| 15 | 
            +
                        %span{class: "text-sm bg-green-100 text-green-600 py-1 px-2 rounded-lg"}=log.rate
         | 
| 16 | 
            +
                      - unless log.label.blank?
         | 
| 17 | 
            +
                        %span{class: "text-sm bg-green-100 text-green-600 py-1 px-2 rounded-lg"}=log.label.upcase
         | 
| 12 18 | 
             
                      - unless log.user_id.blank?
         | 
| 13 19 | 
             
                        %span{class: "text-sm bg-gray-100 text-gray-600 py-1 px-2 rounded-lg font-bold"}="##{log.user_id}"
         | 
| 14 20 | 
             
                      - unless log.ip.blank?
         | 
| @@ -19,7 +25,7 @@ | |
| 19 25 | 
             
                      %span{class: "text-sm bg-gray-100 text-gray-600 py-1 px-2 rounded-lg"}= log.created_at
         | 
| 20 26 | 
             
                    %div{class: "flex space-x-2 items-center"}
         | 
| 21 27 | 
             
                      %span
         | 
| 22 | 
            -
                        = link_to '详情', log
         | 
| 28 | 
            +
                        = link_to '详情', log, data: { turbo: false }
         | 
| 23 29 | 
             
                      %span
         | 
| 24 30 | 
             
                        = button_to '删除', log, method: :delete, data: { confirm: 'Are you sure?' }, class: "text-red-600 rounded-md px-2 py-0.5"
         | 
| 25 31 | 
             
                  %div{class: "flex justify-between items-center"}
         | 
| @@ -32,5 +38,5 @@ | |
| 32 38 | 
             
                    %div{class: "text-yellow-500 font-meidum text-xl"}
         | 
| 33 39 | 
             
                      - log.mod_words.each do |word|
         | 
| 34 40 | 
             
                        %span [
         | 
| 35 | 
            -
                        %span= link_to word, stop_words_path(q: word), data: { turbo: false } | 
| 41 | 
            +
                        %span= link_to word, stop_words_path(q: word), data: { turbo: false }
         | 
| 36 42 | 
             
                        %span ]
         | 
| @@ -4,10 +4,11 @@ | |
| 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[aliyun_check aliyun_check], %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"
         | 
| 7 8 | 
             
                      = f.submit "检索", class: "rounded-md px-2 py-1 text-sm bg-black text-white cursor-pointer"
         | 
| 8 9 | 
             
                      = link_to "重置", logs_path, class: "text-sm"
         | 
| 9 10 |  | 
| 10 | 
            -
                %div="共 #{@pagy.count} 条"
         | 
| 11 | 
            +
                %div{class: "text-sm text-gray-600"}="共 #{@pagy.count} 条"
         | 
| 11 12 | 
             
              %div
         | 
| 12 13 | 
             
                - if @logs.blank?
         | 
| 13 14 | 
             
                  %div{class: "flex justify-center text-gray-500 p-8 border rounded-md"} 空空如也
         | 
| @@ -0,0 +1,29 @@ | |
| 1 | 
            +
            %div{class: "flex flex-col space-y-2"}
         | 
| 2 | 
            +
              %div
         | 
| 3 | 
            +
                %div{class: "font-bold"} 源内容:
         | 
| 4 | 
            +
                %div= @log.original_content
         | 
| 5 | 
            +
              %div
         | 
| 6 | 
            +
                %div{class: "font-bold"} 过滤后内容:
         | 
| 7 | 
            +
                %div= @log.filtered_content
         | 
| 8 | 
            +
              %div
         | 
| 9 | 
            +
                %div{class: "font-bold"} 动作:
         | 
| 10 | 
            +
                %div= @log.action
         | 
| 11 | 
            +
              %div
         | 
| 12 | 
            +
                %div{class: "font-bold"} 场景:
         | 
| 13 | 
            +
                %div= @log.scenario
         | 
| 14 | 
            +
              %div
         | 
| 15 | 
            +
                %div{class: "font-bold"} 检测阶段:
         | 
| 16 | 
            +
                %div= @log.stage
         | 
| 17 | 
            +
              %div
         | 
| 18 | 
            +
                %div{class: "font-bold"} 命中敏感词:
         | 
| 19 | 
            +
                %div= @log.mod_words
         | 
| 20 | 
            +
              %div
         | 
| 21 | 
            +
                %div{class: "font-bold"} 云检测返回标签:
         | 
| 22 | 
            +
                %div= @log.labels
         | 
| 23 | 
            +
              %div
         | 
| 24 | 
            +
                %div{class: "font-bold"} 云检测返回标签:
         | 
| 25 | 
            +
                %div= @log.labels
         | 
| 26 | 
            +
              %div
         | 
| 27 | 
            +
                %div{class: "font-bold"} 云检测返回:
         | 
| 28 | 
            +
                %div{class: "p-1 bg-gray-100 rounded-lg"}
         | 
| 29 | 
            +
                  %pre= JSON.pretty_generate(@log.response)
         | 
| @@ -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,10 @@ | |
| 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 "调试", debugger_path
         | 
| 16 | 
            +
                  %li= link_to "控制台", main_app.send(CensorBear.config.main_app_root_path_method.to_sym)
         | 
| 16 17 | 
             
                  %li= current_user.email
         | 
| 17 18 | 
             
                %div
         | 
| 18 19 | 
             
                  = yield
         | 
    
        data/config/routes.rb
    CHANGED
    
    
    
        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,32 +115,44 @@ 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 | 
            -
                      d['content'], @type,  | 
| 120 | 
            +
                      d['content'], @type, 'banned', 'aliyun_check',
         | 
| 121 121 | 
             
                      filtered_content: d['filteredContent'],
         | 
| 122 122 | 
             
                      mod_words: @mod_words,
         | 
| 123 123 | 
             
                      labels: @labels,
         | 
| 124 | 
            -
                      ip: @ip, user_id: @user_id
         | 
| 124 | 
            +
                      ip: @ip, user_id: @user_id,
         | 
| 125 | 
            +
                      response: response
         | 
| 125 126 | 
             
                    )
         | 
| 126 127 | 
             
                    raise NotPassedException
         | 
| 127 | 
            -
                  elsif action == 'block'
         | 
| 128 | 
            +
                  elsif action == 'block' && rate >= 90
         | 
| 128 129 | 
             
                    @is_mod = true
         | 
| 129 130 | 
             
                    CensorBear.info(
         | 
| 130 | 
            -
                      d['content'], @type,  | 
| 131 | 
            +
                      d['content'], @type, 'mod', 'aliyun_check',
         | 
| 131 132 | 
             
                      filtered_content: d['filteredContent'],
         | 
| 132 133 | 
             
                      mod_words: @mod_words,
         | 
| 133 134 | 
             
                      labels: @labels,
         | 
| 134 | 
            -
                      ip: @ip, user_id: @user_id
         | 
| 135 | 
            +
                      ip: @ip, user_id: @user_id,
         | 
| 136 | 
            +
                      response: response
         | 
| 135 137 | 
             
                    )
         | 
| 136 138 | 
             
                  elsif action == 'review'
         | 
| 137 139 | 
             
                    @is_mod = true
         | 
| 138 140 | 
             
                    CensorBear.info(
         | 
| 139 | 
            -
                      d['content'], @type,  | 
| 141 | 
            +
                      d['content'], @type, 'mod', 'aliyun_check',
         | 
| 140 142 | 
             
                      filtered_content: d['filteredContent'],
         | 
| 141 143 | 
             
                      mod_words: @mod_words,
         | 
| 142 144 | 
             
                      labels: @labels,
         | 
| 143 | 
            -
                      ip: @ip, user_id: @user_id
         | 
| 145 | 
            +
                      ip: @ip, user_id: @user_id,
         | 
| 146 | 
            +
                      response: response
         | 
| 147 | 
            +
                    )
         | 
| 148 | 
            +
                  else
         | 
| 149 | 
            +
                    CensorBear.info(
         | 
| 150 | 
            +
                      d['content'], @type, 'ignore', 'aliyun_check',
         | 
| 151 | 
            +
                      filtered_content: d['filteredContent'],
         | 
| 152 | 
            +
                      mod_words: @mod_words,
         | 
| 153 | 
            +
                      labels: @labels,
         | 
| 154 | 
            +
                      ip: @ip, user_id: @user_id,
         | 
| 155 | 
            +
                      response: response
         | 
| 144 156 | 
             
                    )
         | 
| 145 157 | 
             
                  end
         | 
| 146 158 | 
             
                end
         | 
| @@ -149,6 +161,7 @@ module CensorBear | |
| 149 161 |  | 
| 150 162 | 
             
                def concat_labels(data)
         | 
| 151 163 | 
             
                  return [] if data.blank?
         | 
| 164 | 
            +
             | 
| 152 165 | 
             
                  labels = []
         | 
| 153 166 | 
             
                  data.map do |d|
         | 
| 154 167 | 
             
                    next if d['label'].blank?
         | 
| @@ -160,6 +173,7 @@ module CensorBear | |
| 160 173 |  | 
| 161 174 | 
             
                def concat_words(data)
         | 
| 162 175 | 
             
                  return [] if data.blank?
         | 
| 176 | 
            +
             | 
| 163 177 | 
             
                  words = []
         | 
| 164 178 | 
             
                  data.each do |d|
         | 
| 165 179 | 
             
                    next if d['contexts'].blank?
         | 
    
        data/lib/censor_bear/version.rb
    CHANGED
    
    
    
        data/lib/censor_bear.rb
    CHANGED
    
    | @@ -24,6 +24,8 @@ module CensorBear | |
| 24 24 | 
             
                  @config.aliyun_green_access_key_id = ''
         | 
| 25 25 | 
             
                  @config.aliyun_green_access_key_secret = ''
         | 
| 26 26 | 
             
                  @config.aliyun_green_enable_internal = false
         | 
| 27 | 
            +
                  @config.main_app_root_path_method = 'root_path'
         | 
| 28 | 
            +
             | 
| 27 29 | 
             
                  @config
         | 
| 28 30 | 
             
                end
         | 
| 29 31 |  | 
| @@ -45,6 +47,7 @@ module CensorBear | |
| 45 47 | 
             
                  labels = options[:labels] || []
         | 
| 46 48 | 
             
                  ip = options[:ip] || nil
         | 
| 47 49 | 
             
                  user_id = options[:user_id] || nil
         | 
| 50 | 
            +
                  response = options[:response] || {}
         | 
| 48 51 |  | 
| 49 52 | 
             
                  CensorBear::Log.create(
         | 
| 50 53 | 
             
                    original_content: content,
         | 
| @@ -56,6 +59,7 @@ module CensorBear | |
| 56 59 | 
             
                    labels: labels,
         | 
| 57 60 | 
             
                    ip: ip,
         | 
| 58 61 | 
             
                    user_id: user_id,
         | 
| 62 | 
            +
                    response: response
         | 
| 59 63 | 
             
                  )
         | 
| 60 64 | 
             
                end
         | 
| 61 65 |  | 
    
        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.14
         | 
| 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
         | 
| @@ -112,16 +112,19 @@ files: | |
| 112 112 | 
             
            - Rakefile
         | 
| 113 113 | 
             
            - app/assets/config/censor_bear_manifest.js
         | 
| 114 114 | 
             
            - app/assets/stylesheets/censor_bear/application.css
         | 
| 115 | 
            +
            - app/assets/stylesheets/censor_bear/home.css
         | 
| 115 116 | 
             
            - app/assets/stylesheets/censor_bear/logs.css
         | 
| 116 117 | 
             
            - app/assets/stylesheets/censor_bear/mod_logs.css
         | 
| 117 118 | 
             
            - app/assets/stylesheets/censor_bear/stop_words.css
         | 
| 118 119 | 
             
            - app/assets/stylesheets/censor_bear/tailwind.min.css
         | 
| 119 120 | 
             
            - app/assets/stylesheets/scaffold.css
         | 
| 120 121 | 
             
            - app/controllers/censor_bear/application_controller.rb
         | 
| 122 | 
            +
            - app/controllers/censor_bear/home_controller.rb
         | 
| 121 123 | 
             
            - app/controllers/censor_bear/logs_controller.rb
         | 
| 122 124 | 
             
            - app/controllers/censor_bear/mod_logs_controller.rb
         | 
| 123 125 | 
             
            - app/controllers/censor_bear/stop_words_controller.rb
         | 
| 124 126 | 
             
            - app/helpers/censor_bear/application_helper.rb
         | 
| 127 | 
            +
            - app/helpers/censor_bear/home_helper.rb
         | 
| 125 128 | 
             
            - app/helpers/censor_bear/logs_helper.rb
         | 
| 126 129 | 
             
            - app/helpers/censor_bear/mod_logs_helper.rb
         | 
| 127 130 | 
             
            - app/helpers/censor_bear/stop_words_helper.rb
         | 
| @@ -131,13 +134,16 @@ files: | |
| 131 134 | 
             
            - app/models/censor_bear/log.rb
         | 
| 132 135 | 
             
            - app/models/censor_bear/mod_log.rb
         | 
| 133 136 | 
             
            - app/models/censor_bear/stop_word.rb
         | 
| 137 | 
            +
            - app/views/censor_bear/home/debug.turbo_stream.haml
         | 
| 138 | 
            +
            - app/views/censor_bear/home/debugger.html.haml
         | 
| 139 | 
            +
            - app/views/censor_bear/home/index.html.erb
         | 
| 134 140 | 
             
            - app/views/censor_bear/logs/_form.html.erb
         | 
| 135 141 | 
             
            - app/views/censor_bear/logs/_log.html.haml
         | 
| 136 142 | 
             
            - app/views/censor_bear/logs/destroy.turbo_stream.haml
         | 
| 137 143 | 
             
            - app/views/censor_bear/logs/edit.html.erb
         | 
| 138 144 | 
             
            - app/views/censor_bear/logs/index.html.haml
         | 
| 139 145 | 
             
            - app/views/censor_bear/logs/new.html.erb
         | 
| 140 | 
            -
            - app/views/censor_bear/logs/show.html. | 
| 146 | 
            +
            - app/views/censor_bear/logs/show.html.haml
         | 
| 141 147 | 
             
            - app/views/censor_bear/mod_logs/_form.html.erb
         | 
| 142 148 | 
             
            - app/views/censor_bear/mod_logs/_mod_log.html.haml
         | 
| 143 149 | 
             
            - app/views/censor_bear/mod_logs/destroy.turbo_stream.haml
         | 
| @@ -162,6 +168,7 @@ files: | |
| 162 168 | 
             
            - db/migrate/20211129110218_create_censor_bear_mod_logs.rb
         | 
| 163 169 | 
             
            - db/migrate/20211206092626_add_ip_to_censor_bear_logs.rb
         | 
| 164 170 | 
             
            - db/migrate/20211208041114_add_labels_to_censor_bear_logs.rb
         | 
| 171 | 
            +
            - db/migrate/20211209093050_add_response_to_censor_bear_logs.rb
         | 
| 165 172 | 
             
            - lib/censor_bear.rb
         | 
| 166 173 | 
             
            - lib/censor_bear/censor.rb
         | 
| 167 174 | 
             
            - lib/censor_bear/configuration.rb
         | 
| @@ -1,34 +0,0 @@ | |
| 1 | 
            -
            <p id="notice"><%= notice %></p>
         | 
| 2 | 
            -
             | 
| 3 | 
            -
            <p>
         | 
| 4 | 
            -
              <strong>Orginal content:</strong>
         | 
| 5 | 
            -
              <%= @log.original_content %>
         | 
| 6 | 
            -
            </p>
         | 
| 7 | 
            -
             | 
| 8 | 
            -
            <p>
         | 
| 9 | 
            -
              <strong>Action:</strong>
         | 
| 10 | 
            -
              <%= @log.action %>
         | 
| 11 | 
            -
            </p>
         | 
| 12 | 
            -
             | 
| 13 | 
            -
            <p>
         | 
| 14 | 
            -
              <strong>Scenario:</strong>
         | 
| 15 | 
            -
              <%= @log.scenario %>
         | 
| 16 | 
            -
            </p>
         | 
| 17 | 
            -
             | 
| 18 | 
            -
            <p>
         | 
| 19 | 
            -
              <strong>Stage:</strong>
         | 
| 20 | 
            -
              <%= @log.stage %>
         | 
| 21 | 
            -
            </p>
         | 
| 22 | 
            -
             | 
| 23 | 
            -
            <p>
         | 
| 24 | 
            -
              <strong>Filtered content:</strong>
         | 
| 25 | 
            -
              <%= @log.filtered_content %>
         | 
| 26 | 
            -
            </p>
         | 
| 27 | 
            -
             | 
| 28 | 
            -
            <p>
         | 
| 29 | 
            -
              <strong>Mod words:</strong>
         | 
| 30 | 
            -
              <%= @log.mod_words %>
         | 
| 31 | 
            -
            </p>
         | 
| 32 | 
            -
             | 
| 33 | 
            -
            <%= link_to 'Edit', edit_log_path(@log) %> |
         | 
| 34 | 
            -
            <%= link_to 'Back', logs_path %>
         |