diff options
author | kibigo! <marrus-sh@users.noreply.github.com> | 2017-10-11 10:43:10 -0700 |
---|---|---|
committer | kibigo! <marrus-sh@users.noreply.github.com> | 2017-10-11 10:43:10 -0700 |
commit | 8d6b9ba4946b5b159af0fbd130637a226a286796 (patch) | |
tree | 9def26711682d29338cfa1b081822029a01669eb /app/models/media_attachment.rb | |
parent | f0a2a6c875e9294f0ea1d4c6bc90529e41a2dc37 (diff) | |
parent | 476e79b8e340c9103352a0799e102e4aca1a5593 (diff) |
Merge upstream 2.0ish #165
Diffstat (limited to 'app/models/media_attachment.rb')
-rw-r--r-- | app/models/media_attachment.rb | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/app/models/media_attachment.rb b/app/models/media_attachment.rb index 65ff893a8..f6c8879c5 100644 --- a/app/models/media_attachment.rb +++ b/app/models/media_attachment.rb @@ -16,6 +16,7 @@ # shortcode :string # type :integer default("image"), not null # file_meta :json +# description :text # require 'mime/types' @@ -75,6 +76,7 @@ class MediaAttachment < ApplicationRecord validates_attachment_size :file, less_than: 8.megabytes validates :account, presence: true + validates :description, length: { maximum: 420 }, if: :local? scope :attached, -> { where.not(status_id: nil) } scope :unattached, -> { where(status_id: nil) } @@ -95,6 +97,7 @@ class MediaAttachment < ApplicationRecord shortcode end + before_create :prepare_description, unless: :local? before_create :set_shortcode before_post_process :set_type_and_extension before_save :set_meta @@ -157,6 +160,10 @@ class MediaAttachment < ApplicationRecord end end + def prepare_description + self.description = description.strip[0...420] unless description.nil? + end + def set_type_and_extension self.type = VIDEO_MIME_TYPES.include?(file_content_type) ? :video : AUDIO_MIME_TYPES.include?(file_content_type) ? :audio : :image extension = AUDIO_MIME_TYPES.include?(file_content_type) ? '.mp4' : appropriate_extension |