1 defmodule Pleroma.Web.Router do
2 use Pleroma.Web, :router
5 plug(:accepts, ["json"])
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)
18 pipeline :authenticated_api do
19 plug(:accepts, ["json"])
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)
32 pipeline :admin_api do
33 plug(:accepts, ["json"])
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)
48 pipeline :mastodon_html do
49 plug(:accepts, ["html"])
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)
62 pipeline :pleroma_html do
63 plug(:accepts, ["html"])
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)
73 pipeline :well_known do
74 plug(:accepts, ["json", "jrd+json", "xml", "xrd+xml"])
78 plug(:accepts, ["json", "xml"])
82 plug(:accepts, ["html", "json"])
85 pipeline :pleroma_api do
86 plug(:accepts, ["html", "json"])
89 pipeline :mailbox_preview do
90 plug(:accepts, ["html"])
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'"
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)
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)
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)
118 post("/relay", AdminAPIController, :relay_follow)
119 delete("/relay", AdminAPIController, :relay_unfollow)
121 get("/invite_token", AdminAPIController, :get_invite_token)
122 post("/email_invite", AdminAPIController, :email_invite)
124 get("/password_reset", AdminAPIController, :get_password_reset)
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)
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)
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)
148 scope "/api/v1", Pleroma.Web.MastodonAPI do
149 pipe_through(:authenticated_api)
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)
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)
167 post("/follows", MastodonAPIController, :follow)
169 get("/blocks", MastodonAPIController, :blocks)
171 get("/mutes", MastodonAPIController, :empty_array)
173 get("/timelines/home", MastodonAPIController, :home_timeline)
175 get("/timelines/direct", MastodonAPIController, :dm_timeline)
177 get("/favourites", MastodonAPIController, :favourites)
179 post("/statuses", MastodonAPIController, :post_status)
180 delete("/statuses/:id", MastodonAPIController, :delete_status)
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)
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)
192 post("/media", MastodonAPIController, :upload)
193 put("/media/:id", MastodonAPIController, :update_media)
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)
204 get("/domain_blocks", MastodonAPIController, :domain_blocks)
205 post("/domain_blocks", MastodonAPIController, :block_domain)
206 delete("/domain_blocks", MastodonAPIController, :unblock_domain)
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)
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)
219 get("/suggestions", MastodonAPIController, :suggestions)
221 get("/endorsements", MastodonAPIController, :empty_array)
224 scope "/api/web", Pleroma.Web.MastodonAPI do
225 pipe_through(:authenticated_api)
227 put("/settings", MastodonAPIController, :put_settings)
230 scope "/api/v1", Pleroma.Web.MastodonAPI do
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)
237 get("/timelines/public", MastodonAPIController, :public_timeline)
238 get("/timelines/tag/:tag", MastodonAPIController, :hashtag_timeline)
239 get("/timelines/list/:list_id", MastodonAPIController, :list_timeline)
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)
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)
252 get("/trends", MastodonAPIController, :empty_array)
254 get("/search", MastodonAPIController, :search)
257 scope "/api/v2", Pleroma.Web.MastodonAPI do
259 get("/search", MastodonAPIController, :search2)
262 scope "/api", Pleroma.Web do
263 pipe_through(:config)
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)
271 scope "/api", Pleroma.Web do
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)
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)
283 post("/account/register", TwitterAPI.Controller, :register)
284 post("/account/password_reset", TwitterAPI.Controller, :password_reset)
286 get("/search", TwitterAPI.Controller, :search)
287 get("/statusnet/tags/timeline/:tag", TwitterAPI.Controller, :public_and_external_timeline)
290 scope "/api", Pleroma.Web do
293 get("/statuses/public_timeline", TwitterAPI.Controller, :public_timeline)
296 "/statuses/public_and_external_timeline",
297 TwitterAPI.Controller,
298 :public_and_external_timeline
301 get("/statuses/networkpublic_timeline", TwitterAPI.Controller, :public_and_external_timeline)
304 scope "/api", Pleroma.Web, as: :twitter_api_search do
306 get("/pleroma/search_user", TwitterAPI.Controller, :search_user)
309 scope "/api", Pleroma.Web, as: :authenticated_twitter_api do
310 pipe_through(:authenticated_api)
312 get("/account/verify_credentials", TwitterAPI.Controller, :verify_credentials)
313 post("/account/verify_credentials", TwitterAPI.Controller, :verify_credentials)
315 post("/account/update_profile", TwitterAPI.Controller, :update_profile)
316 post("/account/update_profile_banner", TwitterAPI.Controller, :update_banner)
317 post("/qvitter/update_background_image", TwitterAPI.Controller, :update_background)
319 get("/statuses/home_timeline", TwitterAPI.Controller, :friends_timeline)
320 get("/statuses/friends_timeline", TwitterAPI.Controller, :friends_timeline)
321 get("/statuses/mentions", TwitterAPI.Controller, :mentions_timeline)
322 get("/statuses/mentions_timeline", TwitterAPI.Controller, :mentions_timeline)
323 get("/statuses/dm_timeline", TwitterAPI.Controller, :dm_timeline)
324 get("/qvitter/statuses/notifications", TwitterAPI.Controller, :notifications)
326 # XXX: this is really a pleroma API, but we want to keep the pleroma namespace clean
328 post("/qvitter/statuses/notifications/read", TwitterAPI.Controller, :notifications_read)
330 post("/statuses/update", TwitterAPI.Controller, :status_update)
331 post("/statuses/retweet/:id", TwitterAPI.Controller, :retweet)
332 post("/statuses/unretweet/:id", TwitterAPI.Controller, :unretweet)
333 post("/statuses/destroy/:id", TwitterAPI.Controller, :delete_post)
335 get("/pleroma/friend_requests", TwitterAPI.Controller, :friend_requests)
336 post("/pleroma/friendships/approve", TwitterAPI.Controller, :approve_friend_request)
337 post("/pleroma/friendships/deny", TwitterAPI.Controller, :deny_friend_request)
339 post("/friendships/create", TwitterAPI.Controller, :follow)
340 post("/friendships/destroy", TwitterAPI.Controller, :unfollow)
341 post("/blocks/create", TwitterAPI.Controller, :block)
342 post("/blocks/destroy", TwitterAPI.Controller, :unblock)
344 post("/statusnet/media/upload", TwitterAPI.Controller, :upload)
345 post("/media/upload", TwitterAPI.Controller, :upload_json)
346 post("/media/metadata/create", TwitterAPI.Controller, :update_media)
348 post("/favorites/create/:id", TwitterAPI.Controller, :favorite)
349 post("/favorites/create", TwitterAPI.Controller, :favorite)
350 post("/favorites/destroy/:id", TwitterAPI.Controller, :unfavorite)
352 post("/qvitter/update_avatar", TwitterAPI.Controller, :update_avatar)
354 get("/friends/ids", TwitterAPI.Controller, :friends_ids)
355 get("/friendships/no_retweets/ids", TwitterAPI.Controller, :empty_array)
357 get("/mutes/users/ids", TwitterAPI.Controller, :empty_array)
358 get("/qvitter/mutes", TwitterAPI.Controller, :raw_empty_array)
360 get("/externalprofile/show", TwitterAPI.Controller, :external_profile)
363 pipeline :ap_relay do
364 plug(:accepts, ["activity+json"])
368 plug(:accepts, ["xml", "atom", "html", "activity+json"])
371 scope "/", Pleroma.Web do
372 pipe_through(:ostatus)
374 get("/objects/:uuid", OStatus.OStatusController, :object)
375 get("/activities/:uuid", OStatus.OStatusController, :activity)
376 get("/notice/:id", OStatus.OStatusController, :notice)
377 get("/users/:nickname/feed", OStatus.OStatusController, :feed)
378 get("/users/:nickname", OStatus.OStatusController, :feed_redirect)
380 post("/users/:nickname/salmon", OStatus.OStatusController, :salmon_incoming)
381 post("/push/hub/:nickname", Websub.WebsubController, :websub_subscription_request)
382 get("/push/subscriptions/:id", Websub.WebsubController, :websub_subscription_confirmation)
383 post("/push/subscriptions/:id", Websub.WebsubController, :websub_incoming)
386 pipeline :activitypub do
387 plug(:accepts, ["activity+json"])
388 plug(Pleroma.Web.Plugs.HTTPSignaturePlug)
391 scope "/", Pleroma.Web.ActivityPub do
392 # XXX: not really ostatus
393 pipe_through(:ostatus)
395 get("/users/:nickname/followers", ActivityPubController, :followers)
396 get("/users/:nickname/following", ActivityPubController, :following)
397 get("/users/:nickname/outbox", ActivityPubController, :outbox)
400 scope "/relay", Pleroma.Web.ActivityPub do
401 pipe_through(:ap_relay)
402 get("/", ActivityPubController, :relay)
405 scope "/", Pleroma.Web.ActivityPub do
406 pipe_through(:activitypub)
407 post("/users/:nickname/inbox", ActivityPubController, :inbox)
408 post("/inbox", ActivityPubController, :inbox)
411 scope "/.well-known", Pleroma.Web do
412 pipe_through(:well_known)
414 get("/host-meta", WebFinger.WebFingerController, :host_meta)
415 get("/webfinger", WebFinger.WebFingerController, :webfinger)
416 get("/nodeinfo", Nodeinfo.NodeinfoController, :schemas)
419 scope "/nodeinfo", Pleroma.Web do
420 get("/:version", Nodeinfo.NodeinfoController, :nodeinfo)
423 scope "/", Pleroma.Web.MastodonAPI do
424 pipe_through(:mastodon_html)
426 get("/web/login", MastodonAPIController, :login)
427 post("/web/login", MastodonAPIController, :login_post)
428 get("/web/*path", MastodonAPIController, :index)
429 delete("/auth/sign_out", MastodonAPIController, :logout)
432 pipeline :remote_media do
435 scope "/proxy/", Pleroma.Web.MediaProxy do
436 pipe_through(:remote_media)
437 get("/:sig/:url", MediaProxyController, :remote)
438 get("/:sig/:url/:filename", MediaProxyController, :remote)
441 if Mix.env() == :dev do
443 pipe_through([:mailbox_preview])
445 forward("/mailbox", Plug.Swoosh.MailboxPreview, base_path: "/dev/mailbox")
449 scope "/", Fallback do
450 get("/registration/:token", RedirectController, :registration_page)
451 get("/*path", RedirectController, :redirector)
453 options("/*path", RedirectController, :empty)
457 defmodule Fallback.RedirectController do
458 use Pleroma.Web, :controller
460 def redirector(conn, _params) do
462 |> put_resp_content_type("text/html")
463 |> send_file(200, Pleroma.Plugs.InstanceStatic.file_path("index.html"))
466 def registration_page(conn, params) do
467 redirector(conn, params)
470 def empty(conn, _params) do