Support "_" placeholder username for domain's own NIP-05
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing

This commit is contained in:
2024-06-19 20:57:22 +02:00
parent 7ac3130c18
commit 48ab96dda9
2 changed files with 43 additions and 13 deletions

View File

@@ -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