logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

fetch_remote_account_service.rb (1107B)


  1. # frozen_string_literal: true
  2. class FetchRemoteAccountService < BaseService
  3. include AuthorExtractor
  4. def call(url, prefetched_body = nil, protocol = :ostatus)
  5. if prefetched_body.nil?
  6. resource_url, resource_options, protocol = FetchAtomService.new.call(url)
  7. else
  8. resource_url = url
  9. resource_options = { prefetched_body: prefetched_body }
  10. end
  11. case protocol
  12. when :ostatus
  13. process_atom(resource_url, **resource_options)
  14. when :activitypub
  15. ActivityPub::FetchRemoteAccountService.new.call(resource_url, **resource_options)
  16. end
  17. end
  18. private
  19. def process_atom(url, prefetched_body:)
  20. xml = Nokogiri::XML(prefetched_body)
  21. xml.encoding = 'utf-8'
  22. account = author_from_xml(xml.at_xpath('/xmlns:feed', xmlns: OStatus::TagManager::XMLNS), false)
  23. UpdateRemoteProfileService.new.call(xml, account) unless account.nil?
  24. account
  25. rescue TypeError
  26. Rails.logger.debug "Unparseable URL given: #{url}"
  27. nil
  28. rescue Nokogiri::XML::XPath::SyntaxError
  29. Rails.logger.debug 'Invalid XML or missing namespace'
  30. nil
  31. end
  32. end