5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-20 08:16:21 +00:00

feat: acceder a la social inbox desde el sitio

This commit is contained in:
f 2024-02-16 14:54:50 -03:00
parent cdf0685c67
commit 6d0ea6fa5d
No known key found for this signature in database
2 changed files with 62 additions and 1 deletions

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true # frozen_string_literal: true
require 'distributed_press/v1/social/client'
class Site class Site
# Agrega soporte para Social Distributed Press en los sitios # Agrega soporte para Social Distributed Press en los sitios
module SocialDistributedPress module SocialDistributedPress
@ -10,13 +12,20 @@ class Site
before_save :generate_private_key_pem!, unless: :private_key_pem? before_save :generate_private_key_pem!, unless: :private_key_pem?
# @return [SocialInbox]
def social_inbox
@social_inbox ||= SocialInbox.new(site: self)
end
private private
# Genera la llave privada y la almacena # Genera la llave privada y la almacena
# #
# @return [nil] # @return [nil]
def generate_private_key_pem! def generate_private_key_pem!
self.private_key_pem ||= ::DistributedPress::V1::Social::Client.new(public_key_url: nil, key_size: 2048).private_key.export self.private_key_pem ||= DistributedPress::V1::Social::Client.new(
public_key_url: nil,
key_size: 2048).private_key.export
end end
end end
end end

View file

@ -0,0 +1,52 @@
# frozen_string_literal: true
require 'distributed_press/v1/social/client'
# Gestiona la Social Inbox de un sitio
class SocialInbox
# @return [Site]
attr_reader :site
# @param :site [Site]
def initialize(site:)
@site = site
end
# @return [String]
def actor
@actor ||=
begin
user = site.config.dig('activity_pub', 'username')
user ||= hostname.split('.', 2).first
"@#{user}@#{hostname}"
end
end
# @return [DistributedPress::V1::Social::Client]
def client
@client ||= DistributedPress::V1::Social::Client.new(
url: site.config.dig('activity_pub', 'url'),
public_key_url: public_key_url,
private_key_pem: site.private_key_pem,
logger: Rails.logger,
cache_store: :redis
)
end
# @return [String]
def public_key_url
@public_key_url ||= URI("https://#{hostname}").tap do |uri|
uri.path = '/about.jsonld'
uri.fragment = 'main-key'
end.to_s
end
def hostname
@hostname ||=
begin
host = site.config.dig('activity_pub', 'hostname')
host ||= site.hostname
end
end
end