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.

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