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