Add Webfinger
This commit is contained in:
parent
82c641035a
commit
b63eaa34be
4 changed files with 51 additions and 0 deletions
34
lib/nulla_web/controllers/webfinger_controller.ex
Normal file
34
lib/nulla_web/controllers/webfinger_controller.ex
Normal file
|
@ -0,0 +1,34 @@
|
|||
defmodule NullaWeb.WebfingerController do
|
||||
use NullaWeb, :controller
|
||||
alias Nulla.Repo
|
||||
alias Nulla.ActivityPub
|
||||
alias Nulla.Models.User
|
||||
alias Nulla.Models.InstanceSettings
|
||||
|
||||
def show(conn, %{"resource" => resource}) do
|
||||
case Regex.run(~r/^acct:([^@]+)@(.+)$/, resource) do
|
||||
[_, username, domain] ->
|
||||
case User.get_user_by_username(username) do
|
||||
nil ->
|
||||
conn
|
||||
|> put_status(:not_found)
|
||||
|> json(%{error: "Not Found"})
|
||||
|
||||
user ->
|
||||
instance_settings = InstanceSettings.get_instance_settings!()
|
||||
|
||||
if domain == instance_settings.domain do
|
||||
json(conn, ActivityPub.webfinger(domain, username, resource))
|
||||
else
|
||||
conn
|
||||
|> put_status(:not_found)
|
||||
|> json(%{error: "Not Found"})
|
||||
end
|
||||
end
|
||||
_ ->
|
||||
conn
|
||||
|> put_status(:bad_request)
|
||||
|> json(%{error: "Bad Request"})
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue