Hide media server settings when no Blossom server is configured
This commit is contained in:
6 files changed
+72
-3
No files matched your search
@@ -186,9 +186,14 @@ class SettingsController < ApplicationController
|
||||
pubkey: @user.nostr_pubkey, kind: NostrManagerService::PROFILE_KIND, relays: relays
|
||||
)
|
||||
Rails.cache.write(nostr_metadata_cache_key("profile"), profile, expires_in: 5.minutes)
|
||||
render json: { next: "blossom", event_id: profile&.dig("id") }
|
||||
render json: {
|
||||
next: Setting.nostr_media_servers_enabled? ? "blossom" : "render",
|
||||
event_id: profile&.dig("id")
|
||||
}
|
||||
|
||||
when "blossom"
|
||||
return render json: { next: "render" } unless Setting.nostr_media_servers_enabled?
|
||||
|
||||
write_relays = Rails.cache.read(nostr_metadata_cache_key("write_relays")) || []
|
||||
relays = write_relays.any? ? write_relays : discovery_relay_urls
|
||||
media_list = NostrManager::DiscoverUserEvent.call(
|
||||
@@ -201,7 +206,7 @@ class SettingsController < ApplicationController
|
||||
when "render", nil
|
||||
@nip65_event = Rails.cache.read(nostr_metadata_cache_key("nip65"))
|
||||
@profile = Rails.cache.read(nostr_metadata_cache_key("profile"))
|
||||
@media_list = Rails.cache.read(nostr_metadata_cache_key("blossom"))
|
||||
@media_list = Rails.cache.read(nostr_metadata_cache_key("blossom")) if Setting.nostr_media_servers_enabled?
|
||||
render partial: "nostr_metadata", formats: :html
|
||||
|
||||
else
|
||||
|
||||
@@ -31,6 +31,9 @@ module Settings
|
||||
message: "must be an http:// or https:// URL"
|
||||
} }
|
||||
|
||||
field :nostr_media_servers_enabled, type: :boolean,
|
||||
default: -> { self.nostr_blossom_server_url.present? }
|
||||
|
||||
field :nostr_signer_relays, type: :array, default: %w[
|
||||
wss://nostr.kosmos.org
|
||||
]
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
<% if Setting.nostr_relay_url.present? %>
|
||||
<li>Publish notes and other stuff on our Nostr relay</li>
|
||||
<% end %>
|
||||
<% if Setting.nostr_blossom_server_url.present? %>
|
||||
<% if Setting.nostr_media_servers_enabled? %>
|
||||
<li>Publish media files on our Nostr media server</li>
|
||||
<% end %>
|
||||
</ul>
|
||||
|
||||
@@ -24,9 +24,11 @@
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<% if Setting.nostr_media_servers_enabled? %>
|
||||
<section class="mb-8 sm:mb-12">
|
||||
<h3>Media servers</h3>
|
||||
<%= render Settings::NostrMediaServerStatusComponent.new(
|
||||
media_list_event: @media_list
|
||||
) %>
|
||||
</section>
|
||||
<% end %>
|
||||
@@ -22,4 +22,17 @@ RSpec.describe Setting, type: :model do
|
||||
end
|
||||
end
|
||||
|
||||
describe ".nostr_media_servers_enabled?" do
|
||||
it "is enabled when a Blossom server is configured" do
|
||||
Setting.nostr_blossom_server_url = "https://blossom.example.com"
|
||||
|
||||
expect(Setting.nostr_media_servers_enabled?).to be(true)
|
||||
end
|
||||
|
||||
it "is disabled without a Blossom server" do
|
||||
Setting.nostr_blossom_server_url = nil
|
||||
|
||||
expect(Setting.nostr_media_servers_enabled?).to be(false)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -159,6 +159,8 @@ RSpec.describe "Settings", type: :request do
|
||||
allow(Setting).to receive(:nostr_relay_url).and_return("wss://site.example.com")
|
||||
allow(Setting).to receive(:nostr_discovery_relays)
|
||||
.and_return(["wss://discovery.example.com"])
|
||||
allow(Setting).to receive(:nostr_blossom_server_url)
|
||||
.and_return("https://blossom.example.com")
|
||||
end
|
||||
|
||||
let(:discovery_relays) do
|
||||
@@ -274,6 +276,50 @@ RSpec.describe "Settings", type: :request do
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
end
|
||||
|
||||
it "includes the media servers section when configured" do
|
||||
get nostr_metadata_settings_path(step: "render"),
|
||||
headers: { "HTTP_ACCEPT" => "text/html" }
|
||||
|
||||
expect(response.body).to include("Media servers")
|
||||
end
|
||||
end
|
||||
|
||||
context "without a configured media server" do
|
||||
before do
|
||||
allow(Setting).to receive(:nostr_blossom_server_url).and_return(nil)
|
||||
end
|
||||
|
||||
it "skips the media server list and asks to render next" do
|
||||
expect(NostrManager::DiscoverUserEvent).to receive(:call)
|
||||
.with(pubkey: "abc123", kind: NostrManagerService::PROFILE_KIND,
|
||||
relays: discovery_relays)
|
||||
.and_return(nil)
|
||||
|
||||
get nostr_metadata_settings_path(step: "profile"),
|
||||
headers: { "HTTP_ACCEPT" => "application/json" }
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
expect(JSON.parse(response.body)).to eq("next" => "render", "event_id" => nil)
|
||||
end
|
||||
|
||||
it "does not fetch the media server list" do
|
||||
expect(NostrManager::DiscoverUserEvent).not_to receive(:call)
|
||||
|
||||
get nostr_metadata_settings_path(step: "blossom"),
|
||||
headers: { "HTTP_ACCEPT" => "application/json" }
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
expect(JSON.parse(response.body)).to eq("next" => "render")
|
||||
end
|
||||
|
||||
it "does not render the media servers section" do
|
||||
get nostr_metadata_settings_path(step: "render"),
|
||||
headers: { "HTTP_ACCEPT" => "text/html" }
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
expect(response.body).not_to include("Media servers")
|
||||
end
|
||||
end
|
||||
|
||||
context "with an unknown step" do
|
||||
|
||||
Reference in new issue
Block a user