The code powering m.abunchtell.com https://m.abunchtell.com
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 

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