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