1 defmodule Pleroma.Web.Router do
2 use Pleroma.Web, :router
4 alias Pleroma.{Repo, User, Web.Router}
7 plug(:accepts, ["json"])
9 plug(Pleroma.Plugs.OAuthPlug)
10 plug(Pleroma.Plugs.BasicAuthDecoderPlug)
11 plug(Pleroma.Plugs.UserFetcherPlug)
12 plug(Pleroma.Plugs.SessionAuthenticationPlug)
13 plug(Pleroma.Plugs.LegacyAuthenticationPlug)
14 plug(Pleroma.Plugs.AuthenticationPlug)
15 plug(Pleroma.Plugs.UserEnabledPlug)
16 plug(Pleroma.Plugs.SetUserSessionIdPlug)
17 plug(Pleroma.Plugs.EnsureUserKeyPlug)
20 pipeline :authenticated_api do
21 plug(:accepts, ["json"])
23 plug(Pleroma.Plugs.OAuthPlug)
24 plug(Pleroma.Plugs.BasicAuthDecoderPlug)
25 plug(Pleroma.Plugs.UserFetcherPlug)
26 plug(Pleroma.Plugs.SessionAuthenticationPlug)
27 plug(Pleroma.Plugs.LegacyAuthenticationPlug)
28 plug(Pleroma.Plugs.AuthenticationPlug)
29 plug(Pleroma.Plugs.UserEnabledPlug)
30 plug(Pleroma.Plugs.SetUserSessionIdPlug)
31 plug(Pleroma.Plugs.EnsureAuthenticatedPlug)
34 pipeline :mastodon_html do
35 plug(:accepts, ["html"])
37 plug(Pleroma.Plugs.OAuthPlug)
38 plug(Pleroma.Plugs.BasicAuthDecoderPlug)
39 plug(Pleroma.Plugs.UserFetcherPlug)
40 plug(Pleroma.Plugs.SessionAuthenticationPlug)
41 plug(Pleroma.Plugs.LegacyAuthenticationPlug)
42 plug(Pleroma.Plugs.AuthenticationPlug)
43 plug(Pleroma.Plugs.UserEnabledPlug)
44 plug(Pleroma.Plugs.SetUserSessionIdPlug)
45 plug(Pleroma.Plugs.EnsureUserKeyPlug)
48 pipeline :pleroma_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.AuthenticationPlug)
56 plug(Pleroma.Plugs.EnsureUserKeyPlug)
59 pipeline :well_known do
60 plug(:accepts, ["json", "jrd+json", "xml", "xrd+xml"])
64 plug(:accepts, ["json", "xml"])
68 plug(:accepts, ["html", "json"])
71 pipeline :pleroma_api do
72 plug(:accepts, ["html", "json"])
75 scope "/api/pleroma", Pleroma.Web.TwitterAPI do
76 pipe_through(:pleroma_api)
77 get("/password_reset/:token", UtilController, :show_password_reset)
78 post("/password_reset", UtilController, :password_reset)
79 get("/emoji", UtilController, :emoji)
82 scope "/", Pleroma.Web.TwitterAPI do
83 pipe_through(:pleroma_html)
84 get("/ostatus_subscribe", UtilController, :remote_follow)
85 post("/ostatus_subscribe", UtilController, :do_remote_follow)
86 post("/main/ostatus", UtilController, :remote_subscribe)
89 scope "/api/pleroma", Pleroma.Web.TwitterAPI do
90 pipe_through(:authenticated_api)
91 post("/follow_import", UtilController, :follow_import)
92 post("/change_password", UtilController, :change_password)
93 post("/delete_account", UtilController, :delete_account)
96 scope "/oauth", Pleroma.Web.OAuth do
97 get("/authorize", OAuthController, :authorize)
98 post("/authorize", OAuthController, :create_authorization)
99 post("/token", OAuthController, :token_exchange)
100 post("/revoke", OAuthController, :token_revoke)
103 scope "/api/v1", Pleroma.Web.MastodonAPI do
104 pipe_through(:authenticated_api)
106 patch("/accounts/update_credentials", MastodonAPIController, :update_credentials)
107 get("/accounts/verify_credentials", MastodonAPIController, :verify_credentials)
108 get("/accounts/relationships", MastodonAPIController, :relationships)
109 get("/accounts/search", MastodonAPIController, :account_search)
110 post("/accounts/:id/follow", MastodonAPIController, :follow)
111 post("/accounts/:id/unfollow", MastodonAPIController, :unfollow)
112 post("/accounts/:id/block", MastodonAPIController, :block)
113 post("/accounts/:id/unblock", MastodonAPIController, :unblock)
114 post("/accounts/:id/mute", MastodonAPIController, :relationship_noop)
115 post("/accounts/:id/unmute", MastodonAPIController, :relationship_noop)
116 get("/accounts/:id/lists", MastodonAPIController, :account_lists)
118 get("/follow_requests", MastodonAPIController, :follow_requests)
119 post("/follow_requests/:id/authorize", MastodonAPIController, :authorize_follow_request)
120 post("/follow_requests/:id/reject", MastodonAPIController, :reject_follow_request)
122 post("/follows", MastodonAPIController, :follow)
124 get("/blocks", MastodonAPIController, :blocks)
126 get("/mutes", MastodonAPIController, :empty_array)
128 get("/timelines/home", MastodonAPIController, :home_timeline)
130 get("/timelines/direct", MastodonAPIController, :dm_timeline)
132 get("/favourites", MastodonAPIController, :favourites)
134 post("/statuses", MastodonAPIController, :post_status)
135 delete("/statuses/:id", MastodonAPIController, :delete_status)
137 post("/statuses/:id/reblog", MastodonAPIController, :reblog_status)
138 post("/statuses/:id/unreblog", MastodonAPIController, :unreblog_status)
139 post("/statuses/:id/favourite", MastodonAPIController, :fav_status)
140 post("/statuses/:id/unfavourite", MastodonAPIController, :unfav_status)
142 post("/notifications/clear", MastodonAPIController, :clear_notifications)
143 post("/notifications/dismiss", MastodonAPIController, :dismiss_notification)
144 get("/notifications", MastodonAPIController, :notifications)
145 get("/notifications/:id", MastodonAPIController, :get_notification)
147 post("/media", MastodonAPIController, :upload)
148 put("/media/:id", MastodonAPIController, :update_media)
150 get("/lists", MastodonAPIController, :get_lists)
151 get("/lists/:id", MastodonAPIController, :get_list)
152 delete("/lists/:id", MastodonAPIController, :delete_list)
153 post("/lists", MastodonAPIController, :create_list)
154 put("/lists/:id", MastodonAPIController, :rename_list)
155 get("/lists/:id/accounts", MastodonAPIController, :list_accounts)
156 post("/lists/:id/accounts", MastodonAPIController, :add_to_list)
157 delete("/lists/:id/accounts", MastodonAPIController, :remove_from_list)
159 get("/domain_blocks", MastodonAPIController, :domain_blocks)
160 post("/domain_blocks", MastodonAPIController, :block_domain)
161 delete("/domain_blocks", MastodonAPIController, :unblock_domain)
163 get("/filters", MastodonAPIController, :get_filters)
164 post("/filters", MastodonAPIController, :create_filter)
165 get("/filters/:id", MastodonAPIController, :get_filter)
166 put("/filters/:id", MastodonAPIController, :update_filter)
167 delete("/filters/:id", MastodonAPIController, :delete_filter)
169 get("/suggestions", MastodonAPIController, :suggestions)
171 get("/endorsements", MastodonAPIController, :empty_array)
174 scope "/api/web", Pleroma.Web.MastodonAPI do
175 pipe_through(:authenticated_api)
177 put("/settings", MastodonAPIController, :put_settings)
180 scope "/api/v1", Pleroma.Web.MastodonAPI do
182 get("/instance", MastodonAPIController, :masto_instance)
183 get("/instance/peers", MastodonAPIController, :peers)
184 post("/apps", MastodonAPIController, :create_app)
185 get("/custom_emojis", MastodonAPIController, :custom_emojis)
187 get("/timelines/public", MastodonAPIController, :public_timeline)
188 get("/timelines/tag/:tag", MastodonAPIController, :hashtag_timeline)
189 get("/timelines/list/:list_id", MastodonAPIController, :list_timeline)
191 get("/statuses/:id", MastodonAPIController, :get_status)
192 get("/statuses/:id/context", MastodonAPIController, :get_context)
193 get("/statuses/:id/card", MastodonAPIController, :empty_object)
194 get("/statuses/:id/favourited_by", MastodonAPIController, :favourited_by)
195 get("/statuses/:id/reblogged_by", MastodonAPIController, :reblogged_by)
197 get("/accounts/:id/statuses", MastodonAPIController, :user_statuses)
198 get("/accounts/:id/followers", MastodonAPIController, :followers)
199 get("/accounts/:id/following", MastodonAPIController, :following)
200 get("/accounts/:id", MastodonAPIController, :user)
202 get("/trends", MastodonAPIController, :empty_array)
204 get("/search", MastodonAPIController, :search)
207 scope "/api/v2", Pleroma.Web.MastodonAPI do
209 get("/search", MastodonAPIController, :search2)
212 scope "/api", Pleroma.Web do
213 pipe_through(:config)
215 get("/help/test", TwitterAPI.UtilController, :help_test)
216 post("/help/test", TwitterAPI.UtilController, :help_test)
217 get("/statusnet/config", TwitterAPI.UtilController, :config)
218 get("/statusnet/version", TwitterAPI.UtilController, :version)
221 scope "/api", Pleroma.Web do
224 get("/statuses/user_timeline", TwitterAPI.Controller, :user_timeline)
225 get("/qvitter/statuses/user_timeline", TwitterAPI.Controller, :user_timeline)
226 get("/users/show", TwitterAPI.Controller, :show_user)
228 get("/statuses/followers", TwitterAPI.Controller, :followers)
229 get("/statuses/friends", TwitterAPI.Controller, :friends)
230 get("/statuses/show/:id", TwitterAPI.Controller, :fetch_status)
231 get("/statusnet/conversation/:id", TwitterAPI.Controller, :fetch_conversation)
233 post("/account/register", TwitterAPI.Controller, :register)
235 get("/search", TwitterAPI.Controller, :search)
236 get("/statusnet/tags/timeline/:tag", TwitterAPI.Controller, :public_and_external_timeline)
239 scope "/api", Pleroma.Web do
242 get("/statuses/public_timeline", TwitterAPI.Controller, :public_timeline)
245 "/statuses/public_and_external_timeline",
246 TwitterAPI.Controller,
247 :public_and_external_timeline
250 get("/statuses/networkpublic_timeline", TwitterAPI.Controller, :public_and_external_timeline)
254 scope "/api", Pleroma.Web, as: :twitter_api_search do
256 get("/pleroma/search_user", TwitterAPI.Controller, :search_user)
259 scope "/api", Pleroma.Web, as: :authenticated_twitter_api do
260 pipe_through(:authenticated_api)
262 get("/account/verify_credentials", TwitterAPI.Controller, :verify_credentials)
263 post("/account/verify_credentials", TwitterAPI.Controller, :verify_credentials)
265 post("/account/update_profile", TwitterAPI.Controller, :update_profile)
266 post("/account/update_profile_banner", TwitterAPI.Controller, :update_banner)
267 post("/qvitter/update_background_image", TwitterAPI.Controller, :update_background)
270 "/account/most_recent_notification",
271 TwitterAPI.Controller,
272 :update_most_recent_notification
275 get("/statuses/home_timeline", TwitterAPI.Controller, :friends_timeline)
276 get("/statuses/friends_timeline", TwitterAPI.Controller, :friends_timeline)
277 get("/statuses/mentions", TwitterAPI.Controller, :mentions_timeline)
278 get("/statuses/mentions_timeline", TwitterAPI.Controller, :mentions_timeline)
279 get("/statuses/dm_timeline", TwitterAPI.Controller, :dm_timeline)
280 get("/qvitter/statuses/notifications", TwitterAPI.Controller, :notifications)
282 # XXX: this is really a pleroma API, but we want to keep the pleroma namespace clean
284 post("/qvitter/statuses/notifications/read", TwitterAPI.Controller, :notifications_read)
286 post("/statuses/update", TwitterAPI.Controller, :status_update)
287 post("/statuses/retweet/:id", TwitterAPI.Controller, :retweet)
288 post("/statuses/unretweet/:id", TwitterAPI.Controller, :unretweet)
289 post("/statuses/destroy/:id", TwitterAPI.Controller, :delete_post)
291 get("/pleroma/friend_requests", TwitterAPI.Controller, :friend_requests)
292 post("/pleroma/friendships/approve", TwitterAPI.Controller, :approve_friend_request)
293 post("/pleroma/friendships/deny", TwitterAPI.Controller, :deny_friend_request)
295 post("/friendships/create", TwitterAPI.Controller, :follow)
296 post("/friendships/destroy", TwitterAPI.Controller, :unfollow)
297 post("/blocks/create", TwitterAPI.Controller, :block)
298 post("/blocks/destroy", TwitterAPI.Controller, :unblock)
300 post("/statusnet/media/upload", TwitterAPI.Controller, :upload)
301 post("/media/upload", TwitterAPI.Controller, :upload_json)
303 post("/favorites/create/:id", TwitterAPI.Controller, :favorite)
304 post("/favorites/create", TwitterAPI.Controller, :favorite)
305 post("/favorites/destroy/:id", TwitterAPI.Controller, :unfavorite)
307 post("/qvitter/update_avatar", TwitterAPI.Controller, :update_avatar)
309 get("/friends/ids", TwitterAPI.Controller, :friends_ids)
310 get("/friendships/no_retweets/ids", TwitterAPI.Controller, :empty_array)
312 get("/mutes/users/ids", TwitterAPI.Controller, :empty_array)
313 get("/qvitter/mutes", TwitterAPI.Controller, :raw_empty_array)
315 get("/externalprofile/show", TwitterAPI.Controller, :external_profile)
318 pipeline :ap_relay do
319 plug(:accepts, ["activity+json"])
323 plug(:accepts, ["xml", "atom", "html", "activity+json"])
326 scope "/", Pleroma.Web do
327 pipe_through(:ostatus)
329 get("/objects/:uuid", OStatus.OStatusController, :object)
330 get("/activities/:uuid", OStatus.OStatusController, :activity)
331 get("/notice/:id", OStatus.OStatusController, :notice)
332 get("/users/:nickname/feed", OStatus.OStatusController, :feed)
333 get("/users/:nickname", OStatus.OStatusController, :feed_redirect)
335 post("/users/:nickname/salmon", OStatus.OStatusController, :salmon_incoming)
336 post("/push/hub/:nickname", Websub.WebsubController, :websub_subscription_request)
337 get("/push/subscriptions/:id", Websub.WebsubController, :websub_subscription_confirmation)
338 post("/push/subscriptions/:id", Websub.WebsubController, :websub_incoming)
341 pipeline :activitypub do
342 plug(:accepts, ["activity+json"])
343 plug(Pleroma.Web.Plugs.HTTPSignaturePlug)
346 scope "/", Pleroma.Web.ActivityPub do
347 # XXX: not really ostatus
348 pipe_through(:ostatus)
350 get("/users/:nickname/followers", ActivityPubController, :followers)
351 get("/users/:nickname/following", ActivityPubController, :following)
352 get("/users/:nickname/outbox", ActivityPubController, :outbox)
355 scope "/relay", Pleroma.Web.ActivityPub do
356 pipe_through(:ap_relay)
357 get("/", ActivityPubController, :relay)
360 scope "/", Pleroma.Web.ActivityPub do
361 pipe_through(:activitypub)
362 post("/users/:nickname/inbox", ActivityPubController, :inbox)
363 post("/inbox", ActivityPubController, :inbox)
366 scope "/.well-known", Pleroma.Web do
367 pipe_through(:well_known)
369 get("/host-meta", WebFinger.WebFingerController, :host_meta)
370 get("/webfinger", WebFinger.WebFingerController, :webfinger)
371 get("/nodeinfo", Nodeinfo.NodeinfoController, :schemas)
374 scope "/nodeinfo", Pleroma.Web do
375 get("/:version", Nodeinfo.NodeinfoController, :nodeinfo)
378 scope "/", Pleroma.Web.MastodonAPI do
379 pipe_through(:mastodon_html)
381 get("/web/login", MastodonAPIController, :login)
382 post("/web/login", MastodonAPIController, :login_post)
383 get("/web/*path", MastodonAPIController, :index)
384 delete("/auth/sign_out", MastodonAPIController, :logout)
387 pipeline :remote_media do
390 scope "/proxy/", Pleroma.Web.MediaProxy do
391 pipe_through(:remote_media)
392 get("/:sig/:url", MediaProxyController, :remote)
393 get("/:sig/:url/:filename", MediaProxyController, :remote)
396 scope "/", Fallback do
397 get("/registration/:token", RedirectController, :registration_page)
398 get("/*path", RedirectController, :redirector)
400 options("/*path", RedirectController, :empty)
404 defmodule Fallback.RedirectController do
405 use Pleroma.Web, :controller
407 def redirector(conn, _params) do
408 if Mix.env() != :test do
410 |> put_resp_content_type("text/html")
411 |> send_file(200, "priv/static/index.html")
415 def registration_page(conn, params) do
416 redirector(conn, params)
419 def empty(conn, _params) do