The code powering m.abunchtell.com https://m.abunchtell.com
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.
 
 
 
 

87 lines
2.4 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. content_security_policy only: :embed do |p|
  18. p.frame_ancestors(false)
  19. end
  20. def show
  21. respond_to do |format|
  22. format.html do
  23. expires_in 10.seconds, public: true if current_account.nil?
  24. set_ancestors
  25. set_descendants
  26. end
  27. format.json do
  28. expires_in 3.minutes, public: @status.distributable? && public_fetch_mode?
  29. render_with_cache json: @status, content_type: 'application/activity+json', serializer: ActivityPub::NoteSerializer, adapter: ActivityPub::Adapter
  30. end
  31. end
  32. end
  33. def activity
  34. expires_in 3.minutes, public: @status.distributable? && public_fetch_mode?
  35. render_with_cache json: @status, content_type: 'application/activity+json', serializer: ActivityPub::ActivitySerializer, adapter: ActivityPub::Adapter
  36. end
  37. def embed
  38. raise ActiveRecord::RecordNotFound if @status.hidden?
  39. expires_in 180, public: true
  40. response.headers['X-Frame-Options'] = 'ALLOWALL'
  41. render layout: 'embedded'
  42. end
  43. private
  44. def set_body_classes
  45. @body_classes = 'with-modals'
  46. end
  47. def set_link_headers
  48. response.headers['Link'] = LinkHeader.new([[ActivityPub::TagManager.instance.uri_for(@status), [%w(rel alternate), %w(type application/activity+json)]]])
  49. end
  50. def set_status
  51. @status = @account.statuses.find(params[:id])
  52. authorize @status, :show?
  53. rescue Mastodon::NotPermittedError
  54. raise ActiveRecord::RecordNotFound
  55. end
  56. def set_instance_presenter
  57. @instance_presenter = InstancePresenter.new
  58. end
  59. def redirect_to_original
  60. redirect_to ActivityPub::TagManager.instance.url_for(@status.reblog) if @status.reblog?
  61. end
  62. def set_referrer_policy_header
  63. response.headers['Referrer-Policy'] = 'origin' unless @status.distributable?
  64. end
  65. def set_autoplay
  66. @autoplay = truthy_param?(:autoplay)
  67. end
  68. end