5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-26 17:06:21 +00:00

feat: obtener información sobre la instancia

This commit is contained in:
f 2024-02-24 11:09:57 -03:00
parent 4e31a6858d
commit f836427979
No known key found for this signature in database
3 changed files with 29 additions and 4 deletions

View file

@ -150,6 +150,9 @@ module Api
next if a.instance next if a.instance
a.instance = ActivityPub::Instance.find_or_create_by(hostname: URI.parse(a.uri).hostname) a.instance = ActivityPub::Instance.find_or_create_by(hostname: URI.parse(a.uri).hostname)
ActivityPub::InstanceFetchJob.perform_later(site: site, instance: a.instance)
a.save! a.save!
end end
end end

View file

@ -0,0 +1,22 @@
# frozen_string_literal: true
class ActivityPub
# Obtiene o actualiza los datos de una instancia.
class InstanceFetchJob < ApplicationJob
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?
instance.update(content: response.parsed_response)
break
end
end
end
end

View file

@ -28,7 +28,7 @@ class SocialInbox
end end
def actor_id def actor_id
@actor_id ||= generate_uri do |uri| @actor_id ||= SocialInbox.generate_uri(hostname) do |uri|
uri.path = '/about.jsonld' uri.path = '/about.jsonld'
end end
end end
@ -61,7 +61,7 @@ class SocialInbox
# @return [String] # @return [String]
def public_key_url def public_key_url
@public_key_url ||= generate_uri do |uri| @public_key_url ||= SocialInbox.generate_uri(hostname) do |uri|
uri.path = '/about.jsonld' uri.path = '/about.jsonld'
uri.fragment = 'main-key' uri.fragment = 'main-key'
end end
@ -78,7 +78,7 @@ class SocialInbox
# Genera una URI dentro de este sitio # Genera una URI dentro de este sitio
# #
# @return [String] # @return [String]
def generate_uri(&block) def self.generate_uri(hostname, &block)
@public_key_url ||= URI("https://#{hostname}").tap(&block).to_s URI("https://#{hostname}").tap(&block).to_s
end end
end end