Add own relay to NIP-05 relay list if configured
This commit is contained in:
parent
926dc06294
commit
87d900b627
@ -5,11 +5,19 @@ class WellKnownController < ApplicationController
|
||||
@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: {
|
||||
names: { "#{@user.cn}": @user.nostr_pubkey }
|
||||
}.to_json
|
||||
render json: res.to_json
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -45,6 +45,27 @@ RSpec.describe "Well-known URLs", type: :request do
|
||||
expect(res["names"].keys.size).to eq(1)
|
||||
expect(res["names"]["bobdylan"]).to eq(user.nostr_pubkey)
|
||||
end
|
||||
|
||||
context "without relay configured" do
|
||||
it "does not include a recommended relay" do
|
||||
get "/.well-known/nostr.json?name=bobdylan"
|
||||
res = JSON.parse(response.body)
|
||||
expect(res["relays"]).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
context "with relay configured" do
|
||||
before do
|
||||
Setting.nostr_relay_url = "wss://nostr.kosmos.org"
|
||||
end
|
||||
|
||||
it "includes a recommended relay" do
|
||||
get "/.well-known/nostr.json?name=bobdylan"
|
||||
res = JSON.parse(response.body)
|
||||
expect(res["relays"][user.nostr_pubkey].length).to eq(1)
|
||||
expect(res["relays"][user.nostr_pubkey].first).to eq("wss://nostr.kosmos.org")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user