Allow to configure a separate key for the NIP-05 address of the primary domain vs the accounts domain.
48 lines
1.5 KiB
Ruby
48 lines
1.5 KiB
Ruby
class WellKnownController < ApplicationController
|
|
before_action :require_nostr_enabled, only: [ :nostr ]
|
|
before_action :allow_cross_origin_requests, only: [ :nostr ]
|
|
|
|
layout false
|
|
|
|
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] == "_"
|
|
if domain == Setting.primary_domain
|
|
# pubkey for the primary domain without a username (e.g. kosmos.org)
|
|
res = { names: { "_": Setting.nostr_public_key_primary_domain || Setting.nostr_public_key } }
|
|
else
|
|
# pubkey for the akkounts domain without a username (e.g. accounts.kosmos.org)
|
|
res = { names: { "_": Setting.nostr_public_key } }
|
|
end
|
|
|
|
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
|
|
|
|
def allow_cross_origin_requests
|
|
headers['Access-Control-Allow-Origin'] = "*"
|
|
headers['Access-Control-Allow-Methods'] = "GET"
|
|
end
|
|
end
|