Close DunCheck

This commit is contained in:
sylor_huang@126.com 2020-09-07 16:33:26 +08:00
parent d35faf3935
commit f9bcc7e02b
2 changed files with 32 additions and 31 deletions

View File

@ -6,15 +6,16 @@ module DunCheckAble
end end
def check_text_able def check_text_able
dun_check_params = get_model return true
if dun_check_params[:is_change] # dun_check_params = get_model
dun_check_params.delete(:is_change) # if dun_check_params[:is_change]
check_result = DunCheck::TextCheck.new(dun_check_params).call # dun_check_params.delete(:is_change)
if check_result[:status].to_i == -1 # check_result = DunCheck::TextCheck.new(dun_check_params).call
errors.add(:base, "内容含有:#{check_result[:extra_params][:infos]},请修改") # if check_result[:status].to_i == -1
# raise ActiveRecord::RecordInvalid.new(self) # errors.add(:base, "内容含有:#{check_result[:extra_params][:infos]},请修改")
end # # raise ActiveRecord::RecordInvalid.new(self)
end # end
# end
end end
def get_model def get_model

View File

@ -3,29 +3,29 @@ module DunCheckImageAble
included do included do
def self.check_image_able(file) def self.check_image_able(file)
return {status: 1}
# original_filename = file.original_filename
# file_extention = original_filename.split(".").last
# check_include = %w(jpg png bmp gif webp tiff jpeg)
original_filename = file.original_filename # if file_extention && check_include.include?(file_extention)
file_extention = original_filename.split(".").last # base64_file = Base64.encode64(file.open.read.force_encoding(Encoding::UTF_8))
check_include = %w(jpg png bmp gif webp tiff jpeg) # check_params = [
# {
if file_extention && check_include.include?(file_extention) # name: original_filename,
base64_file = Base64.encode64(file.open.read.force_encoding(Encoding::UTF_8)) # type: 2,
check_params = [ # data: base64_file,
{ # }
name: original_filename, # ]
type: 2, # check_result = DunCheck::ImageCheck.new(check_params).call
data: base64_file, # if check_result[:status].to_i == -1
} # return {status: -1, message: check_result[:message]}
] # else
check_result = DunCheck::ImageCheck.new(check_params).call # return {status: 1}
if check_result[:status].to_i == -1 # end
return {status: -1, message: check_result[:message]} # else
else # return {status: 1}
return {status: 1} # end
end
else
return {status: 1}
end
end end
end end