diff --git a/lib/nulla/activitypub.ex b/lib/nulla/activitypub.ex index 0f7dd73..838aae4 100644 --- a/lib/nulla/activitypub.ex +++ b/lib/nulla/activitypub.ex @@ -209,7 +209,7 @@ defmodule Nulla.ActivityPub do @spec webfinger(Actor.t()) :: Jason.OrderedObject.t() def webfinger(actor) do - data = [ + Jason.OrderedObject.new( subject: "#{actor.preferredUsername}@#{actor.domain}", aliases: [ "https://#{actor.domain}/@#{actor.preferredUsername}", @@ -225,27 +225,14 @@ defmodule Nulla.ActivityPub do rel: "self", type: "application/activity+json", href: "https://#{actor.domain}/users/#{actor.preferredUsername}" + ), + Jason.OrderedObject.new( + rel: "http://webfinger.net/rel/avatar", + type: actor.icon.mediaType, + href: actor.icon.url ) ] - ] - - data = - if actor.icon do - Keyword.update!(data, :links, fn links -> - links ++ - [ - Jason.OrderedObject.new( - rel: "http://webfinger.net/rel/avatar", - type: Map.get(actor.icon, :mediaType), - href: Map.get(actor.icon, :url) - ) - ] - end) - else - data - end - - Jason.OrderedObject.new(data) + ) end @spec nodeinfo(String.t()) :: Jason.OrderedObject.t() diff --git a/lib/nulla/models/actor.ex b/lib/nulla/models/actor.ex index d77fcb0..f1c58a1 100644 --- a/lib/nulla/models/actor.ex +++ b/lib/nulla/models/actor.ex @@ -29,8 +29,8 @@ defmodule Nulla.Models.Actor do field :tag, {:array, :map}, default: [] field :attachment, {:array, :map}, default: [] field :endpoints, :map - field :icon, :map - field :image, :map + field :icon, :map, default: %{} + field :image, :map, default: %{} field :vcard_bday, :date field :vcard_Address, :string diff --git a/lib/nulla_web/controllers/webfinger_controller.ex b/lib/nulla_web/controllers/webfinger_controller.ex index a36e6b3..cc7854f 100644 --- a/lib/nulla_web/controllers/webfinger_controller.ex +++ b/lib/nulla_web/controllers/webfinger_controller.ex @@ -5,13 +5,13 @@ defmodule NullaWeb.WebfingerController do alias Nulla.Models.InstanceSettings def index(conn, %{"resource" => resource}) do - case Regex.run(~r/^acct:(.+)@(.+)$/, resource) do + case Regex.run(~r/^acct:([^@]+)@(.+)$/, resource) do [_, username, domain] -> case Actor.get_actor(username, domain) do nil -> conn - |> put_resp_content_type("text/plain") - |> send_resp(404, "") + |> put_status(:not_found) + |> json(%{error: "Not Found"}) %Actor{} = actor -> instance_settings = InstanceSettings.get_instance_settings!() @@ -20,21 +20,15 @@ defmodule NullaWeb.WebfingerController do json(conn, ActivityPub.webfinger(actor)) else conn - |> put_resp_content_type("text/plain") - |> send_resp(404, "") + |> put_status(:not_found) + |> json(%{error: "Not Found"}) end end _ -> conn - |> put_resp_content_type("text/plain") - |> send_resp(400, "") + |> put_status(:bad_request) + |> json(%{error: "Bad Request"}) end end - - def index(conn, _params) do - conn - |> put_resp_content_type("text/plain") - |> send_resp(400, "") - end end diff --git a/priv/repo/migrations/20250615130714_create_actors.exs b/priv/repo/migrations/20250615130714_create_actors.exs index 8098ce9..da2ff37 100644 --- a/priv/repo/migrations/20250615130714_create_actors.exs +++ b/priv/repo/migrations/20250615130714_create_actors.exs @@ -26,8 +26,8 @@ defmodule Nulla.Repo.Migrations.CreateActors do add :tag, {:array, :map}, default: [] add :attachment, {:array, :map}, default: [] add :endpoints, :map - add :icon, :map - add :image, :map + add :icon, :map, default: %{} + add :image, :map, default: %{} add :vcard_bday, :date add :vcard_Address, :string end