diff options
author | Eugen Rochko <eugen@zeonfederated.com> | 2016-09-12 18:22:43 +0200 |
---|---|---|
committer | Eugen Rochko <eugen@zeonfederated.com> | 2016-09-12 18:22:43 +0200 |
commit | ce29624c6df83699a01808d68c19a2492864ffe8 (patch) | |
tree | 822f151d24ab6c04f20b0926f6290621c476e032 /app/models | |
parent | 3d566279cb84aba6d07eaadebda6c059f2a58657 (diff) |
Fixing image upload limits, allowing webm, merge/unmerge events trigger
timeline reload in UI, other small fixes
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/account.rb | 9 | ||||
-rw-r--r-- | app/models/media_attachment.rb | 15 |
2 files changed, 18 insertions, 6 deletions
diff --git a/app/models/account.rb b/app/models/account.rb index 1767f72e2..6e96defe4 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -1,6 +1,9 @@ class Account < ApplicationRecord include Targetable + MENTION_RE = /(?:^|\s|\.|>)@([a-z0-9_]+(?:@[a-z0-9\.\-]+)?)/i + IMAGE_MIME_TYPES = ['image/jpeg', 'image/png', 'image/gif'] + # Local users has_one :user, inverse_of: :account validates :username, presence: true, format: { with: /\A[a-z0-9_]+\z/i, message: 'only letters, numbers and underscores' }, uniqueness: { scope: :domain, case_sensitive: false }, if: 'local?' @@ -8,12 +11,12 @@ class Account < ApplicationRecord # Avatar upload has_attached_file :avatar, styles: { large: '300x300#', medium: '96x96#', small: '48x48#' } - validates_attachment_content_type :avatar, content_type: /\Aimage\/.*\Z/ + validates_attachment_content_type :avatar, content_type: IMAGE_MIME_TYPES validates_attachment_size :avatar, less_than: 2.megabytes # Header upload has_attached_file :header, styles: { medium: '700x335#' } - validates_attachment_content_type :header, content_type: /\Aimage\/.*\Z/ + validates_attachment_content_type :header, content_type: IMAGE_MIME_TYPES validates_attachment_size :header, less_than: 2.megabytes # Local user profile validations @@ -35,8 +38,6 @@ class Account < ApplicationRecord has_many :media_attachments, dependent: :destroy - MENTION_RE = /(?:^|\s|\.|>)@([a-z0-9_]+(?:@[a-z0-9\.\-]+)?)/i - def follow!(other_account) self.active_relationships.where(target_account: other_account).first_or_create!(target_account: other_account) end diff --git a/app/models/media_attachment.rb b/app/models/media_attachment.rb index 0f631af57..7dddfd610 100644 --- a/app/models/media_attachment.rb +++ b/app/models/media_attachment.rb @@ -1,9 +1,12 @@ class MediaAttachment < ApplicationRecord + IMAGE_MIME_TYPES = ['image/jpeg', 'image/png', 'image/gif'] + VIDEO_MIME_TYPES = ['video/webm'] + belongs_to :account, inverse_of: :media_attachments belongs_to :status, inverse_of: :media_attachments - has_attached_file :file, styles: { small: '510x680>' } - validates_attachment_content_type :file, content_type: /\Aimage\/.*\z/ + has_attached_file :file, styles: lambda { |f| f.instance.image? ? { small: '510x680>' } : { small: { format: 'webm' } } }, processors: lambda { |f| f.video? ? [:transcoder] : [:thumbnail] } + validates_attachment_content_type :file, content_type: IMAGE_MIME_TYPES + VIDEO_MIME_TYPES validates_attachment_size :file, less_than: 4.megabytes validates :account, presence: true @@ -15,4 +18,12 @@ class MediaAttachment < ApplicationRecord def file_remote_url=(url) self.file = URI.parse(url) end + + def image? + IMAGE_MIME_TYPES.include? file_content_type + end + + def video? + VIDEO_MIME_TYPES.include? file_content_type + end end |