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