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