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.

54 lines
1.3 KiB

  1. # frozen_string_literal: true
  2. module WellKnown
  3. class WebfingerController < ActionController::Base
  4. include RoutingHelper
  5. before_action :set_account
  6. before_action :check_account_suspension
  7. rescue_from ActiveRecord::RecordNotFound, with: :not_found
  8. rescue_from ActionController::ParameterMissing, WebfingerResource::InvalidRequest, with: :bad_request
  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_permanently?
  28. end
  29. def bad_request
  30. expires_in(3.minutes, public: true)
  31. head 400
  32. end
  33. def not_found
  34. expires_in(3.minutes, public: true)
  35. head 404
  36. end
  37. def gone
  38. head 410
  39. end
  40. end
  41. end