Merge branch 'develop' into feature/activitypub
[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.OAuthPlug
14 plug Pleroma.Plugs.AuthenticationPlug, %{fetcher: &Router.user_fetcher/1, optional: true}
15 end
16
17 pipeline :authenticated_api do
18 plug :accepts, ["json"]
19 plug :fetch_session
20 plug Pleroma.Plugs.OAuthPlug
21 plug Pleroma.Plugs.AuthenticationPlug, %{fetcher: &Router.user_fetcher/1}
22 end
23
24 pipeline :mastodon_html do
25 plug :accepts, ["html"]
26 plug :fetch_session
27 plug Pleroma.Plugs.OAuthPlug
28 plug Pleroma.Plugs.AuthenticationPlug, %{fetcher: &Router.user_fetcher/1, optional: true}
29 end
30
31 pipeline :pleroma_html do
32 plug :accepts, ["html"]
33 plug :fetch_session
34 plug Pleroma.Plugs.OAuthPlug
35 plug Pleroma.Plugs.AuthenticationPlug, %{fetcher: &Router.user_fetcher/1, optional: true}
36 end
37
38 pipeline :well_known do
39 plug :accepts, ["xml", "xrd+xml"]
40 end
41
42 pipeline :config do
43 plug :accepts, ["json", "xml"]
44 end
45
46 pipeline :oauth do
47 plug :accepts, ["html", "json"]
48 end
49
50 pipeline :pleroma_api do
51 plug :accepts, ["html", "json"]
52 end
53
54 scope "/api/pleroma", Pleroma.Web.TwitterAPI do
55 pipe_through :pleroma_api
56 get "/password_reset/:token", UtilController, :show_password_reset
57 post "/password_reset", UtilController, :password_reset
58 get "/emoji", UtilController, :emoji
59 end
60
61 scope "/", Pleroma.Web.TwitterAPI do
62 pipe_through :pleroma_html
63 get "/ostatus_subscribe", UtilController, :remote_follow
64 post "/ostatus_subscribe", UtilController, :do_remote_follow
65 post "/main/ostatus", UtilController, :remote_subscribe
66 end
67
68 scope "/api/pleroma", Pleroma.Web.TwitterAPI do
69 pipe_through :authenticated_api
70 post "/follow_import", UtilController, :follow_import
71 end
72
73 scope "/oauth", Pleroma.Web.OAuth do
74 get "/authorize", OAuthController, :authorize
75 post "/authorize", OAuthController, :create_authorization
76 post "/token", OAuthController, :token_exchange
77 end
78
79 scope "/api/v1", Pleroma.Web.MastodonAPI do
80 pipe_through :authenticated_api
81
82 patch "/accounts/update_credentials", MastodonAPIController, :update_credentials
83 get "/accounts/verify_credentials", MastodonAPIController, :verify_credentials
84 get "/accounts/relationships", MastodonAPIController, :relationships
85 get "/accounts/search", MastodonAPIController, :account_search
86 post "/accounts/:id/follow", MastodonAPIController, :follow
87 post "/accounts/:id/unfollow", MastodonAPIController, :unfollow
88 post "/accounts/:id/block", MastodonAPIController, :block
89 post "/accounts/:id/unblock", MastodonAPIController, :unblock
90 post "/accounts/:id/mute", MastodonAPIController, :relationship_noop
91 post "/accounts/:id/unmute", MastodonAPIController, :relationship_noop
92
93 post "/follows", MastodonAPIController, :follow
94
95 get "/blocks", MastodonAPIController, :blocks
96
97 get "/domain_blocks", MastodonAPIController, :empty_array
98 get "/follow_requests", MastodonAPIController, :empty_array
99 get "/mutes", MastodonAPIController, :empty_array
100
101 get "/timelines/home", MastodonAPIController, :home_timeline
102
103 get "/favourites", MastodonAPIController, :favourites
104
105 post "/statuses", MastodonAPIController, :post_status
106 delete "/statuses/:id", MastodonAPIController, :delete_status
107
108 post "/statuses/:id/reblog", MastodonAPIController, :reblog_status
109 post "/statuses/:id/favourite", MastodonAPIController, :fav_status
110 post "/statuses/:id/unfavourite", MastodonAPIController, :unfav_status
111
112 post "/notifications/clear", MastodonAPIController, :clear_notifications
113 post "/notifications/dismiss", MastodonAPIController, :dismiss_notification
114 get "/notifications", MastodonAPIController, :notifications
115 get "/notifications/:id", MastodonAPIController, :get_notification
116
117 post "/media", MastodonAPIController, :upload
118 end
119
120 scope "/api/v1", Pleroma.Web.MastodonAPI do
121 pipe_through :api
122 get "/instance", MastodonAPIController, :masto_instance
123 get "/instance/peers", MastodonAPIController, :peers
124 post "/apps", MastodonAPIController, :create_app
125 get "/custom_emojis", MastodonAPIController, :custom_emojis
126
127 get "/timelines/public", MastodonAPIController, :public_timeline
128 get "/timelines/tag/:tag", MastodonAPIController, :hashtag_timeline
129
130 get "/statuses/:id", MastodonAPIController, :get_status
131 get "/statuses/:id/context", MastodonAPIController, :get_context
132 get "/statuses/:id/favourited_by", MastodonAPIController, :favourited_by
133 get "/statuses/:id/reblogged_by", MastodonAPIController, :reblogged_by
134
135 get "/accounts/:id/statuses", MastodonAPIController, :user_statuses
136 get "/accounts/:id/followers", MastodonAPIController, :followers
137 get "/accounts/:id/following", MastodonAPIController, :following
138 get "/accounts/:id", MastodonAPIController, :user
139
140 get "/search", MastodonAPIController, :search
141 end
142
143 scope "/api", Pleroma.Web do
144 pipe_through :config
145
146 get "/help/test", TwitterAPI.UtilController, :help_test
147 post "/help/test", TwitterAPI.UtilController, :help_test
148 get "/statusnet/config", TwitterAPI.UtilController, :config
149 get "/statusnet/version", TwitterAPI.UtilController, :version
150 end
151
152 @instance Application.get_env(:pleroma, :instance)
153 @registrations_open Keyword.get(@instance, :registrations_open)
154
155 scope "/api", Pleroma.Web do
156 pipe_through :api
157
158 get "/statuses/public_timeline", TwitterAPI.Controller, :public_timeline
159 get "/statuses/public_and_external_timeline", TwitterAPI.Controller, :public_and_external_timeline
160 get "/statuses/networkpublic_timeline", TwitterAPI.Controller, :public_and_external_timeline
161 get "/statuses/user_timeline", TwitterAPI.Controller, :user_timeline
162 get "/qvitter/statuses/user_timeline", TwitterAPI.Controller, :user_timeline
163 get "/users/show", TwitterAPI.Controller, :show_user
164
165 get "/statuses/followers", TwitterAPI.Controller, :followers
166 get "/statuses/friends", TwitterAPI.Controller, :friends
167 get "/statuses/show/:id", TwitterAPI.Controller, :fetch_status
168 get "/statusnet/conversation/:id", TwitterAPI.Controller, :fetch_conversation
169
170 if @registrations_open do
171 post "/account/register", TwitterAPI.Controller, :register
172 end
173
174 get "/search", TwitterAPI.Controller, :search
175 get "/statusnet/tags/timeline/:tag", TwitterAPI.Controller, :public_and_external_timeline
176 end
177
178 scope "/api", Pleroma.Web do
179 pipe_through :authenticated_api
180
181 get "/account/verify_credentials", TwitterAPI.Controller, :verify_credentials
182 post "/account/verify_credentials", TwitterAPI.Controller, :verify_credentials
183
184 post "/account/update_profile", TwitterAPI.Controller, :update_profile
185 post "/account/update_profile_banner", TwitterAPI.Controller, :update_banner
186 post "/qvitter/update_background_image", TwitterAPI.Controller, :update_background
187
188 post "/account/most_recent_notification", TwitterAPI.Controller, :update_most_recent_notification
189
190 get "/statuses/home_timeline", TwitterAPI.Controller, :friends_timeline
191 get "/statuses/friends_timeline", TwitterAPI.Controller, :friends_timeline
192 get "/statuses/mentions", TwitterAPI.Controller, :mentions_timeline
193 get "/statuses/mentions_timeline", TwitterAPI.Controller, :mentions_timeline
194
195 post "/statuses/update", TwitterAPI.Controller, :status_update
196 post "/statuses/retweet/:id", TwitterAPI.Controller, :retweet
197 post "/statuses/destroy/:id", TwitterAPI.Controller, :delete_post
198
199 post "/friendships/create", TwitterAPI.Controller, :follow
200 post "/friendships/destroy", TwitterAPI.Controller, :unfollow
201 post "/blocks/create", TwitterAPI.Controller, :block
202 post "/blocks/destroy", TwitterAPI.Controller, :unblock
203
204 post "/statusnet/media/upload", TwitterAPI.Controller, :upload
205 post "/media/upload", TwitterAPI.Controller, :upload_json
206
207 post "/favorites/create/:id", TwitterAPI.Controller, :favorite
208 post "/favorites/create", TwitterAPI.Controller, :favorite
209 post "/favorites/destroy/:id", TwitterAPI.Controller, :unfavorite
210
211 post "/qvitter/update_avatar", TwitterAPI.Controller, :update_avatar
212
213 get "/friends/ids", TwitterAPI.Controller, :friends_ids
214 get "/friendships/no_retweets/ids", TwitterAPI.Controller, :empty_array
215
216 get "/mutes/users/ids", TwitterAPI.Controller, :empty_array
217
218 get "/externalprofile/show", TwitterAPI.Controller, :external_profile
219 end
220
221 pipeline :ostatus do
222 plug :accepts, ["xml", "atom", "html", "activity+json"]
223 end
224
225 scope "/", Pleroma.Web do
226 pipe_through :ostatus
227
228 get "/objects/:uuid", OStatus.OStatusController, :object
229 get "/activities/:uuid", OStatus.OStatusController, :activity
230 get "/notice/:id", OStatus.OStatusController, :notice
231
232 get "/users/:nickname/feed", OStatus.OStatusController, :feed
233 get "/users/:nickname", OStatus.OStatusController, :feed_redirect
234 post "/users/:nickname/salmon", OStatus.OStatusController, :salmon_incoming
235 post "/push/hub/:nickname", Websub.WebsubController, :websub_subscription_request
236 get "/push/subscriptions/:id", Websub.WebsubController, :websub_subscription_confirmation
237 post "/push/subscriptions/:id", Websub.WebsubController, :websub_incoming
238 end
239
240 pipeline :activitypub do
241 plug :accepts, ["activity+json"]
242 plug Pleroma.Web.Plugs.HTTPSignaturePlug
243 end
244
245 scope "/", Pleroma.Web.ActivityPub do
246 pipe_through :activitypub
247 post "/users/:nickname/inbox", ActivityPubController, :inbox
248 end
249
250 scope "/.well-known", Pleroma.Web do
251 pipe_through :well_known
252
253 get "/host-meta", WebFinger.WebFingerController, :host_meta
254 get "/webfinger", WebFinger.WebFingerController, :webfinger
255 end
256
257 scope "/", Pleroma.Web.MastodonAPI do
258 pipe_through :mastodon_html
259
260 get "/web/login", MastodonAPIController, :login
261 post "/web/login", MastodonAPIController, :login_post
262 get "/web/*path", MastodonAPIController, :index
263 delete "/auth/sign_out", MastodonAPIController, :logout
264 end
265
266 pipeline :remote_media do
267 plug :accepts, ["html"]
268 end
269 scope "/proxy/", Pleroma.Web.MediaProxy do
270 pipe_through :remote_media
271 get "/:sig/:url", MediaProxyController, :remote
272 end
273
274 scope "/", Fallback do
275 get "/*path", RedirectController, :redirector
276 end
277 end
278
279 defmodule Fallback.RedirectController do
280 use Pleroma.Web, :controller
281 def redirector(conn, _params) do
282 if Mix.env != :test do
283 conn
284 |> put_resp_content_type("text/html")
285 |> send_file(200, "priv/static/index.html")
286 end
287 end
288 end