mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-26 09:56:21 +00:00
feat: obtener información sobre la instancia
This commit is contained in:
parent
4e31a6858d
commit
f836427979
3 changed files with 29 additions and 4 deletions
|
@ -150,6 +150,9 @@ module Api
|
|||
next if a.instance
|
||||
|
||||
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!
|
||||
end
|
||||
end
|
||||
|
|
22
app/jobs/activity_pub/instance_fetch_job.rb
Normal file
22
app/jobs/activity_pub/instance_fetch_job.rb
Normal 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
|
|
@ -28,7 +28,7 @@ class SocialInbox
|
|||
end
|
||||
|
||||
def actor_id
|
||||
@actor_id ||= generate_uri do |uri|
|
||||
@actor_id ||= SocialInbox.generate_uri(hostname) do |uri|
|
||||
uri.path = '/about.jsonld'
|
||||
end
|
||||
end
|
||||
|
@ -61,7 +61,7 @@ class SocialInbox
|
|||
|
||||
# @return [String]
|
||||
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.fragment = 'main-key'
|
||||
end
|
||||
|
@ -78,7 +78,7 @@ class SocialInbox
|
|||
# Genera una URI dentro de este sitio
|
||||
#
|
||||
# @return [String]
|
||||
def generate_uri(&block)
|
||||
@public_key_url ||= URI("https://#{hostname}").tap(&block).to_s
|
||||
def self.generate_uri(hostname, &block)
|
||||
URI("https://#{hostname}").tap(&block).to_s
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue