Support "_" placeholder username for domain's own NIP-05
This commit is contained in:
@@ -1,18 +1,23 @@
|
||||
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
|
||||
@user = User.where(cn: params[:name], ou: domain).first
|
||||
http_status :not_found and return if @user.nil? || @user.nostr_pubkey.blank?
|
||||
relay_url = Setting.nostr_relay_url
|
||||
|
||||
res = {
|
||||
names: { @user.cn => @user.nostr_pubkey }
|
||||
}
|
||||
if params[:name] == "_"
|
||||
# pubkey for the primary domain without a username (e.g. kosmos.org)
|
||||
res = { names: { "_": Setting.nostr_public_key } }
|
||||
else
|
||||
@user = User.where(cn: params[:name], ou: domain).first
|
||||
http_status :not_found and return if @user.nil? || @user.nostr_pubkey.blank?
|
||||
|
||||
if Setting.nostr_relay_url
|
||||
res[:relays] = {
|
||||
@user.nostr_pubkey => [ Setting.nostr_relay_url ]
|
||||
}
|
||||
res = { names: { @user.cn => @user.nostr_pubkey } }
|
||||
end
|
||||
|
||||
if relay_url
|
||||
res[:relays] = { @user.nostr_pubkey => [ relay_url ] }
|
||||
end
|
||||
|
||||
respond_to do |format|
|
||||
@@ -21,4 +26,10 @@ class WellKnownController < ApplicationController
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def require_nostr_enabled
|
||||
http_status :not_found unless Setting.nostr_enabled?
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user