add: dun_check text and image
This commit is contained in:
parent
4cf8588343
commit
c283c7ed58
|
@ -6,16 +6,15 @@ module DunCheckAble
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_text_able
|
def check_text_able
|
||||||
return true
|
dun_check_params = get_model
|
||||||
# dun_check_params = get_model
|
if dun_check_params[:is_change]
|
||||||
# if dun_check_params[:is_change]
|
dun_check_params.delete(:is_change)
|
||||||
# dun_check_params.delete(:is_change)
|
check_result = DunCheck::TextCheck.new(dun_check_params).call
|
||||||
# check_result = DunCheck::TextCheck.new(dun_check_params).call
|
if check_result[:status].to_i == -1
|
||||||
# if check_result[:status].to_i == -1
|
errors.add(:base, "内容含有:#{check_result[:extra_params][:infos]},请修改")
|
||||||
# errors.add(:base, "内容含有:#{check_result[:extra_params][:infos]},请修改")
|
# raise ActiveRecord::RecordInvalid.new(self)
|
||||||
# # raise ActiveRecord::RecordInvalid.new(self)
|
end
|
||||||
# end
|
end
|
||||||
# end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_model
|
def get_model
|
||||||
|
|
|
@ -3,29 +3,28 @@ module DunCheckImageAble
|
||||||
|
|
||||||
included do
|
included do
|
||||||
def self.check_image_able(file)
|
def self.check_image_able(file)
|
||||||
|
original_filename = file.original_filename
|
||||||
|
file_extention = original_filename.split(".").last
|
||||||
|
check_include = %w(jpg png bmp gif webp tiff jpeg)
|
||||||
|
|
||||||
|
if file_extention && check_include.include?(file_extention)
|
||||||
|
base64_file = Base64.encode64(file.open.read.force_encoding(Encoding::UTF_8))
|
||||||
|
check_params = [
|
||||||
|
{
|
||||||
|
name: original_filename,
|
||||||
|
type: 2,
|
||||||
|
data: base64_file,
|
||||||
|
}
|
||||||
|
]
|
||||||
|
check_result = DunCheck::ImageCheck.new(check_params).call
|
||||||
|
if check_result[:status].to_i == -1
|
||||||
|
return {status: -1, message: check_result[:message]}
|
||||||
|
else
|
||||||
return {status: 1}
|
return {status: 1}
|
||||||
# original_filename = file.original_filename
|
end
|
||||||
# file_extention = original_filename.split(".").last
|
else
|
||||||
# check_include = %w(jpg png bmp gif webp tiff jpeg)
|
return {status: 1}
|
||||||
|
end
|
||||||
# if file_extention && check_include.include?(file_extention)
|
|
||||||
# base64_file = Base64.encode64(file.open.read.force_encoding(Encoding::UTF_8))
|
|
||||||
# check_params = [
|
|
||||||
# {
|
|
||||||
# name: original_filename,
|
|
||||||
# type: 2,
|
|
||||||
# data: base64_file,
|
|
||||||
# }
|
|
||||||
# ]
|
|
||||||
# check_result = DunCheck::ImageCheck.new(check_params).call
|
|
||||||
# if check_result[:status].to_i == -1
|
|
||||||
# return {status: -1, message: check_result[:message]}
|
|
||||||
# else
|
|
||||||
# return {status: 1}
|
|
||||||
# end
|
|
||||||
# else
|
|
||||||
# return {status: 1}
|
|
||||||
# end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue