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.

65 lines
1.8 KiB

  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. redirect_to short_account_status_url(params[:account_username], @stream_entry.activity) if @type == 'status'
  15. end
  16. format.atom do
  17. unless @stream_entry.hidden?
  18. skip_session!
  19. expires_in 3.minutes, public: true
  20. end
  21. render xml: OStatus::AtomSerializer.render(OStatus::AtomSerializer.new.entry(@stream_entry, true))
  22. end
  23. end
  24. end
  25. def embed
  26. redirect_to embed_short_account_status_url(@account, @stream_entry.activity), status: 301
  27. end
  28. private
  29. def set_account
  30. @account = Account.find_local!(params[:account_username])
  31. end
  32. def set_link_headers
  33. response.headers['Link'] = LinkHeader.new(
  34. [
  35. [account_stream_entry_url(@account, @stream_entry, format: 'atom'), [%w(rel alternate), %w(type application/atom+xml)]],
  36. [ActivityPub::TagManager.instance.uri_for(@stream_entry.activity), [%w(rel alternate), %w(type application/activity+json)]],
  37. ]
  38. )
  39. end
  40. def set_stream_entry
  41. @stream_entry = @account.stream_entries.where(activity_type: 'Status').find(params[:id])
  42. @type = @stream_entry.activity_type.downcase
  43. raise ActiveRecord::RecordNotFound if @stream_entry.activity.nil?
  44. authorize @stream_entry.activity, :show? if @stream_entry.hidden?
  45. rescue Mastodon::NotPermittedError
  46. # Reraise in order to get a 404
  47. raise ActiveRecord::RecordNotFound
  48. end
  49. def check_account_suspension
  50. gone if @account.suspended?
  51. end
  52. end