2024-02-21 15:30:01 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# Obtiene o actualiza el contenido de un objeto, usando las credenciales
|
|
|
|
# del sitio.
|
|
|
|
#
|
|
|
|
# XXX: Esto usa las credenciales del sitio para volver el objeto
|
|
|
|
# disponible para todo el CMS. Asumimos que el objeto devuelto es el
|
|
|
|
# mismo para todo el mundo y las credenciales solo son para
|
|
|
|
# autenticación.
|
2024-02-21 15:46:38 +00:00
|
|
|
class ActivityPub
|
|
|
|
class FetchJob < ApplicationJob
|
2024-02-27 19:53:48 +00:00
|
|
|
self.priority = 50
|
|
|
|
|
2024-03-13 19:11:40 +00:00
|
|
|
def perform(site:, object_id:)
|
2024-02-21 15:46:38 +00:00
|
|
|
ActivityPub::Object.transaction do
|
2024-03-13 19:11:40 +00:00
|
|
|
object = ::ActivityPub::Object.find(object_id)
|
|
|
|
|
|
|
|
return if object.blank?
|
2024-02-21 20:08:11 +00:00
|
|
|
return if object.activity_pubs.where(aasm_state: 'removed').count.positive?
|
|
|
|
|
2024-02-21 15:46:38 +00:00
|
|
|
response = site.social_inbox.dereferencer.get(uri: object.uri)
|
2024-02-21 15:30:01 +00:00
|
|
|
|
2024-02-21 15:46:38 +00:00
|
|
|
# @todo Fallar cuando la respuesta no funcione?
|
|
|
|
return unless response.ok?
|
2024-02-21 20:22:31 +00:00
|
|
|
return if response.miss? && object.content.present?
|
2024-02-21 15:32:39 +00:00
|
|
|
|
2024-02-21 17:07:11 +00:00
|
|
|
content = FastJsonparser.parse(response.body)
|
|
|
|
|
|
|
|
object.update(content: content, type: ActivityPub::Object.type_from(content).name)
|
2024-02-21 15:46:38 +00:00
|
|
|
end
|
2024-02-21 15:30:01 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|