You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 lines
2.6 KiB

  1. # frozen_string_literal: true
  2. class StatusesController < ApplicationController
  3. include StatusControllerConcern
  4. include SignatureAuthentication
  5. include Authorization
  6. include AccountOwnedConcern
  7. layout 'public'
  8. before_action :require_signature!, only: :show, if: -> { request.format == :json && authorized_fetch_mode? }
  9. before_action :set_status
  10. before_action :set_instance_presenter
  11. before_action :set_link_headers
  12. before_action :redirect_to_original, only: :show
  13. before_action :set_referrer_policy_header, only: :show
  14. before_action :set_cache_headers
  15. before_action :set_body_classes
  16. before_action :set_autoplay, only: :embed
  17. skip_around_action :set_locale, if: -> { request.format == :json }
  18. skip_before_action :require_functional!, only: [:show, :embed], unless: :whitelist_mode?
  19. content_security_policy only: :embed do |p|
  20. p.frame_ancestors(false)
  21. end
  22. def show
  23. respond_to do |format|
  24. format.html do
  25. expires_in 10.seconds, public: true if current_account.nil?
  26. set_ancestors
  27. set_descendants
  28. end
  29. format.json do
  30. expires_in 3.minutes, public: @status.distributable? && public_fetch_mode?
  31. render_with_cache json: @status, content_type: 'application/activity+json', serializer: ActivityPub::NoteSerializer, adapter: ActivityPub::Adapter
  32. end
  33. end
  34. end
  35. def activity
  36. expires_in 3.minutes, public: @status.distributable? && public_fetch_mode?
  37. render_with_cache json: ActivityPub::ActivityPresenter.from_status(@status), content_type: 'application/activity+json', serializer: ActivityPub::ActivitySerializer, adapter: ActivityPub::Adapter
  38. end
  39. def embed
  40. return not_found if @status.hidden? || @status.reblog?
  41. expires_in 180, public: true
  42. response.headers['X-Frame-Options'] = 'ALLOWALL'
  43. render layout: 'embedded'
  44. end
  45. private
  46. def set_body_classes
  47. @body_classes = 'with-modals'
  48. end
  49. def set_link_headers
  50. response.headers['Link'] = LinkHeader.new([[ActivityPub::TagManager.instance.uri_for(@status), [%w(rel alternate), %w(type application/activity+json)]]])
  51. end
  52. def set_status
  53. @status = @account.statuses.find(params[:id])
  54. authorize @status, :show?
  55. rescue Mastodon::NotPermittedError
  56. not_found
  57. end
  58. def set_instance_presenter
  59. @instance_presenter = InstancePresenter.new
  60. end
  61. def redirect_to_original
  62. redirect_to ActivityPub::TagManager.instance.url_for(@status.reblog) if @status.reblog?
  63. end
  64. def set_referrer_policy_header
  65. response.headers['Referrer-Policy'] = 'origin' unless @status.distributable?
  66. end
  67. def set_autoplay
  68. @autoplay = truthy_param?(:autoplay)
  69. end
  70. end