闭社主体 forked from https://github.com/tootsuite/mastodon
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.

53 lines
1.3 KiB

  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, with: :not_found
  9. rescue_from ActionController::ParameterMissing, WebfingerResource::InvalidRequest, with: :bad_request
  10. def show
  11. expires_in 3.days, public: true
  12. render json: @account, serializer: WebfingerSerializer, content_type: 'application/jrd+json'
  13. end
  14. private
  15. def set_account
  16. @account = Account.find_local!(username_from_resource)
  17. end
  18. def username_from_resource
  19. resource_user = resource_param
  20. username, domain = resource_user.split('@')
  21. resource_user = "#{username}@#{Rails.configuration.x.local_domain}" if Rails.configuration.x.alternate_domains.include?(domain)
  22. WebfingerResource.new(resource_user).username
  23. end
  24. def resource_param
  25. params.require(:resource)
  26. end
  27. def check_account_suspension
  28. expires_in(3.minutes, public: true) && gone if @account.suspended?
  29. end
  30. def bad_request
  31. head 400
  32. end
  33. def not_found
  34. head 404
  35. end
  36. def gone
  37. head 410
  38. end
  39. end
  40. end