From bfbc2ca0d8dcef47f8581585b42f13b6b4c933d9 Mon Sep 17 00:00:00 2001 From: Eugen Date: Wed, 19 Apr 2017 15:37:18 +0200 Subject: Attachment list for uncached attachments (#2110) * For undownloaded attachments, set type :unknown, display them as a list in the web UI * Fix case when attachment type is set explicitly --- app/models/media_attachment.rb | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'app/models') diff --git a/app/models/media_attachment.rb b/app/models/media_attachment.rb index ec1808790..bb16adb5b 100644 --- a/app/models/media_attachment.rb +++ b/app/models/media_attachment.rb @@ -3,7 +3,7 @@ class MediaAttachment < ApplicationRecord self.inheritance_column = nil - enum type: [:image, :gifv, :video] + enum type: [:image, :gifv, :video, :unknown] IMAGE_MIME_TYPES = ['image/jpeg', 'image/png', 'image/gif'].freeze VIDEO_MIME_TYPES = ['video/webm', 'video/mp4'].freeze @@ -95,6 +95,8 @@ class MediaAttachment < ApplicationRecord private def set_shortcode + self.type = :unknown if file.blank? && type.blank? + return unless local? loop do @@ -104,9 +106,10 @@ class MediaAttachment < ApplicationRecord end def set_type_and_extension - self.type = VIDEO_MIME_TYPES.include?(file_content_type) ? :video : :image - - unless file.blank? + if file.blank? + self.type = :unknown + else + self.type = VIDEO_MIME_TYPES.include?(file_content_type) ? :video : :image extension = Paperclip::Interpolations.content_type_extension(file, :original) basename = Paperclip::Interpolations.basename(file, :original) file.instance_write :file_name, [basename, extension].delete_if(&:empty?).join('.') -- cgit