stream_entries_controller.rb 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. # frozen_string_literal: true
  2. class StreamEntriesController < ApplicationController
  3. include Authorization
  4. include SignatureVerification
  5. layout 'public'
  6. before_action :set_account
  7. before_action :set_stream_entry
  8. before_action :set_link_headers
  9. before_action :check_account_suspension
  10. before_action :set_cache_headers
  11. def show
  12. respond_to do |format|
  13. format.html do
  14. expires_in 5.minutes, public: true unless @stream_entry.hidden?
  15. redirect_to short_account_status_url(params[:account_username], @stream_entry.activity)
  16. end
  17. format.atom do
  18. expires_in 3.minutes, public: true unless @stream_entry.hidden?
  19. render xml: OStatus::AtomSerializer.render(OStatus::AtomSerializer.new.entry(@stream_entry, true))
  20. end
  21. end
  22. end
  23. def embed
  24. redirect_to embed_short_account_status_url(@account, @stream_entry.activity), status: 301
  25. end
  26. private
  27. def set_account
  28. @account = Account.find_local!(params[:account_username])
  29. end
  30. def set_link_headers
  31. response.headers['Link'] = LinkHeader.new(
  32. [
  33. [account_stream_entry_url(@account, @stream_entry, format: 'atom'), [%w(rel alternate), %w(type application/atom+xml)]],
  34. [ActivityPub::TagManager.instance.uri_for(@stream_entry.activity), [%w(rel alternate), %w(type application/activity+json)]],
  35. ]
  36. )
  37. end
  38. def set_stream_entry
  39. @stream_entry = @account.stream_entries.where(activity_type: 'Status').find(params[:id])
  40. @type = 'status'
  41. raise ActiveRecord::RecordNotFound if @stream_entry.activity.nil?
  42. authorize @stream_entry.activity, :show? if @stream_entry.hidden?
  43. rescue Mastodon::NotPermittedError
  44. # Reraise in order to get a 404
  45. raise ActiveRecord::RecordNotFound
  46. end
  47. def check_account_suspension
  48. gone if @account.suspended?
  49. end
  50. end