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)
12 def user_fetcher(username_or_email) do
16 # First, try logging in as if it was a name
17 user = Repo.get_by(User, %{nickname: username_or_email}) ->
20 # If we get nil, we try using it as an email
21 user = Repo.get_by(User, %{email: username_or_email}) ->
28 plug(:accepts, ["json"])
30 plug(Pleroma.Plugs.OAuthPlug)
31 plug(Pleroma.Plugs.AuthenticationPlug, %{fetcher: &Router.user_fetcher/1, optional: true})
34 pipeline :authenticated_api do
35 plug(:accepts, ["json"])
37 plug(Pleroma.Plugs.OAuthPlug)
38 plug(Pleroma.Plugs.AuthenticationPlug, %{fetcher: &Router.user_fetcher/1})
41 pipeline :mastodon_html do
42 plug(:accepts, ["html"])
44 plug(Pleroma.Plugs.OAuthPlug)
45 plug(Pleroma.Plugs.AuthenticationPlug, %{fetcher: &Router.user_fetcher/1, optional: true})
48 pipeline :pleroma_html do
49 plug(:accepts, ["html"])
51 plug(Pleroma.Plugs.OAuthPlug)
52 plug(Pleroma.Plugs.AuthenticationPlug, %{fetcher: &Router.user_fetcher/1, optional: true})
55 pipeline :well_known do
56 plug(:accepts, ["json", "jrd+json", "xml", "xrd+xml"])
60 plug(:accepts, ["json", "xml"])
64 plug(:accepts, ["html", "json"])
67 pipeline :pleroma_api do
68 plug(:accepts, ["html", "json"])
71 scope "/api/pleroma", Pleroma.Web.TwitterAPI do
72 pipe_through(:pleroma_api)
73 get("/password_reset/:token", UtilController, :show_password_reset)
74 post("/password_reset", UtilController, :password_reset)
75 get("/emoji", UtilController, :emoji)
78 scope "/", Pleroma.Web.TwitterAPI do
79 pipe_through(:pleroma_html)
80 get("/ostatus_subscribe", UtilController, :remote_follow)
81 post("/ostatus_subscribe", UtilController, :do_remote_follow)
82 post("/main/ostatus", UtilController, :remote_subscribe)
85 scope "/api/pleroma", Pleroma.Web.TwitterAPI do
86 pipe_through(:authenticated_api)
87 post("/follow_import", UtilController, :follow_import)
88 post("/change_password", UtilController, :change_password)
89 post("/delete_account", UtilController, :delete_account)
92 scope "/oauth", Pleroma.Web.OAuth do
93 get("/authorize", OAuthController, :authorize)
94 post("/authorize", OAuthController, :create_authorization)
95 post("/token", OAuthController, :token_exchange)
98 scope "/api/v1", Pleroma.Web.MastodonAPI do
99 pipe_through(:authenticated_api)
101 patch("/accounts/update_credentials", MastodonAPIController, :update_credentials)
102 get("/accounts/verify_credentials", MastodonAPIController, :verify_credentials)
103 get("/accounts/relationships", MastodonAPIController, :relationships)
104 get("/accounts/search", MastodonAPIController, :account_search)
105 post("/accounts/:id/follow", MastodonAPIController, :follow)
106 post("/accounts/:id/unfollow", MastodonAPIController, :unfollow)
107 post("/accounts/:id/block", MastodonAPIController, :block)
108 post("/accounts/:id/unblock", MastodonAPIController, :unblock)
109 post("/accounts/:id/mute", MastodonAPIController, :relationship_noop)
110 post("/accounts/:id/unmute", MastodonAPIController, :relationship_noop)
112 get("/follow_requests", MastodonAPIController, :follow_requests)
113 post("/follow_requests/:id/authorize", MastodonAPIController, :authorize_follow_request)
114 post("/follow_requests/:id/reject", MastodonAPIController, :reject_follow_request)
116 post("/follows", MastodonAPIController, :follow)
118 get("/blocks", MastodonAPIController, :blocks)
120 get("/mutes", MastodonAPIController, :empty_array)
122 get("/timelines/home", MastodonAPIController, :home_timeline)
124 get("/timelines/direct", MastodonAPIController, :dm_timeline)
126 get("/favourites", MastodonAPIController, :favourites)
128 post("/statuses", MastodonAPIController, :post_status)
129 delete("/statuses/:id", MastodonAPIController, :delete_status)
131 post("/statuses/:id/reblog", MastodonAPIController, :reblog_status)
132 post("/statuses/:id/unreblog", MastodonAPIController, :unreblog_status)
133 post("/statuses/:id/favourite", MastodonAPIController, :fav_status)
134 post("/statuses/:id/unfavourite", MastodonAPIController, :unfav_status)
136 post("/notifications/clear", MastodonAPIController, :clear_notifications)
137 post("/notifications/dismiss", MastodonAPIController, :dismiss_notification)
138 get("/notifications", MastodonAPIController, :notifications)
139 get("/notifications/:id", MastodonAPIController, :get_notification)
141 post("/media", MastodonAPIController, :upload)
142 put("/media/:id", MastodonAPIController, :update_media)
144 get("/lists", MastodonAPIController, :get_lists)
145 get("/lists/:id", MastodonAPIController, :get_list)
146 delete("/lists/:id", MastodonAPIController, :delete_list)
147 post("/lists", MastodonAPIController, :create_list)
148 put("/lists/:id", MastodonAPIController, :rename_list)
149 get("/lists/:id/accounts", MastodonAPIController, :list_accounts)
150 post("/lists/:id/accounts", MastodonAPIController, :add_to_list)
151 delete("/lists/:id/accounts", MastodonAPIController, :remove_from_list)
153 get("/domain_blocks", MastodonAPIController, :domain_blocks)
154 post("/domain_blocks", MastodonAPIController, :block_domain)
155 delete("/domain_blocks", MastodonAPIController, :unblock_domain)
157 get("/filters", MastodonAPIController, :get_filters)
158 post("/filters", MastodonAPIController, :create_filter)
159 get("/filters/:id", MastodonAPIController, :get_filter)
160 put("/filters/:id", MastodonAPIController, :update_filter)
161 delete("/filters/:id", MastodonAPIController, :delete_filter)
163 get("/suggestions", MastodonAPIController, :suggestions)
166 scope "/api/web", Pleroma.Web.MastodonAPI do
167 pipe_through(:authenticated_api)
169 put("/settings", MastodonAPIController, :put_settings)
172 scope "/api/v1", Pleroma.Web.MastodonAPI do
174 get("/instance", MastodonAPIController, :masto_instance)
175 get("/instance/peers", MastodonAPIController, :peers)
176 post("/apps", MastodonAPIController, :create_app)
177 get("/custom_emojis", MastodonAPIController, :custom_emojis)
179 get("/timelines/public", MastodonAPIController, :public_timeline)
180 get("/timelines/tag/:tag", MastodonAPIController, :hashtag_timeline)
181 get("/timelines/list/:list_id", MastodonAPIController, :list_timeline)
183 get("/statuses/:id", MastodonAPIController, :get_status)
184 get("/statuses/:id/context", MastodonAPIController, :get_context)
185 get("/statuses/:id/card", MastodonAPIController, :empty_object)
186 get("/statuses/:id/favourited_by", MastodonAPIController, :favourited_by)
187 get("/statuses/:id/reblogged_by", MastodonAPIController, :reblogged_by)
189 get("/accounts/:id/statuses", MastodonAPIController, :user_statuses)
190 get("/accounts/:id/followers", MastodonAPIController, :followers)
191 get("/accounts/:id/following", MastodonAPIController, :following)
192 get("/accounts/:id", MastodonAPIController, :user)
194 get("/trends", MastodonAPIController, :empty_array)
196 get("/search", MastodonAPIController, :search)
199 scope "/api/v2", Pleroma.Web.MastodonAPI do
201 get("/search", MastodonAPIController, :search2)
204 scope "/api", Pleroma.Web do
205 pipe_through(:config)
207 get("/help/test", TwitterAPI.UtilController, :help_test)
208 post("/help/test", TwitterAPI.UtilController, :help_test)
209 get("/statusnet/config", TwitterAPI.UtilController, :config)
210 get("/statusnet/version", TwitterAPI.UtilController, :version)
213 scope "/api", Pleroma.Web do
216 get("/statuses/user_timeline", TwitterAPI.Controller, :user_timeline)
217 get("/qvitter/statuses/user_timeline", TwitterAPI.Controller, :user_timeline)
218 get("/users/show", TwitterAPI.Controller, :show_user)
220 get("/statuses/followers", TwitterAPI.Controller, :followers)
221 get("/statuses/friends", TwitterAPI.Controller, :friends)
222 get("/statuses/show/:id", TwitterAPI.Controller, :fetch_status)
223 get("/statusnet/conversation/:id", TwitterAPI.Controller, :fetch_conversation)
225 post("/account/register", TwitterAPI.Controller, :register)
227 get("/search", TwitterAPI.Controller, :search)
228 get("/statusnet/tags/timeline/:tag", TwitterAPI.Controller, :public_and_external_timeline)
231 scope "/api", Pleroma.Web do
235 pipe_through(:authenticated_api)
238 get("/statuses/public_timeline", TwitterAPI.Controller, :public_timeline)
241 "/statuses/public_and_external_timeline",
242 TwitterAPI.Controller,
243 :public_and_external_timeline
246 get("/statuses/networkpublic_timeline", TwitterAPI.Controller, :public_and_external_timeline)
249 scope "/api", Pleroma.Web do
250 pipe_through(:authenticated_api)
252 get("/account/verify_credentials", TwitterAPI.Controller, :verify_credentials)
253 post("/account/verify_credentials", TwitterAPI.Controller, :verify_credentials)
255 post("/account/update_profile", TwitterAPI.Controller, :update_profile)
256 post("/account/update_profile_banner", TwitterAPI.Controller, :update_banner)
257 post("/qvitter/update_background_image", TwitterAPI.Controller, :update_background)
260 "/account/most_recent_notification",
261 TwitterAPI.Controller,
262 :update_most_recent_notification
265 get("/statuses/home_timeline", TwitterAPI.Controller, :friends_timeline)
266 get("/statuses/friends_timeline", TwitterAPI.Controller, :friends_timeline)
267 get("/statuses/mentions", TwitterAPI.Controller, :mentions_timeline)
268 get("/statuses/mentions_timeline", TwitterAPI.Controller, :mentions_timeline)
269 get("/qvitter/statuses/notifications", TwitterAPI.Controller, :notifications)
271 post("/statuses/update", TwitterAPI.Controller, :status_update)
272 post("/statuses/retweet/:id", TwitterAPI.Controller, :retweet)
273 post("/statuses/unretweet/:id", TwitterAPI.Controller, :unretweet)
274 post("/statuses/destroy/:id", TwitterAPI.Controller, :delete_post)
276 get("/pleroma/friend_requests", TwitterAPI.Controller, :friend_requests)
277 post("/pleroma/friendships/approve", TwitterAPI.Controller, :approve_friend_request)
278 post("/pleroma/friendships/deny", TwitterAPI.Controller, :deny_friend_request)
280 post("/friendships/create", TwitterAPI.Controller, :follow)
281 post("/friendships/destroy", TwitterAPI.Controller, :unfollow)
282 post("/blocks/create", TwitterAPI.Controller, :block)
283 post("/blocks/destroy", TwitterAPI.Controller, :unblock)
285 post("/statusnet/media/upload", TwitterAPI.Controller, :upload)
286 post("/media/upload", TwitterAPI.Controller, :upload_json)
288 post("/favorites/create/:id", TwitterAPI.Controller, :favorite)
289 post("/favorites/create", TwitterAPI.Controller, :favorite)
290 post("/favorites/destroy/:id", TwitterAPI.Controller, :unfavorite)
292 post("/qvitter/update_avatar", TwitterAPI.Controller, :update_avatar)
294 get("/friends/ids", TwitterAPI.Controller, :friends_ids)
295 get("/friendships/no_retweets/ids", TwitterAPI.Controller, :empty_array)
297 get("/mutes/users/ids", TwitterAPI.Controller, :empty_array)
298 get("/qvitter/mutes", TwitterAPI.Controller, :raw_empty_array)
300 get("/externalprofile/show", TwitterAPI.Controller, :external_profile)
303 pipeline :ap_relay do
304 plug(:accepts, ["activity+json"])
308 plug(:accepts, ["xml", "atom", "html", "activity+json"])
311 scope "/", Pleroma.Web do
312 pipe_through(:ostatus)
314 get("/objects/:uuid", OStatus.OStatusController, :object)
315 get("/activities/:uuid", OStatus.OStatusController, :activity)
316 get("/notice/:id", OStatus.OStatusController, :notice)
317 get("/users/:nickname/feed", OStatus.OStatusController, :feed)
318 get("/users/:nickname", OStatus.OStatusController, :feed_redirect)
321 post("/users/:nickname/salmon", OStatus.OStatusController, :salmon_incoming)
322 post("/push/hub/:nickname", Websub.WebsubController, :websub_subscription_request)
323 get("/push/subscriptions/:id", Websub.WebsubController, :websub_subscription_confirmation)
324 post("/push/subscriptions/:id", Websub.WebsubController, :websub_incoming)
328 pipeline :activitypub do
329 plug(:accepts, ["activity+json"])
330 plug(Pleroma.Web.Plugs.HTTPSignaturePlug)
333 scope "/", Pleroma.Web.ActivityPub do
334 # XXX: not really ostatus
335 pipe_through(:ostatus)
337 get("/users/:nickname/followers", ActivityPubController, :followers)
338 get("/users/:nickname/following", ActivityPubController, :following)
339 get("/users/:nickname/outbox", ActivityPubController, :outbox)
344 scope "/relay", Pleroma.Web.ActivityPub do
345 pipe_through(:ap_relay)
346 get("/", ActivityPubController, :relay)
350 scope "/", Pleroma.Web.ActivityPub do
351 pipe_through(:activitypub)
352 post("/users/:nickname/inbox", ActivityPubController, :inbox)
353 post("/inbox", ActivityPubController, :inbox)
356 scope "/.well-known", Pleroma.Web do
357 pipe_through(:well_known)
359 get("/host-meta", WebFinger.WebFingerController, :host_meta)
360 get("/webfinger", WebFinger.WebFingerController, :webfinger)
361 get("/nodeinfo", Nodeinfo.NodeinfoController, :schemas)
364 scope "/nodeinfo", Pleroma.Web do
365 get("/:version", Nodeinfo.NodeinfoController, :nodeinfo)
369 scope "/", Pleroma.Web.MastodonAPI do
370 pipe_through(:mastodon_html)
372 get("/web/login", MastodonAPIController, :login)
373 post("/web/login", MastodonAPIController, :login_post)
374 get("/web/*path", MastodonAPIController, :index)
375 delete("/auth/sign_out", MastodonAPIController, :logout)
378 pipeline :remote_media do
379 plug(:accepts, ["html"])
382 scope "/proxy/", Pleroma.Web.MediaProxy do
383 pipe_through(:remote_media)
384 get("/:sig/:url", MediaProxyController, :remote)
387 scope "/", Fallback do
388 get("/registration/:token", RedirectController, :registration_page)
389 get("/*path", RedirectController, :redirector)
393 defmodule Fallback.RedirectController do
394 use Pleroma.Web, :controller
396 def redirector(conn, _params) do
397 if Mix.env() != :test do
399 |> put_resp_content_type("text/html")
400 |> send_file(200, "priv/static/index.html")
404 def registration_page(conn, params) do
405 redirector(conn, params)