diff options
author | Rémy Coutable <remy@rymai.me> | 2016-07-08 18:55:49 +0200 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2016-07-19 18:51:09 +0200 |
commit | 29ea8d09e05d749f0b6a784311aea942f7d2d0f1 (patch) | |
tree | 9326f19dc1a67b3345f2c128f0b1118760fdb094 /app/uploaders | |
parent | 356b2d2bd782289b6130a22531523562514aa7f6 (diff) | |
download | gitlab-ce-29ea8d09e05d749f0b6a784311aea942f7d2d0f1.tar.gz |
Remove duplication, useless rescue, and avoid using ActionView
Signed-off-by: Rémy Coutable <remy@rymai.me>
Diffstat (limited to 'app/uploaders')
-rw-r--r-- | app/uploaders/uploader_helper.rb | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/app/uploaders/uploader_helper.rb b/app/uploaders/uploader_helper.rb index 6d510fe7dde..703f7820913 100644 --- a/app/uploaders/uploader_helper.rb +++ b/app/uploaders/uploader_helper.rb @@ -1,18 +1,19 @@ # Extra methods for uploader module UploaderHelper - IMAGE_EXT = %w(png jpg jpeg gif bmp tiff) - VIDEO_EXT = %w(mov mp4 ogg webm flv) + IMAGE_EXT = %w[png jpg jpeg gif bmp tiff] + # 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 + VIDEO_EXT = %w[mp4 m4v mov webm ogv] def image? extension_match?(IMAGE_EXT) - rescue - false end def video? extension_match?(VIDEO_EXT) - rescue - false end def image_or_video? @@ -20,13 +21,15 @@ module UploaderHelper end def extension_match?(extensions) - if file.respond_to?(:extension) - extensions.include?(file.extension.downcase) - else - # Not all CarrierWave storages respond to :extension - ext = file.path.split('.').last.downcase - extensions.include?(ext) - end + 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) end def file_storage? |