Add API to upload media attachments
This commit is contained in:
@@ -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)
|
||||
|
13
app/models/media_attachment.rb
Normal file
13
app/models/media_attachment.rb
Normal file
@@ -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
|
@@ -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?'
|
||||
|
Reference in New Issue
Block a user