2017-03-22 13:26:22 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class StatusesController < ApplicationController
|
2019-07-08 05:03:45 -05:00
|
|
|
include StatusControllerConcern
|
2018-02-02 03:19:59 -06:00
|
|
|
include SignatureAuthentication
|
2017-05-29 11:22:22 -05:00
|
|
|
include Authorization
|
2019-07-08 05:03:45 -05:00
|
|
|
include AccountOwnedConcern
|
2018-04-11 05:35:09 -05:00
|
|
|
|
2017-03-22 13:26:22 -05:00
|
|
|
layout 'public'
|
|
|
|
|
2019-07-11 13:11:09 -05:00
|
|
|
before_action :require_signature!, only: :show, if: -> { request.format == :json && authorized_fetch_mode? }
|
2017-03-22 13:26:22 -05:00
|
|
|
before_action :set_status
|
2018-07-28 12:25:33 -05:00
|
|
|
before_action :set_instance_presenter
|
2017-03-22 13:26:22 -05:00
|
|
|
before_action :set_link_headers
|
2019-07-11 13:11:09 -05:00
|
|
|
before_action :redirect_to_original, only: :show
|
|
|
|
before_action :set_referrer_policy_header, only: :show
|
2018-01-03 18:21:38 -06:00
|
|
|
before_action :set_cache_headers
|
2019-07-08 05:03:45 -05:00
|
|
|
before_action :set_body_classes
|
|
|
|
before_action :set_autoplay, only: :embed
|
2017-03-22 13:26:22 -05:00
|
|
|
|
2019-08-11 15:59:40 -05:00
|
|
|
skip_around_action :set_locale, if: -> { request.format == :json }
|
2019-09-27 18:33:27 -05:00
|
|
|
skip_before_action :require_functional!, only: [:show, :embed]
|
2019-08-11 15:59:40 -05:00
|
|
|
|
2018-08-22 10:37:51 -05:00
|
|
|
content_security_policy only: :embed do |p|
|
|
|
|
p.frame_ancestors(false)
|
|
|
|
end
|
|
|
|
|
2017-03-22 13:26:22 -05:00
|
|
|
def show
|
2017-07-14 20:01:39 -05:00
|
|
|
respond_to do |format|
|
|
|
|
format.html do
|
2017-11-21 00:13:37 -06:00
|
|
|
use_pack 'public'
|
2019-05-10 10:09:12 -05:00
|
|
|
|
2019-06-05 07:02:59 -05:00
|
|
|
expires_in 10.seconds, public: true if current_account.nil?
|
2018-04-23 12:27:35 -05:00
|
|
|
set_ancestors
|
|
|
|
set_descendants
|
2017-07-14 20:01:39 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
format.json do
|
2019-07-11 13:11:09 -05:00
|
|
|
expires_in 3.minutes, public: @status.distributable? && public_fetch_mode?
|
2019-07-21 15:32:16 -05:00
|
|
|
render_with_cache json: @status, content_type: 'application/activity+json', serializer: ActivityPub::NoteSerializer, adapter: ActivityPub::Adapter
|
2017-07-14 20:01:39 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-03-22 13:26:22 -05:00
|
|
|
|
2017-07-14 20:01:39 -05:00
|
|
|
def activity
|
2019-07-11 13:11:09 -05:00
|
|
|
expires_in 3.minutes, public: @status.distributable? && public_fetch_mode?
|
2019-07-21 15:32:16 -05:00
|
|
|
render_with_cache json: @status, content_type: 'application/activity+json', serializer: ActivityPub::ActivitySerializer, adapter: ActivityPub::Adapter
|
2017-03-22 13:26:22 -05:00
|
|
|
end
|
|
|
|
|
2017-08-30 03:23:43 -05:00
|
|
|
def embed
|
2017-11-21 00:13:37 -06:00
|
|
|
use_pack 'embed'
|
2018-06-30 21:12:34 -05:00
|
|
|
raise ActiveRecord::RecordNotFound if @status.hidden?
|
|
|
|
|
|
|
|
expires_in 180, public: true
|
2017-08-30 03:23:43 -05:00
|
|
|
response.headers['X-Frame-Options'] = 'ALLOWALL'
|
|
|
|
|
2019-07-07 09:16:51 -05:00
|
|
|
render layout: 'embedded'
|
2019-02-28 11:16:34 -06:00
|
|
|
end
|
|
|
|
|
2017-03-22 13:26:22 -05:00
|
|
|
private
|
|
|
|
|
2019-07-08 05:03:45 -05:00
|
|
|
def set_body_classes
|
|
|
|
@body_classes = 'with-modals'
|
2018-04-23 12:27:35 -05:00
|
|
|
end
|
|
|
|
|
2017-03-22 13:26:22 -05:00
|
|
|
def set_link_headers
|
2019-07-07 09:16:51 -05:00
|
|
|
response.headers['Link'] = LinkHeader.new([[ActivityPub::TagManager.instance.uri_for(@status), [%w(rel alternate), %w(type application/activity+json)]]])
|
2017-03-22 13:26:22 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def set_status
|
2019-07-07 09:16:51 -05:00
|
|
|
@status = @account.statuses.find(params[:id])
|
2017-05-29 11:22:22 -05:00
|
|
|
authorize @status, :show?
|
|
|
|
rescue Mastodon::NotPermittedError
|
|
|
|
raise ActiveRecord::RecordNotFound
|
2017-03-22 13:26:22 -05:00
|
|
|
end
|
|
|
|
|
2018-07-28 12:25:33 -05:00
|
|
|
def set_instance_presenter
|
|
|
|
@instance_presenter = InstancePresenter.new
|
|
|
|
end
|
|
|
|
|
2017-08-24 09:21:42 -05:00
|
|
|
def redirect_to_original
|
2019-07-07 09:16:51 -05:00
|
|
|
redirect_to ActivityPub::TagManager.instance.url_for(@status.reblog) if @status.reblog?
|
2017-08-24 09:21:42 -05:00
|
|
|
end
|
2018-04-17 06:51:01 -05:00
|
|
|
|
|
|
|
def set_referrer_policy_header
|
2019-07-08 05:03:45 -05:00
|
|
|
response.headers['Referrer-Policy'] = 'origin' unless @status.distributable?
|
2019-02-28 11:16:34 -06:00
|
|
|
end
|
|
|
|
|
2019-07-08 05:03:45 -05:00
|
|
|
def set_autoplay
|
|
|
|
@autoplay = truthy_param?(:autoplay)
|
2019-02-28 11:16:34 -06:00
|
|
|
end
|
2017-03-22 13:26:22 -05:00
|
|
|
end
|