2024-02-24 14:09:57 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class ActivityPub
|
2024-02-27 19:54:09 +00:00
|
|
|
# Obtiene o actualiza los datos de una instancia. Usamos un cliente
|
|
|
|
# de ActivityPub porque la instancia podría estar en federación
|
|
|
|
# limitada.
|
2024-02-24 14:09:57 +00:00
|
|
|
class InstanceFetchJob < ApplicationJob
|
2024-02-27 19:53:48 +00:00
|
|
|
self.priority = 100
|
|
|
|
|
2024-02-24 14:09:57 +00:00
|
|
|
def perform(site:, instance:)
|
|
|
|
%w[/api/v2/instance /api/v1/instance].each do |api|
|
|
|
|
uri = SocialInbox.generate_uri(instance.hostname) do |u|
|
|
|
|
u.path = api
|
|
|
|
end
|
|
|
|
|
|
|
|
response = site.social_inbox.dereferencer.get(uri: uri)
|
|
|
|
|
|
|
|
next unless response.ok?
|
2024-02-27 19:54:09 +00:00
|
|
|
# @todo Validate schema
|
|
|
|
next unless response.parsed_response.is_a?(DistributedPress::V1::Social::ReferencedObject)
|
2024-02-24 14:09:57 +00:00
|
|
|
|
2024-02-27 19:54:09 +00:00
|
|
|
instance.update(content: response.parsed_response.object)
|
2024-02-24 14:09:57 +00:00
|
|
|
|
2024-02-28 15:32:59 +00:00
|
|
|
break
|
|
|
|
rescue BRS::BaseError,
|
|
|
|
Errno::ECONNREFUSED,
|
|
|
|
HTTParty::Error,
|
|
|
|
JSON::JSONError,
|
|
|
|
Net::OpenTimeout,
|
|
|
|
OpenSSL::OpenSSLError,
|
|
|
|
SocketError,
|
|
|
|
Errno::ENETUNREACH => e
|
|
|
|
ExceptionNotifier.notify_exception(e, data: { instance: uri })
|
2024-02-24 14:09:57 +00:00
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|