summaryrefslogtreecommitdiffstats
path: root/app/services/resolve_url_service.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/services/resolve_url_service.rb')
-rw-r--r--app/services/resolve_url_service.rb47
1 files changed, 16 insertions, 31 deletions
diff --git a/app/services/resolve_url_service.rb b/app/services/resolve_url_service.rb
index f941b489a5a..80381c16b6f 100644
--- a/app/services/resolve_url_service.rb
+++ b/app/services/resolve_url_service.rb
@@ -4,64 +4,49 @@ class ResolveURLService < BaseService
include JsonLdHelper
include Authorization
- attr_reader :url
-
def call(url, on_behalf_of: nil)
- @url = url
+ @url = url
@on_behalf_of = on_behalf_of
- return process_local_url if local_url?
-
- process_url unless fetched_atom_feed.nil?
+ if local_url?
+ process_local_url
+ elsif !fetched_resource.nil?
+ process_url
+ end
end
private
def process_url
if equals_or_includes_any?(type, ActivityPub::FetchRemoteAccountService::SUPPORTED_TYPES)
- FetchRemoteAccountService.new.call(atom_url, body, protocol)
+ FetchRemoteAccountService.new.call(resource_url, body, protocol)
elsif equals_or_includes_any?(type, ActivityPub::Activity::Create::SUPPORTED_TYPES + ActivityPub::Activity::Create::CONVERTED_TYPES)
- FetchRemoteStatusService.new.call(atom_url, body, protocol)
+ FetchRemoteStatusService.new.call(resource_url, body, protocol)
end
end
- def fetched_atom_feed
- @_fetched_atom_feed ||= FetchAtomService.new.call(url)
+ def fetched_resource
+ @fetched_resource ||= FetchResourceService.new.call(@url)
end
- def atom_url
- fetched_atom_feed.first
+ def resource_url
+ fetched_resource.first
end
def body
- fetched_atom_feed.second[:prefetched_body]
+ fetched_resource.second[:prefetched_body]
end
def protocol
- fetched_atom_feed.third
+ fetched_resource.third
end
def type
return json_data['type'] if protocol == :activitypub
-
- case xml_root
- when 'feed'
- 'Person'
- when 'entry'
- 'Note'
- end
end
def json_data
- @_json_data ||= body_to_json(body)
- end
-
- def xml_root
- xml_data.root.name
- end
-
- def xml_data
- @_xml_data ||= Nokogiri::XML(body, nil, 'utf-8')
+ @json_data ||= body_to_json(body)
end
def local_url?
@@ -83,10 +68,10 @@ class ResolveURLService < BaseService
def check_local_status(status)
return if status.nil?
+
authorize_with @on_behalf_of, status, :show?
status
rescue Mastodon::NotPermittedError
- # Do not disclose the existence of status the user is not authorized to see
nil
end
end