Compare commits
3 Commits
00b73b06d7
...
cbfa148051
| Author | SHA1 | Date | |
|---|---|---|---|
|
cbfa148051
|
|||
|
87d900b627
|
|||
|
926dc06294
|
@@ -29,6 +29,7 @@
|
||||
|
||||
#
|
||||
# Service Integrations
|
||||
# (sorted alphabetically by service name)
|
||||
#
|
||||
|
||||
# BTCPAY_PUBLIC_URL='https://btcpay.example.com'
|
||||
@@ -62,5 +63,9 @@
|
||||
|
||||
# MEDIAWIKI_PUBLIC_URL='https://wiki.kosmos.org'
|
||||
|
||||
# NOSTR_PRIVATE_KEY='123456abcdef...'
|
||||
# NOSTR_PUBLIC_KEY='123456abcdef...'
|
||||
# NOSTR_RELAY_URL='wss://nostr.kosmos.org'
|
||||
|
||||
# RS_STORAGE_URL='https://storage.kosmos.org'
|
||||
# RS_REDIS_URL='redis://localhost:6379/2'
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -169,6 +169,9 @@ class Setting < RailsSettings::Base
|
||||
field :nostr_public_key, type: :string,
|
||||
default: ENV["NOSTR_PUBLIC_KEY"].presence
|
||||
|
||||
field :nostr_relay_url, type: :string,
|
||||
default: ENV["NOSTR_RELAY_URL"].presence
|
||||
|
||||
field :nostr_zaps_relay_limit, type: :integer,
|
||||
default: 12
|
||||
|
||||
|
||||
@@ -6,8 +6,13 @@ module NostrManager
|
||||
|
||||
def call
|
||||
tags = parse_tags(@zap.request_event.tags)
|
||||
relays = tags[:relays].take(Setting.nostr_zaps_relay_limit)
|
||||
|
||||
tags[:relays].take(Setting.nostr_zaps_relay_limit).each do |relay_url|
|
||||
if Setting.nostr_relay_url.present?
|
||||
relays << Setting.nostr_relay_url
|
||||
end
|
||||
|
||||
relays.uniq.each do |relay_url|
|
||||
if @delayed
|
||||
NostrPublishEventJob.perform_later(event: @zap.receipt, relay_url: relay_url)
|
||||
else
|
||||
|
||||
@@ -19,6 +19,11 @@
|
||||
title: "Public key",
|
||||
description: "The corresponding public key of the accounts service"
|
||||
) %>
|
||||
<%= render FormElements::FieldsetResettableSettingComponent.new(
|
||||
key: :nostr_relay_url,
|
||||
title: "Relay URL",
|
||||
description: "Websockets URL of a relay associated with #{Setting.primary_domain}"
|
||||
) %>
|
||||
</ul>
|
||||
</section>
|
||||
<section>
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -35,6 +35,19 @@ RSpec.describe NostrManager::PublishZapReceipt, type: :model do
|
||||
|
||||
described_class.call(zap: zap)
|
||||
end
|
||||
|
||||
context "with own relay configured" do
|
||||
before do
|
||||
Setting.nostr_relay_url = "wss://foobar.kosmos.org"
|
||||
end
|
||||
|
||||
it "also publishes the receipt to our own relay" do
|
||||
expect(NostrPublishEventJob).to receive(:perform_later)
|
||||
.exactly(13).times.and_return(true)
|
||||
|
||||
described_class.call(zap: zap)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user