d92ee29bab6e36c7d984004486e7598c74969b70
[akkoma] / lib / pleroma / web / router.ex
1 defmodule Pleroma.Web.Router do
2 use Pleroma.Web, :router
3
4 alias Pleroma.{Repo, User, Web.Router}
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: &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: &Router.user_fetcher/1}
20 end
21
22 pipeline :well_known do
23 plug :accepts, ["xml", "xrd+xml"]
24 end
25
26 scope "/api", Pleroma.Web do
27 pipe_through :api
28
29 get "/help/test", TwitterAPI.UtilController, :help_test
30 get "/statusnet/config", TwitterAPI.UtilController, :config
31
32 get "/statuses/public_timeline", TwitterAPI.Controller, :public_timeline
33 get "/statuses/public_and_external_timeline", TwitterAPI.Controller, :public_and_external_timeline
34 get "/statuses/networkpublic_timeline", TwitterAPI.Controller, :public_and_external_timeline
35 get "/statuses/user_timeline", TwitterAPI.Controller, :user_timeline
36 get "/qvitter/statuses/user_timeline", TwitterAPI.Controller, :user_timeline
37
38 get "/statuses/show/:id", TwitterAPI.Controller, :fetch_status
39 get "/statusnet/conversation/:id", TwitterAPI.Controller, :fetch_conversation
40
41 post "/account/register", TwitterAPI.Controller, :register
42
43 get "/externalprofile/show", TwitterAPI.Controller, :external_profile
44 end
45
46 scope "/api", Pleroma.Web do
47 pipe_through :authenticated_api
48
49 get "/account/verify_credentials", TwitterAPI.Controller, :verify_credentials
50 post "/account/verify_credentials", TwitterAPI.Controller, :verify_credentials
51
52 post "/account/most_recent_notification", TwitterAPI.Controller, :update_most_recent_notification
53
54 get "/statuses/home_timeline", TwitterAPI.Controller, :friends_timeline
55 get "/statuses/friends_timeline", TwitterAPI.Controller, :friends_timeline
56 get "/statuses/mentions", TwitterAPI.Controller, :mentions_timeline
57 get "/statuses/mentions_timeline", TwitterAPI.Controller, :mentions_timeline
58
59 post "/statuses/update", TwitterAPI.Controller, :status_update
60 post "/statuses/retweet/:id", TwitterAPI.Controller, :retweet
61
62 post "/friendships/create", TwitterAPI.Controller, :follow
63 post "/friendships/destroy", TwitterAPI.Controller, :unfollow
64
65 post "/statusnet/media/upload", TwitterAPI.Controller, :upload
66 post "/media/upload", TwitterAPI.Controller, :upload_json
67
68 post "/favorites/create/:id", TwitterAPI.Controller, :favorite
69 post "/favorites/create", TwitterAPI.Controller, :favorite
70 post "/favorites/destroy/:id", TwitterAPI.Controller, :unfavorite
71
72 post "/qvitter/update_avatar", TwitterAPI.Controller, :update_avatar
73 end
74
75 pipeline :ostatus do
76 plug :accepts, ["xml", "atom", "html"]
77 end
78
79 scope "/", Pleroma.Web do
80 pipe_through :ostatus
81
82 get "/objects/:uuid", OStatus.OStatusController, :object
83 get "/activities/:uuid", OStatus.OStatusController, :activity
84
85 get "/users/:nickname/feed", OStatus.OStatusController, :feed
86 get "/users/:nickname", OStatus.OStatusController, :feed_redirect
87 post "/users/:nickname/salmon", OStatus.OStatusController, :salmon_incoming
88 post "/push/hub/:nickname", Websub.WebsubController, :websub_subscription_request
89 get "/push/subscriptions/:id", Websub.WebsubController, :websub_subscription_confirmation
90 post "/push/subscriptions/:id", Websub.WebsubController, :websub_incoming
91 end
92
93 scope "/.well-known", Pleroma.Web do
94 pipe_through :well_known
95
96 get "/host-meta", WebFinger.WebFingerController, :host_meta
97 get "/webfinger", WebFinger.WebFingerController, :webfinger
98 end
99
100 scope "/", Fallback do
101 get "/*path", RedirectController, :redirector
102 end
103 end
104
105 defmodule Fallback.RedirectController do
106 use Pleroma.Web, :controller
107 def redirector(conn, _params), do: (if Mix.env != :test, do: send_file(conn, 200, "priv/static/index.html"))
108 end