2023-08-30 13:58:52 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'distributed_press/v1/social/client'
|
|
|
|
|
|
|
|
# Publicar novedades al Fediverso
|
|
|
|
class DeploySocialDistributedPress < Deploy
|
|
|
|
# Solo luego de publicar remotamente
|
2024-02-17 17:11:17 +00:00
|
|
|
DEPENDENCIES = %i[deploy_distributed_press deploy_rsync deploy_full_rsync].freeze
|
2023-08-30 13:58:52 +00:00
|
|
|
|
2024-02-16 19:01:17 +00:00
|
|
|
after_save :create_hooks!
|
|
|
|
|
2023-08-30 13:58:52 +00:00
|
|
|
# Envía las notificaciones
|
|
|
|
def deploy(output: false)
|
|
|
|
with_tempfile(site.private_key_pem) do |file|
|
2023-08-30 14:09:08 +00:00
|
|
|
key = Shellwords.escape file.path
|
|
|
|
dest = Shellwords.escape destination
|
|
|
|
|
|
|
|
run %(bundle exec jekyll notify --trace --key #{key} --destination "#{dest}"), output: output
|
2023-08-30 13:58:52 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-08-30 14:09:08 +00:00
|
|
|
# Igual que DeployLocal
|
|
|
|
#
|
|
|
|
# @return [String]
|
|
|
|
def destination
|
|
|
|
File.join(Rails.root, '_deploy', site.hostname)
|
|
|
|
end
|
|
|
|
|
|
|
|
# Solo uno
|
|
|
|
#
|
|
|
|
# @return [Integer]
|
|
|
|
def limit
|
|
|
|
1
|
|
|
|
end
|
|
|
|
|
|
|
|
# Espacio ocupado, pero no podemos calcularlo
|
|
|
|
#
|
|
|
|
# @return [Integer]
|
|
|
|
def size
|
|
|
|
0
|
|
|
|
end
|
|
|
|
|
|
|
|
# El perfil de actor
|
|
|
|
#
|
|
|
|
# @return [String,nil]
|
|
|
|
def url
|
|
|
|
site.data.dig('activity_pub', 'actor')
|
|
|
|
end
|
|
|
|
|
2023-08-30 13:58:52 +00:00
|
|
|
# Genera la opción de llave privada para jekyll build
|
|
|
|
#
|
|
|
|
# @params :args [Hash]
|
|
|
|
# @return [String]
|
|
|
|
def flags_for_build(**args)
|
|
|
|
"--key #{Shellwords.escape args[:private_key].path}"
|
|
|
|
end
|
2024-02-16 19:01:17 +00:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
# Obtiene el hostname de la API de Sutty
|
|
|
|
#
|
|
|
|
# @return [String]
|
|
|
|
def api_hostname
|
|
|
|
Rails.application.routes.default_url_options[:host].sub('panel', 'api')
|
|
|
|
end
|
|
|
|
|
|
|
|
# Crea los hooks en la Social Inbox para que nos avise de actividades
|
|
|
|
# nuevas
|
|
|
|
#
|
|
|
|
# @return [nil]
|
|
|
|
def create_hooks!
|
|
|
|
hook_client = site.social_inbox.hook
|
2024-02-17 17:11:17 +00:00
|
|
|
webhook_class = DistributedPress::V1::Social::Schemas::Webhook
|
2024-02-16 19:01:17 +00:00
|
|
|
|
|
|
|
hook_client.class::EVENTS.each do |event|
|
2024-02-22 20:58:51 +00:00
|
|
|
event_url = :"v1_site_webhooks_#{event}_url"
|
2024-02-16 19:01:17 +00:00
|
|
|
|
2024-02-17 17:11:17 +00:00
|
|
|
webhook =
|
|
|
|
webhook_class.new.call({
|
|
|
|
method: 'POST',
|
|
|
|
url: Rails.application.routes.url_helpers.public_send(
|
|
|
|
event_url, site_id: site.name, host: api_hostname
|
|
|
|
),
|
|
|
|
headers: {
|
|
|
|
'X-Social-Inbox': rol.token
|
|
|
|
}
|
|
|
|
})
|
2024-02-16 19:01:17 +00:00
|
|
|
|
|
|
|
raise ArgumentError, webhook.errors.messages if webhook.failure?
|
|
|
|
|
|
|
|
response = hook_client.put(event: event, hook: webhook)
|
|
|
|
|
2024-02-22 21:04:56 +00:00
|
|
|
raise ArgumentError, response.body unless response.ok?
|
2024-02-16 19:01:17 +00:00
|
|
|
rescue ArgumentError => e
|
|
|
|
ExceptionNotifier.notify_exception(e, data: { site_id: site.name, usuarie_id: rol.usuarie_id })
|
|
|
|
end
|
|
|
|
end
|
2023-08-30 13:58:52 +00:00
|
|
|
end
|