Add user timeline fetching without credentials
[akkoma] / lib / pleroma / web / router.ex
1 defmodule Pleroma.Web.Router do
2 use Pleroma.Web, :router
3
4 alias Pleroma.{Repo, User}
5
6 def user_fetcher(username) do
7 {:ok, Repo.get_by(User, %{nickname: username})}
8 end
9
10 pipeline :api do
11 plug :accepts, ["json"]
12 plug :fetch_session
13 plug Pleroma.Plugs.AuthenticationPlug, %{fetcher: &Pleroma.Web.Router.user_fetcher/1, optional: true}
14 end
15
16 pipeline :authenticated_api do
17 plug :accepts, ["json"]
18 plug :fetch_session
19 plug Pleroma.Plugs.AuthenticationPlug, %{fetcher: &Pleroma.Web.Router.user_fetcher/1}
20 end
21
22 scope "/api", Pleroma.Web do
23 pipe_through :api
24 get "/statuses/public_timeline", TwitterAPI.Controller, :public_timeline
25 get "/statuses/public_and_external_timeline", TwitterAPI.Controller, :public_timeline
26 get "/statuses/user_timeline", TwitterAPI.Controller, :user_timeline
27 get "/statuses/show/:id", TwitterAPI.Controller, :fetch_status
28 get "/statusnet/conversation/:id", TwitterAPI.Controller, :fetch_conversation
29 get "/statusnet/config", TwitterAPI.Controller, :config
30 post "/account/register", TwitterAPI.Controller, :register
31 end
32
33 scope "/api", Pleroma.Web do
34 pipe_through :authenticated_api
35
36 get "/account/verify_credentials", TwitterAPI.Controller, :verify_credentials
37 post "/account/verify_credentials", TwitterAPI.Controller, :verify_credentials
38 post "/statuses/update", TwitterAPI.Controller, :status_update
39 get "/statuses/home_timeline", TwitterAPI.Controller, :friends_timeline
40 get "/statuses/friends_timeline", TwitterAPI.Controller, :friends_timeline
41 post "/friendships/create", TwitterAPI.Controller, :follow
42 post "/friendships/destroy", TwitterAPI.Controller, :unfollow
43 post "/statusnet/media/upload", TwitterAPI.Controller, :upload
44 post "/media/upload", TwitterAPI.Controller, :upload_json
45 post "/favorites/create/:id", TwitterAPI.Controller, :favorite
46 post "/favorites/create", TwitterAPI.Controller, :favorite
47 post "/favorites/destroy/:id", TwitterAPI.Controller, :unfavorite
48 post "/statuses/retweet/:id", TwitterAPI.Controller, :retweet
49 end
50 end