webfinger_controller.rb 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # frozen_string_literal: true
  2. module WellKnown
  3. class WebfingerController < ActionController::Base
  4. include RoutingHelper
  5. before_action { response.headers['Vary'] = 'Accept' }
  6. before_action :set_account
  7. before_action :check_account_suspension
  8. rescue_from ActiveRecord::RecordNotFound, ActionController::ParameterMissing, with: :not_found
  9. def show
  10. expires_in 3.days, public: true
  11. render json: @account, serializer: WebfingerSerializer, content_type: 'application/jrd+json'
  12. end
  13. private
  14. def set_account
  15. @account = Account.find_local!(username_from_resource)
  16. end
  17. def username_from_resource
  18. resource_user = resource_param
  19. username, domain = resource_user.split('@')
  20. resource_user = "#{username}@#{Rails.configuration.x.local_domain}" if Rails.configuration.x.alternate_domains.include?(domain)
  21. WebfingerResource.new(resource_user).username
  22. end
  23. def resource_param
  24. params.require(:resource)
  25. end
  26. def check_account_suspension
  27. expires_in(3.minutes, public: true) && gone if @account.suspended?
  28. end
  29. def not_found
  30. head 404
  31. end
  32. def gone
  33. head 410
  34. end
  35. end
  36. end