5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-17 06:46:21 +00:00
panel/app/models/metadata_image.rb
2019-11-07 13:08:14 -03:00

26 lines
531 B
Ruby

# frozen_string_literal: true
# Define un campo de imagen
class MetadataImage < MetadataFile
def validate
super
errors << I18n.t('metadata.image.not_an_image') unless image?
errors.compact!
errors.empty?
end
# Determina si es una imagen antes de subirla
def image?
if value['path'].is_a? ActionDispatch::Http::UploadedFile
`file --mime-type "#{value['path'].tempfile.path}"`
.split(' ')
.last
.chomp
.starts_with? 'image/'
else
true
end
end
end