Merge branch 'develop' into feature/compat/push-subscriptions
[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 pipeline :api do
7 plug(:accepts, ["json"])
8 plug(:fetch_session)
9 plug(Pleroma.Plugs.OAuthPlug)
10 plug(Pleroma.Plugs.BasicAuthDecoderPlug)
11 plug(Pleroma.Plugs.UserFetcherPlug)
12 plug(Pleroma.Plugs.SessionAuthenticationPlug)
13 plug(Pleroma.Plugs.LegacyAuthenticationPlug)
14 plug(Pleroma.Plugs.AuthenticationPlug)
15 plug(Pleroma.Plugs.UserEnabledPlug)
16 plug(Pleroma.Plugs.SetUserSessionIdPlug)
17 plug(Pleroma.Plugs.EnsureUserKeyPlug)
18 end
19
20 pipeline :authenticated_api do
21 plug(:accepts, ["json"])
22 plug(:fetch_session)
23 plug(Pleroma.Plugs.OAuthPlug)
24 plug(Pleroma.Plugs.BasicAuthDecoderPlug)
25 plug(Pleroma.Plugs.UserFetcherPlug)
26 plug(Pleroma.Plugs.SessionAuthenticationPlug)
27 plug(Pleroma.Plugs.LegacyAuthenticationPlug)
28 plug(Pleroma.Plugs.AuthenticationPlug)
29 plug(Pleroma.Plugs.UserEnabledPlug)
30 plug(Pleroma.Plugs.SetUserSessionIdPlug)
31 plug(Pleroma.Plugs.EnsureAuthenticatedPlug)
32 end
33
34 pipeline :admin_api do
35 plug(:accepts, ["json"])
36 plug(:fetch_session)
37 plug(Pleroma.Plugs.OAuthPlug)
38 plug(Pleroma.Plugs.BasicAuthDecoderPlug)
39 plug(Pleroma.Plugs.UserFetcherPlug)
40 plug(Pleroma.Plugs.SessionAuthenticationPlug)
41 plug(Pleroma.Plugs.LegacyAuthenticationPlug)
42 plug(Pleroma.Plugs.AuthenticationPlug)
43 plug(Pleroma.Plugs.UserEnabledPlug)
44 plug(Pleroma.Plugs.SetUserSessionIdPlug)
45 plug(Pleroma.Plugs.EnsureAuthenticatedPlug)
46 plug(Pleroma.Plugs.UserIsAdminPlug)
47 end
48
49 pipeline :mastodon_html do
50 plug(:accepts, ["html"])
51 plug(:fetch_session)
52 plug(Pleroma.Plugs.OAuthPlug)
53 plug(Pleroma.Plugs.BasicAuthDecoderPlug)
54 plug(Pleroma.Plugs.UserFetcherPlug)
55 plug(Pleroma.Plugs.SessionAuthenticationPlug)
56 plug(Pleroma.Plugs.LegacyAuthenticationPlug)
57 plug(Pleroma.Plugs.AuthenticationPlug)
58 plug(Pleroma.Plugs.UserEnabledPlug)
59 plug(Pleroma.Plugs.SetUserSessionIdPlug)
60 plug(Pleroma.Plugs.EnsureUserKeyPlug)
61 end
62
63 pipeline :pleroma_html do
64 plug(:accepts, ["html"])
65 plug(:fetch_session)
66 plug(Pleroma.Plugs.OAuthPlug)
67 plug(Pleroma.Plugs.BasicAuthDecoderPlug)
68 plug(Pleroma.Plugs.UserFetcherPlug)
69 plug(Pleroma.Plugs.SessionAuthenticationPlug)
70 plug(Pleroma.Plugs.AuthenticationPlug)
71 plug(Pleroma.Plugs.EnsureUserKeyPlug)
72 end
73
74 pipeline :well_known do
75 plug(:accepts, ["json", "jrd+json", "xml", "xrd+xml"])
76 end
77
78 pipeline :config do
79 plug(:accepts, ["json", "xml"])
80 end
81
82 pipeline :oauth do
83 plug(:accepts, ["html", "json"])
84 end
85
86 pipeline :pleroma_api do
87 plug(:accepts, ["html", "json"])
88 end
89
90 scope "/api/pleroma", Pleroma.Web.TwitterAPI do
91 pipe_through(:pleroma_api)
92 get("/password_reset/:token", UtilController, :show_password_reset)
93 post("/password_reset", UtilController, :password_reset)
94 get("/emoji", UtilController, :emoji)
95 end
96
97 scope "/api/pleroma/admin", Pleroma.Web.AdminAPI do
98 pipe_through(:admin_api)
99 delete("/user", AdminAPIController, :user_delete)
100 post("/user", AdminAPIController, :user_create)
101
102 get("/permission_group/:nickname", AdminAPIController, :right_get)
103 get("/permission_group/:nickname/:permission_group", AdminAPIController, :right_get)
104 post("/permission_group/:nickname/:permission_group", AdminAPIController, :right_add)
105 delete("/permission_group/:nickname/:permission_group", AdminAPIController, :right_delete)
106
107 post("/relay", AdminAPIController, :relay_follow)
108 delete("/relay", AdminAPIController, :relay_unfollow)
109
110 get("/invite_token", AdminAPIController, :get_invite_token)
111 get("/password_reset", AdminAPIController, :get_password_reset)
112 end
113
114 scope "/", Pleroma.Web.TwitterAPI do
115 pipe_through(:pleroma_html)
116 get("/ostatus_subscribe", UtilController, :remote_follow)
117 post("/ostatus_subscribe", UtilController, :do_remote_follow)
118 post("/main/ostatus", UtilController, :remote_subscribe)
119 end
120
121 scope "/api/pleroma", Pleroma.Web.TwitterAPI do
122 pipe_through(:authenticated_api)
123 post("/follow_import", UtilController, :follow_import)
124 post("/change_password", UtilController, :change_password)
125 post("/delete_account", UtilController, :delete_account)
126 end
127
128 scope "/oauth", Pleroma.Web.OAuth do
129 get("/authorize", OAuthController, :authorize)
130 post("/authorize", OAuthController, :create_authorization)
131 post("/token", OAuthController, :token_exchange)
132 post("/revoke", OAuthController, :token_revoke)
133 end
134
135 scope "/api/v1", Pleroma.Web.MastodonAPI do
136 pipe_through(:authenticated_api)
137
138 patch("/accounts/update_credentials", MastodonAPIController, :update_credentials)
139 get("/accounts/verify_credentials", MastodonAPIController, :verify_credentials)
140 get("/accounts/relationships", MastodonAPIController, :relationships)
141 get("/accounts/search", MastodonAPIController, :account_search)
142 post("/accounts/:id/follow", MastodonAPIController, :follow)
143 post("/accounts/:id/unfollow", MastodonAPIController, :unfollow)
144 post("/accounts/:id/block", MastodonAPIController, :block)
145 post("/accounts/:id/unblock", MastodonAPIController, :unblock)
146 post("/accounts/:id/mute", MastodonAPIController, :relationship_noop)
147 post("/accounts/:id/unmute", MastodonAPIController, :relationship_noop)
148 get("/accounts/:id/lists", MastodonAPIController, :account_lists)
149
150 get("/follow_requests", MastodonAPIController, :follow_requests)
151 post("/follow_requests/:id/authorize", MastodonAPIController, :authorize_follow_request)
152 post("/follow_requests/:id/reject", MastodonAPIController, :reject_follow_request)
153
154 post("/follows", MastodonAPIController, :follow)
155
156 get("/blocks", MastodonAPIController, :blocks)
157
158 get("/mutes", MastodonAPIController, :empty_array)
159
160 get("/timelines/home", MastodonAPIController, :home_timeline)
161
162 get("/timelines/direct", MastodonAPIController, :dm_timeline)
163
164 get("/favourites", MastodonAPIController, :favourites)
165
166 post("/statuses", MastodonAPIController, :post_status)
167 delete("/statuses/:id", MastodonAPIController, :delete_status)
168
169 post("/statuses/:id/reblog", MastodonAPIController, :reblog_status)
170 post("/statuses/:id/unreblog", MastodonAPIController, :unreblog_status)
171 post("/statuses/:id/favourite", MastodonAPIController, :fav_status)
172 post("/statuses/:id/unfavourite", MastodonAPIController, :unfav_status)
173
174 post("/notifications/clear", MastodonAPIController, :clear_notifications)
175 post("/notifications/dismiss", MastodonAPIController, :dismiss_notification)
176 get("/notifications", MastodonAPIController, :notifications)
177 get("/notifications/:id", MastodonAPIController, :get_notification)
178
179 post("/media", MastodonAPIController, :upload)
180 put("/media/:id", MastodonAPIController, :update_media)
181
182 get("/lists", MastodonAPIController, :get_lists)
183 get("/lists/:id", MastodonAPIController, :get_list)
184 delete("/lists/:id", MastodonAPIController, :delete_list)
185 post("/lists", MastodonAPIController, :create_list)
186 put("/lists/:id", MastodonAPIController, :rename_list)
187 get("/lists/:id/accounts", MastodonAPIController, :list_accounts)
188 post("/lists/:id/accounts", MastodonAPIController, :add_to_list)
189 delete("/lists/:id/accounts", MastodonAPIController, :remove_from_list)
190
191 get("/domain_blocks", MastodonAPIController, :domain_blocks)
192 post("/domain_blocks", MastodonAPIController, :block_domain)
193 delete("/domain_blocks", MastodonAPIController, :unblock_domain)
194
195 get("/filters", MastodonAPIController, :get_filters)
196 post("/filters", MastodonAPIController, :create_filter)
197 get("/filters/:id", MastodonAPIController, :get_filter)
198 put("/filters/:id", MastodonAPIController, :update_filter)
199 delete("/filters/:id", MastodonAPIController, :delete_filter)
200
201 post("/push/subscription", MastodonAPIController, :create_push_subscription)
202 get("/push/subscription", MastodonAPIController, :get_push_subscription)
203 put("/push/subscription", MastodonAPIController, :update_push_subscription)
204 delete("/push/subscription", MastodonAPIController, :delete_push_subscription)
205
206 get("/suggestions", MastodonAPIController, :suggestions)
207
208 get("/endorsements", MastodonAPIController, :empty_array)
209 end
210
211 scope "/api/web", Pleroma.Web.MastodonAPI do
212 pipe_through(:authenticated_api)
213
214 put("/settings", MastodonAPIController, :put_settings)
215 end
216
217 scope "/api/v1", Pleroma.Web.MastodonAPI do
218 pipe_through(:api)
219 get("/instance", MastodonAPIController, :masto_instance)
220 get("/instance/peers", MastodonAPIController, :peers)
221 post("/apps", MastodonAPIController, :create_app)
222 get("/custom_emojis", MastodonAPIController, :custom_emojis)
223
224 get("/timelines/public", MastodonAPIController, :public_timeline)
225 get("/timelines/tag/:tag", MastodonAPIController, :hashtag_timeline)
226 get("/timelines/list/:list_id", MastodonAPIController, :list_timeline)
227
228 get("/statuses/:id", MastodonAPIController, :get_status)
229 get("/statuses/:id/context", MastodonAPIController, :get_context)
230 get("/statuses/:id/card", MastodonAPIController, :empty_object)
231 get("/statuses/:id/favourited_by", MastodonAPIController, :favourited_by)
232 get("/statuses/:id/reblogged_by", MastodonAPIController, :reblogged_by)
233
234 get("/accounts/:id/statuses", MastodonAPIController, :user_statuses)
235 get("/accounts/:id/followers", MastodonAPIController, :followers)
236 get("/accounts/:id/following", MastodonAPIController, :following)
237 get("/accounts/:id", MastodonAPIController, :user)
238
239 get("/trends", MastodonAPIController, :empty_array)
240
241 get("/search", MastodonAPIController, :search)
242 end
243
244 scope "/api/v2", Pleroma.Web.MastodonAPI do
245 pipe_through(:api)
246 get("/search", MastodonAPIController, :search2)
247 end
248
249 scope "/api", Pleroma.Web do
250 pipe_through(:config)
251
252 get("/help/test", TwitterAPI.UtilController, :help_test)
253 post("/help/test", TwitterAPI.UtilController, :help_test)
254 get("/statusnet/config", TwitterAPI.UtilController, :config)
255 get("/statusnet/version", TwitterAPI.UtilController, :version)
256 end
257
258 scope "/api", Pleroma.Web do
259 pipe_through(:api)
260
261 get("/statuses/user_timeline", TwitterAPI.Controller, :user_timeline)
262 get("/qvitter/statuses/user_timeline", TwitterAPI.Controller, :user_timeline)
263 get("/users/show", TwitterAPI.Controller, :show_user)
264
265 get("/statuses/followers", TwitterAPI.Controller, :followers)
266 get("/statuses/friends", TwitterAPI.Controller, :friends)
267 get("/statuses/show/:id", TwitterAPI.Controller, :fetch_status)
268 get("/statusnet/conversation/:id", TwitterAPI.Controller, :fetch_conversation)
269
270 post("/account/register", TwitterAPI.Controller, :register)
271
272 get("/search", TwitterAPI.Controller, :search)
273 get("/statusnet/tags/timeline/:tag", TwitterAPI.Controller, :public_and_external_timeline)
274 end
275
276 scope "/api", Pleroma.Web do
277 pipe_through(:api)
278
279 get("/statuses/public_timeline", TwitterAPI.Controller, :public_timeline)
280
281 get(
282 "/statuses/public_and_external_timeline",
283 TwitterAPI.Controller,
284 :public_and_external_timeline
285 )
286
287 get("/statuses/networkpublic_timeline", TwitterAPI.Controller, :public_and_external_timeline)
288 end
289
290 scope "/api", Pleroma.Web, as: :twitter_api_search do
291 pipe_through(:api)
292 get("/pleroma/search_user", TwitterAPI.Controller, :search_user)
293 end
294
295 scope "/api", Pleroma.Web, as: :authenticated_twitter_api do
296 pipe_through(:authenticated_api)
297
298 get("/account/verify_credentials", TwitterAPI.Controller, :verify_credentials)
299 post("/account/verify_credentials", TwitterAPI.Controller, :verify_credentials)
300
301 post("/account/update_profile", TwitterAPI.Controller, :update_profile)
302 post("/account/update_profile_banner", TwitterAPI.Controller, :update_banner)
303 post("/qvitter/update_background_image", TwitterAPI.Controller, :update_background)
304
305 post(
306 "/account/most_recent_notification",
307 TwitterAPI.Controller,
308 :update_most_recent_notification
309 )
310
311 get("/statuses/home_timeline", TwitterAPI.Controller, :friends_timeline)
312 get("/statuses/friends_timeline", TwitterAPI.Controller, :friends_timeline)
313 get("/statuses/mentions", TwitterAPI.Controller, :mentions_timeline)
314 get("/statuses/mentions_timeline", TwitterAPI.Controller, :mentions_timeline)
315 get("/statuses/dm_timeline", TwitterAPI.Controller, :dm_timeline)
316 get("/qvitter/statuses/notifications", TwitterAPI.Controller, :notifications)
317
318 # XXX: this is really a pleroma API, but we want to keep the pleroma namespace clean
319 # for now.
320 post("/qvitter/statuses/notifications/read", TwitterAPI.Controller, :notifications_read)
321
322 post("/statuses/update", TwitterAPI.Controller, :status_update)
323 post("/statuses/retweet/:id", TwitterAPI.Controller, :retweet)
324 post("/statuses/unretweet/:id", TwitterAPI.Controller, :unretweet)
325 post("/statuses/destroy/:id", TwitterAPI.Controller, :delete_post)
326
327 get("/pleroma/friend_requests", TwitterAPI.Controller, :friend_requests)
328 post("/pleroma/friendships/approve", TwitterAPI.Controller, :approve_friend_request)
329 post("/pleroma/friendships/deny", TwitterAPI.Controller, :deny_friend_request)
330
331 post("/friendships/create", TwitterAPI.Controller, :follow)
332 post("/friendships/destroy", TwitterAPI.Controller, :unfollow)
333 post("/blocks/create", TwitterAPI.Controller, :block)
334 post("/blocks/destroy", TwitterAPI.Controller, :unblock)
335
336 post("/statusnet/media/upload", TwitterAPI.Controller, :upload)
337 post("/media/upload", TwitterAPI.Controller, :upload_json)
338
339 post("/favorites/create/:id", TwitterAPI.Controller, :favorite)
340 post("/favorites/create", TwitterAPI.Controller, :favorite)
341 post("/favorites/destroy/:id", TwitterAPI.Controller, :unfavorite)
342
343 post("/qvitter/update_avatar", TwitterAPI.Controller, :update_avatar)
344
345 get("/friends/ids", TwitterAPI.Controller, :friends_ids)
346 get("/friendships/no_retweets/ids", TwitterAPI.Controller, :empty_array)
347
348 get("/mutes/users/ids", TwitterAPI.Controller, :empty_array)
349 get("/qvitter/mutes", TwitterAPI.Controller, :raw_empty_array)
350
351 get("/externalprofile/show", TwitterAPI.Controller, :external_profile)
352 end
353
354 pipeline :ap_relay do
355 plug(:accepts, ["activity+json"])
356 end
357
358 pipeline :ostatus do
359 plug(:accepts, ["xml", "atom", "html", "activity+json"])
360 end
361
362 scope "/", Pleroma.Web do
363 pipe_through(:ostatus)
364
365 get("/objects/:uuid", OStatus.OStatusController, :object)
366 get("/activities/:uuid", OStatus.OStatusController, :activity)
367 get("/notice/:id", OStatus.OStatusController, :notice)
368 get("/users/:nickname/feed", OStatus.OStatusController, :feed)
369 get("/users/:nickname", OStatus.OStatusController, :feed_redirect)
370
371 post("/users/:nickname/salmon", OStatus.OStatusController, :salmon_incoming)
372 post("/push/hub/:nickname", Websub.WebsubController, :websub_subscription_request)
373 get("/push/subscriptions/:id", Websub.WebsubController, :websub_subscription_confirmation)
374 post("/push/subscriptions/:id", Websub.WebsubController, :websub_incoming)
375 end
376
377 pipeline :activitypub do
378 plug(:accepts, ["activity+json"])
379 plug(Pleroma.Web.Plugs.HTTPSignaturePlug)
380 end
381
382 scope "/", Pleroma.Web.ActivityPub do
383 # XXX: not really ostatus
384 pipe_through(:ostatus)
385
386 get("/users/:nickname/followers", ActivityPubController, :followers)
387 get("/users/:nickname/following", ActivityPubController, :following)
388 get("/users/:nickname/outbox", ActivityPubController, :outbox)
389 end
390
391 scope "/relay", Pleroma.Web.ActivityPub do
392 pipe_through(:ap_relay)
393 get("/", ActivityPubController, :relay)
394 end
395
396 scope "/", Pleroma.Web.ActivityPub do
397 pipe_through(:activitypub)
398 post("/users/:nickname/inbox", ActivityPubController, :inbox)
399 post("/inbox", ActivityPubController, :inbox)
400 end
401
402 scope "/.well-known", Pleroma.Web do
403 pipe_through(:well_known)
404
405 get("/host-meta", WebFinger.WebFingerController, :host_meta)
406 get("/webfinger", WebFinger.WebFingerController, :webfinger)
407 get("/nodeinfo", Nodeinfo.NodeinfoController, :schemas)
408 end
409
410 scope "/nodeinfo", Pleroma.Web do
411 get("/:version", Nodeinfo.NodeinfoController, :nodeinfo)
412 end
413
414 scope "/", Pleroma.Web.MastodonAPI do
415 pipe_through(:mastodon_html)
416
417 get("/web/login", MastodonAPIController, :login)
418 post("/web/login", MastodonAPIController, :login_post)
419 get("/web/*path", MastodonAPIController, :index)
420 delete("/auth/sign_out", MastodonAPIController, :logout)
421 end
422
423 pipeline :remote_media do
424 end
425
426 scope "/proxy/", Pleroma.Web.MediaProxy do
427 pipe_through(:remote_media)
428 get("/:sig/:url", MediaProxyController, :remote)
429 get("/:sig/:url/:filename", MediaProxyController, :remote)
430 end
431
432 scope "/", Fallback do
433 get("/registration/:token", RedirectController, :registration_page)
434 get("/*path", RedirectController, :redirector)
435
436 options("/*path", RedirectController, :empty)
437 end
438 end
439
440 defmodule Fallback.RedirectController do
441 use Pleroma.Web, :controller
442
443 def redirector(conn, _params) do
444 conn
445 |> put_resp_content_type("text/html")
446 |> send_file(200, Application.app_dir(:pleroma, "priv/static/index.html"))
447 end
448
449 def registration_page(conn, params) do
450 redirector(conn, params)
451 end
452
453 def empty(conn, _params) do
454 conn
455 |> put_status(204)
456 |> text("")
457 end
458 end