mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-17 06:46:21 +00:00
26 lines
531 B
Ruby
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
|