1
0
mirror of https://github.com/mastodon/mastodon synced 2024-11-25 15:46:24 +09:00
mastodon/app/lib/webfinger_resource.rb
ThibG 89dc29affb Allow webfinger controller to reply to user@WEB_DOMAIN in addition to user@LOCAL_DOMAIN (#2351)
This provides a hotfix for outbound salmon requests to other Mastodon instances
as they currently will try to resovle user@WEB_DOMAIN instead of user@LOCAL_DOMAIN
(see #2012 and #20312).

Furthermore, this should ease transition from users switching from
LOCAL_DOMAIN = WEB_DOMAIN to another LOCAL_DOMAIN when WEB_DOMAIN does not change.
2017-04-23 14:19:54 +02:00

67 lines
1.2 KiB
Ruby

# frozen_string_literal: true
class WebfingerResource
attr_reader :resource
def initialize(resource)
@resource = resource
end
def username
case resource
when /\Ahttps?/i
username_from_url
when /\@/
username_from_acct
else
raise(ActiveRecord::RecordNotFound)
end
end
private
def username_from_url
if account_show_page?
path_params[:username]
else
raise ActiveRecord::RecordNotFound
end
end
def account_show_page?
path_params[:controller] == 'accounts' && path_params[:action] == 'show'
end
def path_params
Rails.application.routes.recognize_path(resource)
end
def username_from_acct
if domain_matches_local?
local_username
else
raise ActiveRecord::RecordNotFound
end
end
def split_acct
resource_without_acct_string.split('@')
end
def resource_without_acct_string
resource.gsub(/\Aacct:/, '')
end
def local_username
split_acct.first
end
def local_domain
split_acct.last
end
def domain_matches_local?
TagManager.instance.local_domain?(local_domain) || TagManager.instance.web_domain?(local_domain)
end
end