Add user route
This commit is contained in:
parent
6feba31ff3
commit
541e329dc4
|
@ -27,6 +27,11 @@ defmodule Clacks.Actor do
|
|||
|> validate_required([:ap_id, :nickname, :local, :data])
|
||||
end
|
||||
|
||||
@spec get_by_nickanme(nickname :: String.t()) :: t() | nil
|
||||
def get_by_nickanme(nickname) do
|
||||
Repo.one(from a in __MODULE__, where: a.nickname == ^nickname)
|
||||
end
|
||||
|
||||
@spec get_by_ap_id(ap_id :: String.t(), force_refetch :: boolean()) :: t() | nil
|
||||
def get_by_ap_id(ap_id, force_refetch \\ false) do
|
||||
if force_refetch do
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
defmodule ClacksWeb.ActorController do
|
||||
use ClacksWeb, :controller
|
||||
alias Clacks.{Repo, Actor}
|
||||
import Ecto.Query
|
||||
|
||||
def get(conn, %{"nickname" => nickname}) do
|
||||
case Actor.get_by_nickanme(nickname) do
|
||||
%Actor{local: true, data: data} ->
|
||||
conn
|
||||
|> put_resp_header("content-type", "application/activity+json")
|
||||
|> json(data)
|
||||
|
||||
%Actor{local: false, ap_id: ap_id} ->
|
||||
conn
|
||||
|> redirect(external: ap_id)
|
||||
|
||||
_ ->
|
||||
conn
|
||||
|> put_status(404)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -15,14 +15,13 @@ defmodule ClacksWeb.Router do
|
|||
|
||||
scope "/", ClacksWeb do
|
||||
pipe_through :browser
|
||||
|
||||
get "/", PageController, :index
|
||||
end
|
||||
|
||||
scope "/", ClacksWeb do
|
||||
pipe_through :activitypub
|
||||
|
||||
get "/objects/:id", ObjectsController, :get
|
||||
get "/users/:nickname", ActorController, :get
|
||||
end
|
||||
|
||||
# Other scopes may use custom stacks.
|
||||
|
|
Loading…
Reference in New Issue