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