5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-26 14:46:21 +00:00
panel/app/models/site/social_distributed_press.rb

37 lines
846 B
Ruby
Raw Normal View History

2023-08-29 20:43:19 +00:00
# frozen_string_literal: true
require 'distributed_press/v1/social/client'
2023-08-29 20:43:19 +00:00
class Site
# Agrega soporte para Social Distributed Press en los sitios
module SocialDistributedPress
extend ActiveSupport::Concern
included do
2024-02-23 15:53:56 +00:00
has_encrypted :private_key_pem
2023-08-29 20:49:25 +00:00
2024-02-20 20:15:43 +00:00
has_many :activity_pubs
has_many :instance_moderations
2024-02-20 20:15:43 +00:00
2023-08-29 20:49:25 +00:00
before_save :generate_private_key_pem!, unless: :private_key_pem?
# @return [SocialInbox]
def social_inbox
@social_inbox ||= SocialInbox.new(site: self)
end
2023-08-29 20:49:25 +00:00
private
# Genera la llave privada y la almacena
#
# @return [nil]
def generate_private_key_pem!
self.private_key_pem ||= DistributedPress::V1::Social::Client.new(
public_key_url: nil,
2024-02-17 17:11:17 +00:00
key_size: 2048
).private_key.export
2023-08-29 20:49:25 +00:00
end
2023-08-29 20:43:19 +00:00
end
end
end