Browse Source

Add user route

master
Shadowfacts 2 years ago
parent
commit
541e329dc4
Signed by: shadowfacts GPG Key ID: 94A5AB95422746E5
3 changed files with 28 additions and 2 deletions
  1. +5
    -0
      lib/clacks/actor.ex
  2. +22
    -0
      lib/clacks_web/controllers/actor_controller.ex
  3. +1
    -2
      lib/clacks_web/router.ex

+ 5
- 0
lib/clacks/actor.ex View File

@ -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


+ 22
- 0
lib/clacks_web/controllers/actor_controller.ex View File

@ -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

+ 1
- 2
lib/clacks_web/router.ex View File

@ -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…
Cancel
Save