34 lines
1.0 KiB
Ruby
34 lines
1.0 KiB
Ruby
class WellKnownController < ApplicationController
|
|
before_action :require_nostr_enabled, only: [ :nostr ]
|
|
|
|
def nostr
|
|
http_status :unprocessable_entity and return if params[:name].blank?
|
|
domain = request.headers["X-Forwarded-Host"].presence || Setting.primary_domain
|
|
relay_url = Setting.nostr_relay_url.presence
|
|
|
|
if params[:name] == "_"
|
|
# pubkey for the primary domain without a username (e.g. kosmos.org)
|
|
res = { names: { "_": Setting.nostr_public_key } }
|
|
res[:relays] = { "_" => [ relay_url ] } if relay_url
|
|
else
|
|
@user = User.where(cn: params[:name], ou: domain).first
|
|
http_status :not_found and return if @user.nil? || @user.nostr_pubkey.blank?
|
|
|
|
res = { names: { @user.cn => @user.nostr_pubkey } }
|
|
res[:relays] = { @user.nostr_pubkey => [ relay_url ] } if relay_url
|
|
end
|
|
|
|
respond_to do |format|
|
|
format.json do
|
|
render json: res.to_json
|
|
end
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def require_nostr_enabled
|
|
http_status :not_found unless Setting.nostr_enabled?
|
|
end
|
|
end
|