diff options
author | Eugen Rochko <eugen@zeonfederated.com> | 2016-09-05 17:46:36 +0200 |
---|---|---|
committer | Eugen Rochko <eugen@zeonfederated.com> | 2016-09-05 17:46:36 +0200 |
commit | ae1fac006206ab28cd7cba63ab85c07a27f3d606 (patch) | |
tree | 61f9cd45d7ed804eab85ae6a28cee584af90bfe3 /app/models | |
parent | 05001d54d15c486caa6cebe9462222d37d87576d (diff) |
Add API to upload media attachments
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/account.rb | 2 | ||||
-rw-r--r-- | app/models/media_attachment.rb | 13 | ||||
-rw-r--r-- | app/models/status.rb | 1 |
3 files changed, 16 insertions, 0 deletions
diff --git a/app/models/account.rb b/app/models/account.rb index bcd6c1eba..8e0283ca1 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -31,6 +31,8 @@ class Account < ApplicationRecord has_many :following, through: :active_relationships, source: :target_account has_many :followers, through: :passive_relationships, source: :account + has_many :media_attachments, dependent: :destroy + MENTION_RE = /(?:^|\s|\.)@([a-z0-9_]+(?:@[a-z0-9\.\-]+)?)/i def follow!(other_account) diff --git a/app/models/media_attachment.rb b/app/models/media_attachment.rb new file mode 100644 index 000000000..af1a4b9af --- /dev/null +++ b/app/models/media_attachment.rb @@ -0,0 +1,13 @@ +class MediaAttachment < ApplicationRecord + belongs_to :account, inverse_of: :media_attachments + belongs_to :status, inverse_of: :media_attachments + + has_attached_file :file + validates_attachment_content_type :file, content_type: /\Aimage\/.*\z/ + + validates :account, presence: true + + def local? + self.remote_url.blank? + end +end diff --git a/app/models/status.rb b/app/models/status.rb index 14a698aae..05ae1a06e 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -11,6 +11,7 @@ class Status < ApplicationRecord has_many :reblogs, foreign_key: 'reblog_of_id', class_name: 'Status', inverse_of: :reblog, dependent: :destroy has_many :replies, foreign_key: 'in_reply_to_id', class_name: 'Status', inverse_of: :thread has_many :mentions, dependent: :destroy + has_many :media_attachments, dependent: :destroy validates :account, presence: true validates :uri, uniqueness: true, unless: 'local?' |