about summary refs log tree commit diff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/assets/stylesheets/api/media.scss3
-rw-r--r--app/controllers/api/media_controller.rb8
-rw-r--r--app/helpers/api/media_helper.rb2
-rw-r--r--app/models/account.rb2
-rw-r--r--app/models/media_attachment.rb13
-rw-r--r--app/models/status.rb1
-rw-r--r--app/views/api/media/create.rabl3
7 files changed, 32 insertions, 0 deletions
diff --git a/app/assets/stylesheets/api/media.scss b/app/assets/stylesheets/api/media.scss
new file mode 100644
index 000000000..e3c4fac3c
--- /dev/null
+++ b/app/assets/stylesheets/api/media.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the Api::Media controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
diff --git a/app/controllers/api/media_controller.rb b/app/controllers/api/media_controller.rb
new file mode 100644
index 000000000..d5a0a124a
--- /dev/null
+++ b/app/controllers/api/media_controller.rb
@@ -0,0 +1,8 @@
+class Api::MediaController < ApiController
+  before_action :doorkeeper_authorize!
+  respond_to    :json
+
+  def create
+    @media = MediaAttachment.create!(account: current_user.account, file: params[:file])
+  end
+end
diff --git a/app/helpers/api/media_helper.rb b/app/helpers/api/media_helper.rb
new file mode 100644
index 000000000..ecaa91e7b
--- /dev/null
+++ b/app/helpers/api/media_helper.rb
@@ -0,0 +1,2 @@
+module Api::MediaHelper
+end
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?'
diff --git a/app/views/api/media/create.rabl b/app/views/api/media/create.rabl
new file mode 100644
index 000000000..23909066d
--- /dev/null
+++ b/app/views/api/media/create.rabl
@@ -0,0 +1,3 @@
+object @media
+attribute :id
+node(:url) { |media| full_asset_url(media.file.url) }