1 defmodule Pleroma.Web.Router do
2 use Pleroma.Web, :router
4 alias Pleroma.{Repo, User, Web.Router}
6 @instance Application.get_env(:pleroma, :instance)
7 @federating Keyword.get(@instance, :federating)
8 @allow_relay Keyword.get(@instance, :allow_relay)
9 @public Keyword.get(@instance, :public)
10 @registrations_open Keyword.get(@instance, :registrations_open)
13 plug(:accepts, ["json"])
15 plug(Pleroma.Plugs.OAuthPlug)
16 plug(Pleroma.Plugs.BasicAuthDecoderPlug)
17 plug(Pleroma.Plugs.UserFetcherPlug)
18 plug(Pleroma.Plugs.SessionAuthenticationPlug)
19 plug(Pleroma.Plugs.AuthenticationPlug)
20 plug(Pleroma.Plugs.UserEnabledPlug)
21 plug(Pleroma.Plugs.SetUserSessionIdPlug)
22 plug(Pleroma.Plugs.EnsureUserKeyPlug)
25 pipeline :authenticated_api do
26 plug(:accepts, ["json"])
28 plug(Pleroma.Plugs.OAuthPlug)
29 plug(Pleroma.Plugs.BasicAuthDecoderPlug)
30 plug(Pleroma.Plugs.UserFetcherPlug)
31 plug(Pleroma.Plugs.SessionAuthenticationPlug)
32 plug(Pleroma.Plugs.AuthenticationPlug)
33 plug(Pleroma.Plugs.UserEnabledPlug)
34 plug(Pleroma.Plugs.SetUserSessionIdPlug)
35 plug(Pleroma.Plugs.EnsureAuthenticatedPlug)
38 pipeline :mastodon_html do
39 plug(:accepts, ["html"])
41 plug(Pleroma.Plugs.OAuthPlug)
42 plug(Pleroma.Plugs.BasicAuthDecoderPlug)
43 plug(Pleroma.Plugs.UserFetcherPlug)
44 plug(Pleroma.Plugs.SessionAuthenticationPlug)
45 plug(Pleroma.Plugs.AuthenticationPlug)
46 plug(Pleroma.Plugs.UserEnabledPlug)
47 plug(Pleroma.Plugs.SetUserSessionIdPlug)
48 plug(Pleroma.Plugs.EnsureUserKeyPlug)
51 pipeline :pleroma_html do
52 plug(:accepts, ["html"])
54 plug(Pleroma.Plugs.OAuthPlug)
55 plug(Pleroma.Plugs.BasicAuthDecoderPlug)
56 plug(Pleroma.Plugs.UserFetcherPlug)
57 plug(Pleroma.Plugs.SessionAuthenticationPlug)
58 plug(Pleroma.Plugs.AuthenticationPlug)
59 plug(Pleroma.Plugs.EnsureUserKeyPlug)
62 pipeline :well_known do
63 plug(:accepts, ["json", "jrd+json", "xml", "xrd+xml"])
67 plug(:accepts, ["json", "xml"])
71 plug(:accepts, ["html", "json"])
74 pipeline :pleroma_api do
75 plug(:accepts, ["html", "json"])
78 scope "/api/pleroma", Pleroma.Web.TwitterAPI do
79 pipe_through(:pleroma_api)
80 get("/password_reset/:token", UtilController, :show_password_reset)
81 post("/password_reset", UtilController, :password_reset)
82 get("/emoji", UtilController, :emoji)
85 scope "/", Pleroma.Web.TwitterAPI do
86 pipe_through(:pleroma_html)
87 get("/ostatus_subscribe", UtilController, :remote_follow)
88 post("/ostatus_subscribe", UtilController, :do_remote_follow)
89 post("/main/ostatus", UtilController, :remote_subscribe)
92 scope "/api/pleroma", Pleroma.Web.TwitterAPI do
93 pipe_through(:authenticated_api)
94 post("/follow_import", UtilController, :follow_import)
95 post("/change_password", UtilController, :change_password)
96 post("/delete_account", UtilController, :delete_account)
99 scope "/oauth", Pleroma.Web.OAuth do
100 get("/authorize", OAuthController, :authorize)
101 post("/authorize", OAuthController, :create_authorization)
102 post("/token", OAuthController, :token_exchange)
105 scope "/api/v1", Pleroma.Web.MastodonAPI do
106 pipe_through(:authenticated_api)
108 patch("/accounts/update_credentials", MastodonAPIController, :update_credentials)
109 get("/accounts/verify_credentials", MastodonAPIController, :verify_credentials)
110 get("/accounts/relationships", MastodonAPIController, :relationships)
111 get("/accounts/search", MastodonAPIController, :account_search)
112 post("/accounts/:id/follow", MastodonAPIController, :follow)
113 post("/accounts/:id/unfollow", MastodonAPIController, :unfollow)
114 post("/accounts/:id/block", MastodonAPIController, :block)
115 post("/accounts/:id/unblock", MastodonAPIController, :unblock)
116 post("/accounts/:id/mute", MastodonAPIController, :relationship_noop)
117 post("/accounts/:id/unmute", MastodonAPIController, :relationship_noop)
119 get("/follow_requests", MastodonAPIController, :follow_requests)
120 post("/follow_requests/:id/authorize", MastodonAPIController, :authorize_follow_request)
121 post("/follow_requests/:id/reject", MastodonAPIController, :reject_follow_request)
123 post("/follows", MastodonAPIController, :follow)
125 get("/blocks", MastodonAPIController, :blocks)
127 get("/mutes", MastodonAPIController, :empty_array)
129 get("/timelines/home", MastodonAPIController, :home_timeline)
131 get("/timelines/direct", MastodonAPIController, :dm_timeline)
133 get("/favourites", MastodonAPIController, :favourites)
135 post("/statuses", MastodonAPIController, :post_status)
136 delete("/statuses/:id", MastodonAPIController, :delete_status)
138 post("/statuses/:id/reblog", MastodonAPIController, :reblog_status)
139 post("/statuses/:id/unreblog", MastodonAPIController, :unreblog_status)
140 post("/statuses/:id/favourite", MastodonAPIController, :fav_status)
141 post("/statuses/:id/unfavourite", MastodonAPIController, :unfav_status)
143 post("/notifications/clear", MastodonAPIController, :clear_notifications)
144 post("/notifications/dismiss", MastodonAPIController, :dismiss_notification)
145 get("/notifications", MastodonAPIController, :notifications)
146 get("/notifications/:id", MastodonAPIController, :get_notification)
148 post("/media", MastodonAPIController, :upload)
149 put("/media/:id", MastodonAPIController, :update_media)
151 get("/lists", MastodonAPIController, :get_lists)
152 get("/lists/:id", MastodonAPIController, :get_list)
153 delete("/lists/:id", MastodonAPIController, :delete_list)
154 post("/lists", MastodonAPIController, :create_list)
155 put("/lists/:id", MastodonAPIController, :rename_list)
156 get("/lists/:id/accounts", MastodonAPIController, :list_accounts)
157 post("/lists/:id/accounts", MastodonAPIController, :add_to_list)
158 delete("/lists/:id/accounts", MastodonAPIController, :remove_from_list)
160 get("/domain_blocks", MastodonAPIController, :domain_blocks)
161 post("/domain_blocks", MastodonAPIController, :block_domain)
162 delete("/domain_blocks", MastodonAPIController, :unblock_domain)
164 get("/filters", MastodonAPIController, :get_filters)
165 post("/filters", MastodonAPIController, :create_filter)
166 get("/filters/:id", MastodonAPIController, :get_filter)
167 put("/filters/:id", MastodonAPIController, :update_filter)
168 delete("/filters/:id", MastodonAPIController, :delete_filter)
170 get("/suggestions", MastodonAPIController, :suggestions)
173 scope "/api/web", Pleroma.Web.MastodonAPI do
174 pipe_through(:authenticated_api)
176 put("/settings", MastodonAPIController, :put_settings)
179 scope "/api/v1", Pleroma.Web.MastodonAPI do
181 get("/instance", MastodonAPIController, :masto_instance)
182 get("/instance/peers", MastodonAPIController, :peers)
183 post("/apps", MastodonAPIController, :create_app)
184 get("/custom_emojis", MastodonAPIController, :custom_emojis)
186 get("/timelines/public", MastodonAPIController, :public_timeline)
187 get("/timelines/tag/:tag", MastodonAPIController, :hashtag_timeline)
188 get("/timelines/list/:list_id", MastodonAPIController, :list_timeline)
190 get("/statuses/:id", MastodonAPIController, :get_status)
191 get("/statuses/:id/context", MastodonAPIController, :get_context)
192 get("/statuses/:id/card", MastodonAPIController, :empty_object)
193 get("/statuses/:id/favourited_by", MastodonAPIController, :favourited_by)
194 get("/statuses/:id/reblogged_by", MastodonAPIController, :reblogged_by)
196 get("/accounts/:id/statuses", MastodonAPIController, :user_statuses)
197 get("/accounts/:id/followers", MastodonAPIController, :followers)
198 get("/accounts/:id/following", MastodonAPIController, :following)
199 get("/accounts/:id", MastodonAPIController, :user)
201 get("/trends", MastodonAPIController, :empty_array)
203 get("/search", MastodonAPIController, :search)
206 scope "/api/v2", Pleroma.Web.MastodonAPI do
208 get("/search", MastodonAPIController, :search2)
211 scope "/api", Pleroma.Web do
212 pipe_through(:config)
214 get("/help/test", TwitterAPI.UtilController, :help_test)
215 post("/help/test", TwitterAPI.UtilController, :help_test)
216 get("/statusnet/config", TwitterAPI.UtilController, :config)
217 get("/statusnet/version", TwitterAPI.UtilController, :version)
220 scope "/api", Pleroma.Web do
223 get("/statuses/user_timeline", TwitterAPI.Controller, :user_timeline)
224 get("/qvitter/statuses/user_timeline", TwitterAPI.Controller, :user_timeline)
225 get("/users/show", TwitterAPI.Controller, :show_user)
227 get("/statuses/followers", TwitterAPI.Controller, :followers)
228 get("/statuses/friends", TwitterAPI.Controller, :friends)
229 get("/statuses/show/:id", TwitterAPI.Controller, :fetch_status)
230 get("/statusnet/conversation/:id", TwitterAPI.Controller, :fetch_conversation)
232 post("/account/register", TwitterAPI.Controller, :register)
234 get("/search", TwitterAPI.Controller, :search)
235 get("/statusnet/tags/timeline/:tag", TwitterAPI.Controller, :public_and_external_timeline)
238 scope "/api", Pleroma.Web do
242 pipe_through(:authenticated_api)
245 get("/statuses/public_timeline", TwitterAPI.Controller, :public_timeline)
248 "/statuses/public_and_external_timeline",
249 TwitterAPI.Controller,
250 :public_and_external_timeline
253 get("/statuses/networkpublic_timeline", TwitterAPI.Controller, :public_and_external_timeline)
256 scope "/api", Pleroma.Web do
257 pipe_through(:authenticated_api)
259 get("/account/verify_credentials", TwitterAPI.Controller, :verify_credentials)
260 post("/account/verify_credentials", TwitterAPI.Controller, :verify_credentials)
262 post("/account/update_profile", TwitterAPI.Controller, :update_profile)
263 post("/account/update_profile_banner", TwitterAPI.Controller, :update_banner)
264 post("/qvitter/update_background_image", TwitterAPI.Controller, :update_background)
267 "/account/most_recent_notification",
268 TwitterAPI.Controller,
269 :update_most_recent_notification
272 get("/statuses/home_timeline", TwitterAPI.Controller, :friends_timeline)
273 get("/statuses/friends_timeline", TwitterAPI.Controller, :friends_timeline)
274 get("/statuses/mentions", TwitterAPI.Controller, :mentions_timeline)
275 get("/statuses/mentions_timeline", TwitterAPI.Controller, :mentions_timeline)
276 get("/qvitter/statuses/notifications", TwitterAPI.Controller, :notifications)
278 post("/statuses/update", TwitterAPI.Controller, :status_update)
279 post("/statuses/retweet/:id", TwitterAPI.Controller, :retweet)
280 post("/statuses/unretweet/:id", TwitterAPI.Controller, :unretweet)
281 post("/statuses/destroy/:id", TwitterAPI.Controller, :delete_post)
283 get("/pleroma/friend_requests", TwitterAPI.Controller, :friend_requests)
284 post("/pleroma/friendships/approve", TwitterAPI.Controller, :approve_friend_request)
285 post("/pleroma/friendships/deny", TwitterAPI.Controller, :deny_friend_request)
287 post("/friendships/create", TwitterAPI.Controller, :follow)
288 post("/friendships/destroy", TwitterAPI.Controller, :unfollow)
289 post("/blocks/create", TwitterAPI.Controller, :block)
290 post("/blocks/destroy", TwitterAPI.Controller, :unblock)
292 post("/statusnet/media/upload", TwitterAPI.Controller, :upload)
293 post("/media/upload", TwitterAPI.Controller, :upload_json)
295 post("/favorites/create/:id", TwitterAPI.Controller, :favorite)
296 post("/favorites/create", TwitterAPI.Controller, :favorite)
297 post("/favorites/destroy/:id", TwitterAPI.Controller, :unfavorite)
299 post("/qvitter/update_avatar", TwitterAPI.Controller, :update_avatar)
301 get("/friends/ids", TwitterAPI.Controller, :friends_ids)
302 get("/friendships/no_retweets/ids", TwitterAPI.Controller, :empty_array)
304 get("/mutes/users/ids", TwitterAPI.Controller, :empty_array)
305 get("/qvitter/mutes", TwitterAPI.Controller, :raw_empty_array)
307 get("/externalprofile/show", TwitterAPI.Controller, :external_profile)
310 pipeline :ap_relay do
311 plug(:accepts, ["activity+json"])
315 plug(:accepts, ["xml", "atom", "html", "activity+json"])
318 scope "/", Pleroma.Web do
319 pipe_through(:ostatus)
321 get("/objects/:uuid", OStatus.OStatusController, :object)
322 get("/activities/:uuid", OStatus.OStatusController, :activity)
323 get("/notice/:id", OStatus.OStatusController, :notice)
324 get("/users/:nickname/feed", OStatus.OStatusController, :feed)
325 get("/users/:nickname", OStatus.OStatusController, :feed_redirect)
328 post("/users/:nickname/salmon", OStatus.OStatusController, :salmon_incoming)
329 post("/push/hub/:nickname", Websub.WebsubController, :websub_subscription_request)
330 get("/push/subscriptions/:id", Websub.WebsubController, :websub_subscription_confirmation)
331 post("/push/subscriptions/:id", Websub.WebsubController, :websub_incoming)
335 pipeline :activitypub do
336 plug(:accepts, ["activity+json"])
337 plug(Pleroma.Web.Plugs.HTTPSignaturePlug)
340 scope "/", Pleroma.Web.ActivityPub do
341 # XXX: not really ostatus
342 pipe_through(:ostatus)
344 get("/users/:nickname/followers", ActivityPubController, :followers)
345 get("/users/:nickname/following", ActivityPubController, :following)
346 get("/users/:nickname/outbox", ActivityPubController, :outbox)
351 scope "/relay", Pleroma.Web.ActivityPub do
352 pipe_through(:ap_relay)
353 get("/", ActivityPubController, :relay)
357 scope "/", Pleroma.Web.ActivityPub do
358 pipe_through(:activitypub)
359 post("/users/:nickname/inbox", ActivityPubController, :inbox)
360 post("/inbox", ActivityPubController, :inbox)
363 scope "/.well-known", Pleroma.Web do
364 pipe_through(:well_known)
366 get("/host-meta", WebFinger.WebFingerController, :host_meta)
367 get("/webfinger", WebFinger.WebFingerController, :webfinger)
368 get("/nodeinfo", Nodeinfo.NodeinfoController, :schemas)
371 scope "/nodeinfo", Pleroma.Web do
372 get("/:version", Nodeinfo.NodeinfoController, :nodeinfo)
376 scope "/", Pleroma.Web.MastodonAPI do
377 pipe_through(:mastodon_html)
379 get("/web/login", MastodonAPIController, :login)
380 post("/web/login", MastodonAPIController, :login_post)
381 get("/web/*path", MastodonAPIController, :index)
382 delete("/auth/sign_out", MastodonAPIController, :logout)
385 pipeline :remote_media do
386 plug(:accepts, ["html"])
389 scope "/proxy/", Pleroma.Web.MediaProxy do
390 pipe_through(:remote_media)
391 get("/:sig/:url", MediaProxyController, :remote)
394 scope "/", Fallback do
395 get("/registration/:token", RedirectController, :registration_page)
396 get("/*path", RedirectController, :redirector)
400 defmodule Fallback.RedirectController do
401 use Pleroma.Web, :controller
403 def redirector(conn, _params) do
404 if Mix.env() != :test do
406 |> put_resp_content_type("text/html")
407 |> send_file(200, "priv/static/index.html")
411 def registration_page(conn, params) do
412 redirector(conn, params)