5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-26 15:06:22 +00:00
panel/app/jobs/activity_pub/instance_fetch_job.rb

29 lines
801 B
Ruby
Raw Normal View History

# 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.
class InstanceFetchJob < ApplicationJob
self.priority = 100
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-27 19:54:09 +00:00
instance.update(content: response.parsed_response.object)
break
end
end
end
end