akkounts/app/controllers/well_known_controller.rb
Râu Cao 7ac3130c18
All checks were successful
continuous-integration/drone/push Build is passing
Consistent formatting
2024-06-19 20:31:31 +02:00

25 lines
666 B
Ruby

class WellKnownController < ApplicationController
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?
res = {
names: { @user.cn => @user.nostr_pubkey }
}
if Setting.nostr_relay_url
res[:relays] = {
@user.nostr_pubkey => [ Setting.nostr_relay_url ]
}
end
respond_to do |format|
format.json do
render json: res.to_json
end
end
end
end