diff --git a/lib/nulla/models/instance_settings.ex b/lib/nulla/models/instance_settings.ex index 37ffe88..b46d3be 100644 --- a/lib/nulla/models/instance_settings.ex +++ b/lib/nulla/models/instance_settings.ex @@ -7,7 +7,6 @@ defmodule Nulla.Models.InstanceSettings do schema "instance_settings" do field :name, :string, default: "Nulla" field :description, :string, default: "Freedom Social Network" - field :domain, :string, default: "localhost" field :registration, :boolean, default: false field :max_characters, :integer, default: 5000 field :max_upload_size, :integer, default: 50 @@ -22,7 +21,6 @@ defmodule Nulla.Models.InstanceSettings do |> cast(attrs, [ :name, :description, - :domain, :registration, :max_characters, :max_upload_size, @@ -33,7 +31,6 @@ defmodule Nulla.Models.InstanceSettings do |> validate_required([ :name, :description, - :domain, :registration, :max_characters, :max_upload_size, diff --git a/lib/nulla/models/relation.ex b/lib/nulla/models/relation.ex index 3271d5d..7d50f93 100644 --- a/lib/nulla/models/relation.ex +++ b/lib/nulla/models/relation.ex @@ -69,7 +69,9 @@ defmodule Nulla.Models.Relation do case get_relation(local_actor_id: local_actor_id, remote_actor_id: remote_actor_id) do nil -> attrs = - Keyword.merge([local_actor_id: local_actor_id, remote_actor_id: remote_actor_id], opts) + [local_actor_id: local_actor_id, remote_actor_id: remote_actor_id] + |> Keyword.merge(opts) + |> Enum.into(%{}) case create_relation(attrs) do {:ok, relation} -> {:ok, relation} diff --git a/lib/nulla/utils.ex b/lib/nulla/utils.ex index 4915620..4dd8d22 100644 --- a/lib/nulla/utils.ex +++ b/lib/nulla/utils.ex @@ -1,6 +1,4 @@ defmodule Nulla.Utils do - alias Finch - def fetch_remote_actor(uri) do headers = [ {"Accept", "application/activity+json"}, diff --git a/lib/nulla_web/controllers/actor_controller.ex b/lib/nulla_web/controllers/actor_controller.ex index ee46d0a..bedcc0f 100644 --- a/lib/nulla_web/controllers/actor_controller.ex +++ b/lib/nulla_web/controllers/actor_controller.ex @@ -4,12 +4,10 @@ defmodule NullaWeb.ActorController do alias Nulla.Models.Actor alias Nulla.Models.Relation alias Nulla.Models.Note - alias Nulla.Models.InstanceSettings def show(conn, %{"username" => username}) do format = Phoenix.Controller.get_format(conn) - instance_settings = InstanceSettings.get_instance_settings!() - domain = instance_settings.domain + domain = NullaWeb.Endpoint.host() case Actor.get_actor(preferredUsername: username, domain: domain) do nil -> diff --git a/lib/nulla_web/controllers/auth_controller.ex b/lib/nulla_web/controllers/auth_controller.ex index e766e56..8a6017d 100644 --- a/lib/nulla_web/controllers/auth_controller.ex +++ b/lib/nulla_web/controllers/auth_controller.ex @@ -39,7 +39,7 @@ defmodule NullaWeb.AuthController do |> put_flash(:error, "Registration is disabled.") |> redirect(to: ~p"/") else - domain = instance_settings.domain + domain = NullaWeb.Endpoint.host() hashed_password = Argon2.hash_pwd_salt(password) {publicKeyPem, privateKeyPem} = Nulla.KeyGen.gen() diff --git a/lib/nulla_web/controllers/follow_controller.ex b/lib/nulla_web/controllers/follow_controller.ex index d8ca5b4..22dc1c4 100644 --- a/lib/nulla_web/controllers/follow_controller.ex +++ b/lib/nulla_web/controllers/follow_controller.ex @@ -7,7 +7,7 @@ defmodule NullaWeb.FollowController do def following(conn, %{"username" => username, "page" => page_param}) do instance_settings = InstanceSettings.get_instance_settings!() - domain = instance_settings.domain + domain = NullaWeb.Endpoint.host() limit = instance_settings.api_limit actor = Actor.get_actor(preferredUsername: username, domain: domain) total = Relation.count_following(actor.id) @@ -26,8 +26,7 @@ defmodule NullaWeb.FollowController do end def following(conn, %{"username" => username}) do - instance_settings = InstanceSettings.get_instance_settings!() - domain = instance_settings.domain + domain = NullaWeb.Endpoint.host() actor = Actor.get_actor(preferredUsername: username, domain: domain) total = Relation.count_following(actor.id) @@ -38,7 +37,7 @@ defmodule NullaWeb.FollowController do def followers(conn, %{"username" => username, "page" => page_param}) do instance_settings = InstanceSettings.get_instance_settings!() - domain = instance_settings.domain + domain = NullaWeb.Endpoint.host() limit = instance_settings.api_limit actor = Actor.get_actor(preferredUsername: username, domain: domain) total = Relation.count_followers(actor.id) @@ -57,8 +56,7 @@ defmodule NullaWeb.FollowController do end def followers(conn, %{"username" => username}) do - instance_settings = InstanceSettings.get_instance_settings!() - domain = instance_settings.domain + domain = NullaWeb.Endpoint.host() actor = Actor.get_actor(preferredUsername: username, domain: domain) total = Relation.count_followers(actor.id) diff --git a/lib/nulla_web/controllers/hostmeta_controller.ex b/lib/nulla_web/controllers/hostmeta_controller.ex index 8f7d835..cee64ce 100644 --- a/lib/nulla_web/controllers/hostmeta_controller.ex +++ b/lib/nulla_web/controllers/hostmeta_controller.ex @@ -1,10 +1,8 @@ defmodule NullaWeb.HostmetaController do use NullaWeb, :controller - alias Nulla.Models.InstanceSettings def index(conn, _params) do - instance_settings = InstanceSettings.get_instance_settings!() - domain = instance_settings.domain + domain = NullaWeb.Endpoint.host() xml = """ diff --git a/lib/nulla_web/controllers/nodeinfo_controller.ex b/lib/nulla_web/controllers/nodeinfo_controller.ex index aaa68bd..f532473 100644 --- a/lib/nulla_web/controllers/nodeinfo_controller.ex +++ b/lib/nulla_web/controllers/nodeinfo_controller.ex @@ -5,8 +5,7 @@ defmodule NullaWeb.NodeinfoController do alias Nulla.Models.InstanceSettings def index(conn, _params) do - instance_settings = InstanceSettings.get_instance_settings!() - domain = instance_settings.domain + domain = NullaWeb.Endpoint.host() json(conn, ActivityPub.nodeinfo(domain)) end diff --git a/lib/nulla_web/controllers/outbox_controller.ex b/lib/nulla_web/controllers/outbox_controller.ex index 093015d..d6b5791 100644 --- a/lib/nulla_web/controllers/outbox_controller.ex +++ b/lib/nulla_web/controllers/outbox_controller.ex @@ -3,14 +3,13 @@ defmodule NullaWeb.OutboxController do alias Nulla.ActivityPub alias Nulla.Models.Actor alias Nulla.Models.Note - alias Nulla.Models.InstanceSettings def outbox(conn, %{"username" => username} = params) do + domain = NullaWeb.Endpoint.host() + actor = Actor.get_actor(preferredUsername: username, domain: domain) + case Map.get(params, "page") do "true" -> - instance_settings = InstanceSettings.get_instance_settings!() - domain = instance_settings.domain - actor = Actor.get_actor(preferredUsername: username, domain: domain) max_id = params["max_id"] && String.to_integer(params["max_id"]) notes = @@ -42,9 +41,6 @@ defmodule NullaWeb.OutboxController do ) _ -> - instance_settings = InstanceSettings.get_instance_settings!() - domain = instance_settings.domain - actor = Actor.get_actor(preferredUsername: username, domain: domain) total = Note.get_total_notes_count(actor.id) conn diff --git a/lib/nulla_web/controllers/webfinger_controller.ex b/lib/nulla_web/controllers/webfinger_controller.ex index 3db0a28..c837146 100644 --- a/lib/nulla_web/controllers/webfinger_controller.ex +++ b/lib/nulla_web/controllers/webfinger_controller.ex @@ -2,21 +2,20 @@ defmodule NullaWeb.WebfingerController do use NullaWeb, :controller alias Nulla.ActivityPub alias Nulla.Models.Actor - alias Nulla.Models.InstanceSettings def index(conn, %{"resource" => resource}) do case Regex.run(~r/^acct:(.+)@(.+)$/, resource) do - [_, username, domain] -> - case Actor.get_actor(preferredUsername: username, domain: domain) do + [_, preferredUsername, actor_domain] -> + case Actor.get_actor(preferredUsername: preferredUsername, domain: actor_domain) do nil -> conn |> put_resp_content_type("text/plain") |> send_resp(404, "") %Actor{} = actor -> - instance_settings = InstanceSettings.get_instance_settings!() + domain = NullaWeb.Endpoint.host() - if domain == instance_settings.domain do + if actor_domain == domain do json(conn, ActivityPub.webfinger(actor)) else conn diff --git a/priv/repo/migrations/20250527054942_create_instance_settings.exs b/priv/repo/migrations/20250527054942_create_instance_settings.exs index e818f66..4a132be 100644 --- a/priv/repo/migrations/20250527054942_create_instance_settings.exs +++ b/priv/repo/migrations/20250527054942_create_instance_settings.exs @@ -6,7 +6,6 @@ defmodule Nulla.Repo.Migrations.CreateInstanceSettings do add :id, :integer, primary_key: true add :name, :string, default: "Nulla", null: false add :description, :text, default: "Freedom Social Network", null: false - add :domain, :string, default: "localhost", null: false add :registration, :boolean, default: false, null: false add :max_characters, :integer, default: 5000, null: false add :max_upload_size, :integer, default: 50, null: false @@ -25,20 +24,15 @@ defmodule Nulla.Repo.Migrations.CreateInstanceSettings do {public_key, private_key} = Nulla.KeyGen.gen() now = DateTime.utc_now() - domain = - Application.get_env(:nulla, NullaWeb.Endpoint, []) - |> Keyword.get(:url, []) - |> Keyword.get(:host, "localhost") - esc = fn str -> "'#{String.replace(str, "'", "''")}'" end sql = """ INSERT INTO instance_settings ( - id, name, description, domain, registration, + id, name, description, registration, max_characters, max_upload_size, api_limit, public_key, private_key, inserted_at, updated_at ) VALUES ( - 1, 'Nulla', 'Freedom Social Network', '#{domain}', false, + 1, 'Nulla', 'Freedom Social Network', false, 5000, 50, 100, #{esc.(public_key)}, #{esc.(private_key)}, '#{now}', '#{now}'