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