debian-mirror-gitlab/app/uploaders/uploader_helper.rb

46 lines
1.2 KiB
Ruby
Raw Normal View History

2015-11-26 14:37:03 +05:30
# Extra methods for uploader
module UploaderHelper
2017-08-17 22:00:37 +05:30
IMAGE_EXT = %w[png jpg jpeg gif bmp tiff].freeze
2016-08-24 12:49:21 +05:30
# We recommend using the .mp4 format over .mov. Videos in .mov format can
# still be used but you really need to make sure they are served with the
# proper MIME type video/mp4 and not video/quicktime or your videos won't play
# on IE >= 9.
# http://archive.sublimevideo.info/20150912/docs.sublimevideo.net/troubleshooting.html
2017-08-17 22:00:37 +05:30
VIDEO_EXT = %w[mp4 m4v mov webm ogv].freeze
# These extension types can contain dangerous code and should only be embedded inline with
# proper filtering. They should always be tagged as "Content-Disposition: attachment", not "inline".
DANGEROUS_EXT = %w[svg].freeze
2016-08-24 12:49:21 +05:30
2015-11-26 14:37:03 +05:30
def image?
2016-08-24 12:49:21 +05:30
extension_match?(IMAGE_EXT)
end
def video?
extension_match?(VIDEO_EXT)
end
def image_or_video?
image? || video?
end
2017-08-17 22:00:37 +05:30
def dangerous?
extension_match?(DANGEROUS_EXT)
end
private
2016-08-24 12:49:21 +05:30
def extension_match?(extensions)
return false unless file
extension =
if file.respond_to?(:extension)
file.extension
else
# Not all CarrierWave storages respond to :extension
File.extname(file.path).delete('.')
end
extensions.include?(extension.downcase)
2015-11-26 14:37:03 +05:30
end
end