postland/lib/postland_web/controllers/webfinger_json.ex
2024-10-26 16:51:05 -05:00

34 lines
918 B
Elixir

defmodule PostlandWeb.WebfingerJSON do
use Phoenix.VerifiedRoutes, endpoint: PostlandWeb.Endpoint, router: PostlandWeb.Router
alias Postland.Accounts
def render("webfinger.json", _assigns) do
user = Accounts.solo_user()
%{
subject: "acct:#{user.username}@#{PostlandWeb.Endpoint.host()}",
links: [
%{
"rel" => "self",
"type" => "application/activity+json",
"href" => url(~p"/actor")
},
%{
"rel" => "http://webfinger.net/rel/profile-page",
"type" => "text/html",
"href" => url(~p"/about")
},
%{
"rel" => "http://webfinger.net/rel/avatar",
"type" => "image/png",
"href" =>
if(user.icon,
do: unverified_url(PostlandWeb.Endpoint, user.icon),
else: url(~p"/images/avatar.png")
)
}
]
}
end
end