diff options
author | Eric Hayes <eric@erichayes.net> | 2016-04-02 22:00:06 -0700 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2016-07-19 18:51:09 +0200 |
commit | c266c7fa18848586cd6ee903cc4c4d4f9049100e (patch) | |
tree | 8fa8d0b2dca828bec6af0ad49855cbb4e69a9e30 /app/uploaders | |
parent | 81e57e783e8882de21d27d9191c09404ed7faca3 (diff) | |
download | gitlab-ce-c266c7fa18848586cd6ee903cc4c4d4f9049100e.tar.gz |
First support of videos in issues, MRs and notes
* Registered video MIME types
* Currently supporting browser-supported formats with extensions that match the mime type
Diffstat (limited to 'app/uploaders')
-rw-r--r-- | app/uploaders/file_uploader.rb | 6 | ||||
-rw-r--r-- | app/uploaders/uploader_helper.rb | 26 |
2 files changed, 24 insertions, 8 deletions
diff --git a/app/uploaders/file_uploader.rb b/app/uploaders/file_uploader.rb index 1af9e9b0edb..80284fa294a 100644 --- a/app/uploaders/file_uploader.rb +++ b/app/uploaders/file_uploader.rb @@ -33,16 +33,16 @@ class FileUploader < CarrierWave::Uploader::Base end def to_h - filename = image? ? self.file.basename : self.file.filename + filename = image_or_video? ? self.file.basename : self.file.filename escaped_filename = filename.gsub("]", "\\]") markdown = "[#{escaped_filename}](#{self.secure_url})" - markdown.prepend("!") if image? + markdown.prepend("!") if image_or_video? { alt: filename, url: self.secure_url, - is_image: image?, + is_image: image_or_video?, markdown: markdown } end diff --git a/app/uploaders/uploader_helper.rb b/app/uploaders/uploader_helper.rb index 5ef440f3367..6d510fe7dde 100644 --- a/app/uploaders/uploader_helper.rb +++ b/app/uploaders/uploader_helper.rb @@ -1,16 +1,32 @@ # Extra methods for uploader module UploaderHelper + IMAGE_EXT = %w(png jpg jpeg gif bmp tiff) + VIDEO_EXT = %w(mov mp4 ogg webm flv) + def image? - img_ext = %w(png jpg jpeg gif bmp tiff) + extension_match?(IMAGE_EXT) + rescue + false + end + + def video? + extension_match?(VIDEO_EXT) + rescue + false + end + + def image_or_video? + image? || video? + end + + def extension_match?(extensions) if file.respond_to?(:extension) - img_ext.include?(file.extension.downcase) + extensions.include?(file.extension.downcase) else # Not all CarrierWave storages respond to :extension ext = file.path.split('.').last.downcase - img_ext.include?(ext) + extensions.include?(ext) end - rescue - false end def file_storage? |