From 6c374b51537126a2cba29f3eaf74faf1fc64ba96 Mon Sep 17 00:00:00 2001 From: multiple creatures Date: Mon, 6 May 2019 20:51:20 -0500 Subject: Drop OStatus support. Fix some of the Rspec tests. --- app/services/fetch_atom_service.rb | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) (limited to 'app/services/fetch_atom_service.rb') diff --git a/app/services/fetch_atom_service.rb b/app/services/fetch_atom_service.rb index d6508a988..ce148bfb4 100644 --- a/app/services/fetch_atom_service.rb +++ b/app/services/fetch_atom_service.rb @@ -7,11 +7,6 @@ class FetchAtomService < BaseService return if url.blank? result = process(url) - - # retry without ActivityPub - result ||= process(url) if @unsupported_activity - - result rescue OpenSSL::SSL::SSLError => e Rails.logger.debug "SSL error: #{e}" nil @@ -28,8 +23,7 @@ class FetchAtomService < BaseService end def perform_request(&block) - accept = 'text/html' - accept = 'application/activity+json, application/ld+json; profile="https://www.w3.org/ns/activitystreams", application/atom+xml, ' + accept unless @unsupported_activity + accept = 'application/activity+json, application/ld+json; profile="https://www.w3.org/ns/activitystreams", text/html' Request.new(:get, @url).add_headers('Accept' => accept).perform(&block) end @@ -37,17 +31,14 @@ class FetchAtomService < BaseService def process_response(response, terminal = false) return nil if response.code != 200 - if response.mime_type == 'application/atom+xml' - [@url, { prefetched_body: response.body_with_limit }, :ostatus] - elsif ['application/activity+json', 'application/ld+json'].include?(response.mime_type) + if ['application/activity+json', 'application/ld+json'].include?(response.mime_type) body = response.body_with_limit json = body_to_json(body) if supported_context?(json) && equals_or_includes_any?(json['type'], ActivityPub::FetchRemoteAccountService::SUPPORTED_TYPES) && json['inbox'].present? - [json['id'], { prefetched_body: body, id: true }, :activitypub] + [json['id'], { prefetched_body: body, id: true }] elsif supported_context?(json) && expected_type?(json) - [json['id'], { prefetched_body: body, id: true }, :activitypub] + [json['id'], { prefetched_body: body, id: true }] else - @unsupported_activity = true nil end elsif !terminal @@ -69,21 +60,17 @@ class FetchAtomService < BaseService page = Nokogiri::HTML(response.body_with_limit) json_link = page.xpath('//link[@rel="alternate"]').find { |link| ['application/activity+json', 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'].include?(link['type']) } - atom_link = page.xpath('//link[@rel="alternate"]').find { |link| link['type'] == 'application/atom+xml' } - - result ||= process(json_link['href'], terminal: true) unless json_link.nil? || @unsupported_activity - result ||= process(atom_link['href'], terminal: true) unless atom_link.nil? + result = process(json_link['href'], terminal: true) unless json_link.nil? + result ||= nil result end def process_link_headers(link_header) json_link = link_header.find_link(%w(rel alternate), %w(type application/activity+json)) || link_header.find_link(%w(rel alternate), ['type', 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"']) - atom_link = link_header.find_link(%w(rel alternate), %w(type application/atom+xml)) - - result ||= process(json_link.href, terminal: true) unless json_link.nil? || @unsupported_activity - result ||= process(atom_link.href, terminal: true) unless atom_link.nil? + result = process(json_link.href, terminal: true) unless json_link.nil? + result ||= nil result end -- cgit