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.

40 lines
963 B

  1. # frozen_string_literal: true
  2. module WellKnown
  3. class WebfingerController < ApplicationController
  4. include RoutingHelper
  5. def show
  6. @account = Account.find_local!(username_from_resource)
  7. respond_to do |format|
  8. format.any(:json, :html) do
  9. render json: @account, serializer: WebfingerSerializer, content_type: 'application/jrd+json'
  10. end
  11. format.xml do
  12. render content_type: 'application/xrd+xml'
  13. end
  14. end
  15. rescue ActiveRecord::RecordNotFound
  16. head 404
  17. end
  18. private
  19. def username_from_resource
  20. resource_user = resource_param
  21. username, domain = resource_user.split('@')
  22. if Rails.configuration.x.alternate_domains.include?(domain)
  23. resource_user = "#{username}@#{Rails.configuration.x.local_domain}"
  24. end
  25. WebfingerResource.new(resource_user).username
  26. end
  27. def resource_param
  28. params.require(:resource)
  29. end
  30. end
  31. end