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) do
13 {:ok, Repo.get_by(User, %{nickname: username})}
17 plug(:accepts, ["json"])
19 plug(Pleroma.Plugs.OAuthPlug)
20 plug(Pleroma.Plugs.AuthenticationPlug, %{fetcher: &Router.user_fetcher/1, optional: true})
23 pipeline :authenticated_api do
24 plug(:accepts, ["json"])
26 plug(Pleroma.Plugs.OAuthPlug)
27 plug(Pleroma.Plugs.AuthenticationPlug, %{fetcher: &Router.user_fetcher/1})
30 pipeline :mastodon_html do
31 plug(:accepts, ["html"])
33 plug(Pleroma.Plugs.OAuthPlug)
34 plug(Pleroma.Plugs.AuthenticationPlug, %{fetcher: &Router.user_fetcher/1, optional: true})
37 pipeline :pleroma_html do
38 plug(:accepts, ["html"])
40 plug(Pleroma.Plugs.OAuthPlug)
41 plug(Pleroma.Plugs.AuthenticationPlug, %{fetcher: &Router.user_fetcher/1, optional: true})
44 pipeline :well_known do
45 plug(:accepts, ["json", "jrd+json", "xml", "xrd+xml"])
49 plug(:accepts, ["json", "xml"])
53 plug(:accepts, ["html", "json"])
56 pipeline :pleroma_api do
57 plug(:accepts, ["html", "json"])
60 scope "/api/pleroma", Pleroma.Web.TwitterAPI do
61 pipe_through(:pleroma_api)
62 get("/password_reset/:token", UtilController, :show_password_reset)
63 post("/password_reset", UtilController, :password_reset)
64 get("/emoji", UtilController, :emoji)
67 scope "/", Pleroma.Web.TwitterAPI do
68 pipe_through(:pleroma_html)
69 get("/ostatus_subscribe", UtilController, :remote_follow)
70 post("/ostatus_subscribe", UtilController, :do_remote_follow)
71 post("/main/ostatus", UtilController, :remote_subscribe)
74 scope "/api/pleroma", Pleroma.Web.TwitterAPI do
75 pipe_through(:authenticated_api)
76 post("/follow_import", UtilController, :follow_import)
77 post("/change_password", UtilController, :change_password)
78 post("/delete_account", UtilController, :delete_account)
81 scope "/oauth", Pleroma.Web.OAuth do
82 get("/authorize", OAuthController, :authorize)
83 post("/authorize", OAuthController, :create_authorization)
84 post("/token", OAuthController, :token_exchange)
87 scope "/api/v1", Pleroma.Web.MastodonAPI do
88 pipe_through(:authenticated_api)
90 patch("/accounts/update_credentials", MastodonAPIController, :update_credentials)
91 get("/accounts/verify_credentials", MastodonAPIController, :verify_credentials)
92 get("/accounts/relationships", MastodonAPIController, :relationships)
93 get("/accounts/search", MastodonAPIController, :account_search)
94 post("/accounts/:id/follow", MastodonAPIController, :follow)
95 post("/accounts/:id/unfollow", MastodonAPIController, :unfollow)
96 post("/accounts/:id/block", MastodonAPIController, :block)
97 post("/accounts/:id/unblock", MastodonAPIController, :unblock)
98 post("/accounts/:id/mute", MastodonAPIController, :relationship_noop)
99 post("/accounts/:id/unmute", MastodonAPIController, :relationship_noop)
101 get("/follow_requests", MastodonAPIController, :follow_requests)
102 post("/follow_requests/:id/authorize", MastodonAPIController, :authorize_follow_request)
103 post("/follow_requests/:id/reject", MastodonAPIController, :reject_follow_request)
105 post("/follows", MastodonAPIController, :follow)
107 get("/blocks", MastodonAPIController, :blocks)
109 get("/mutes", MastodonAPIController, :empty_array)
111 get("/timelines/home", MastodonAPIController, :home_timeline)
113 get("/timelines/direct", MastodonAPIController, :dm_timeline)
115 get("/favourites", MastodonAPIController, :favourites)
117 post("/statuses", MastodonAPIController, :post_status)
118 delete("/statuses/:id", MastodonAPIController, :delete_status)
120 post("/statuses/:id/reblog", MastodonAPIController, :reblog_status)
121 post("/statuses/:id/unreblog", MastodonAPIController, :unreblog_status)
122 post("/statuses/:id/favourite", MastodonAPIController, :fav_status)
123 post("/statuses/:id/unfavourite", MastodonAPIController, :unfav_status)
125 post("/notifications/clear", MastodonAPIController, :clear_notifications)
126 post("/notifications/dismiss", MastodonAPIController, :dismiss_notification)
127 get("/notifications", MastodonAPIController, :notifications)
128 get("/notifications/:id", MastodonAPIController, :get_notification)
130 post("/media", MastodonAPIController, :upload)
131 put("/media/:id", MastodonAPIController, :update_media)
133 get("/lists", MastodonAPIController, :get_lists)
134 get("/lists/:id", MastodonAPIController, :get_list)
135 delete("/lists/:id", MastodonAPIController, :delete_list)
136 post("/lists", MastodonAPIController, :create_list)
137 put("/lists/:id", MastodonAPIController, :rename_list)
138 get("/lists/:id/accounts", MastodonAPIController, :list_accounts)
139 post("/lists/:id/accounts", MastodonAPIController, :add_to_list)
140 delete("/lists/:id/accounts", MastodonAPIController, :remove_from_list)
142 get("/domain_blocks", MastodonAPIController, :domain_blocks)
143 post("/domain_blocks", MastodonAPIController, :block_domain)
144 delete("/domain_blocks", MastodonAPIController, :unblock_domain)
147 scope "/api/web", Pleroma.Web.MastodonAPI do
148 pipe_through(:authenticated_api)
150 put("/settings", MastodonAPIController, :put_settings)
153 scope "/api/v1", Pleroma.Web.MastodonAPI do
155 get("/instance", MastodonAPIController, :masto_instance)
156 get("/instance/peers", MastodonAPIController, :peers)
157 post("/apps", MastodonAPIController, :create_app)
158 get("/custom_emojis", MastodonAPIController, :custom_emojis)
160 get("/timelines/public", MastodonAPIController, :public_timeline)
161 get("/timelines/tag/:tag", MastodonAPIController, :hashtag_timeline)
162 get("/timelines/list/:list_id", MastodonAPIController, :list_timeline)
164 get("/statuses/:id", MastodonAPIController, :get_status)
165 get("/statuses/:id/context", MastodonAPIController, :get_context)
166 get("/statuses/:id/card", MastodonAPIController, :empty_object)
167 get("/statuses/:id/favourited_by", MastodonAPIController, :favourited_by)
168 get("/statuses/:id/reblogged_by", MastodonAPIController, :reblogged_by)
170 get("/accounts/:id/statuses", MastodonAPIController, :user_statuses)
171 get("/accounts/:id/followers", MastodonAPIController, :followers)
172 get("/accounts/:id/following", MastodonAPIController, :following)
173 get("/accounts/:id", MastodonAPIController, :user)
175 get("/trends", MastodonAPIController, :empty_array)
177 get("/search", MastodonAPIController, :search)
180 scope "/api/v2", Pleroma.Web.MastodonAPI do
182 get("/search", MastodonAPIController, :search2)
185 scope "/api", Pleroma.Web do
186 pipe_through(:config)
188 get("/help/test", TwitterAPI.UtilController, :help_test)
189 post("/help/test", TwitterAPI.UtilController, :help_test)
190 get("/statusnet/config", TwitterAPI.UtilController, :config)
191 get("/statusnet/version", TwitterAPI.UtilController, :version)
194 scope "/api", Pleroma.Web do
197 get("/statuses/user_timeline", TwitterAPI.Controller, :user_timeline)
198 get("/qvitter/statuses/user_timeline", TwitterAPI.Controller, :user_timeline)
199 get("/users/show", TwitterAPI.Controller, :show_user)
201 get("/statuses/followers", TwitterAPI.Controller, :followers)
202 get("/statuses/friends", TwitterAPI.Controller, :friends)
203 get("/statuses/show/:id", TwitterAPI.Controller, :fetch_status)
204 get("/statusnet/conversation/:id", TwitterAPI.Controller, :fetch_conversation)
206 if @registrations_open do
207 post("/account/register", TwitterAPI.Controller, :register)
210 get("/search", TwitterAPI.Controller, :search)
211 get("/statusnet/tags/timeline/:tag", TwitterAPI.Controller, :public_and_external_timeline)
214 scope "/api", Pleroma.Web do
218 pipe_through(:authenticated_api)
221 get("/statuses/public_timeline", TwitterAPI.Controller, :public_timeline)
224 "/statuses/public_and_external_timeline",
225 TwitterAPI.Controller,
226 :public_and_external_timeline
229 get("/statuses/networkpublic_timeline", TwitterAPI.Controller, :public_and_external_timeline)
232 scope "/api", Pleroma.Web do
233 pipe_through(:authenticated_api)
235 get("/account/verify_credentials", TwitterAPI.Controller, :verify_credentials)
236 post("/account/verify_credentials", TwitterAPI.Controller, :verify_credentials)
238 post("/account/update_profile", TwitterAPI.Controller, :update_profile)
239 post("/account/update_profile_banner", TwitterAPI.Controller, :update_banner)
240 post("/qvitter/update_background_image", TwitterAPI.Controller, :update_background)
243 "/account/most_recent_notification",
244 TwitterAPI.Controller,
245 :update_most_recent_notification
248 get("/statuses/home_timeline", TwitterAPI.Controller, :friends_timeline)
249 get("/statuses/friends_timeline", TwitterAPI.Controller, :friends_timeline)
250 get("/statuses/mentions", TwitterAPI.Controller, :mentions_timeline)
251 get("/statuses/mentions_timeline", TwitterAPI.Controller, :mentions_timeline)
252 get("/qvitter/statuses/notifications", TwitterAPI.Controller, :notifications)
254 post("/statuses/update", TwitterAPI.Controller, :status_update)
255 post("/statuses/retweet/:id", TwitterAPI.Controller, :retweet)
256 post("/statuses/unretweet/:id", TwitterAPI.Controller, :unretweet)
257 post("/statuses/destroy/:id", TwitterAPI.Controller, :delete_post)
259 get("/pleroma/friend_requests", TwitterAPI.Controller, :friend_requests)
260 post("/pleroma/friendships/approve", TwitterAPI.Controller, :approve_friend_request)
261 post("/pleroma/friendships/deny", TwitterAPI.Controller, :deny_friend_request)
263 post("/friendships/create", TwitterAPI.Controller, :follow)
264 post("/friendships/destroy", TwitterAPI.Controller, :unfollow)
265 post("/blocks/create", TwitterAPI.Controller, :block)
266 post("/blocks/destroy", TwitterAPI.Controller, :unblock)
268 post("/statusnet/media/upload", TwitterAPI.Controller, :upload)
269 post("/media/upload", TwitterAPI.Controller, :upload_json)
271 post("/favorites/create/:id", TwitterAPI.Controller, :favorite)
272 post("/favorites/create", TwitterAPI.Controller, :favorite)
273 post("/favorites/destroy/:id", TwitterAPI.Controller, :unfavorite)
275 post("/qvitter/update_avatar", TwitterAPI.Controller, :update_avatar)
277 get("/friends/ids", TwitterAPI.Controller, :friends_ids)
278 get("/friendships/no_retweets/ids", TwitterAPI.Controller, :empty_array)
280 get("/mutes/users/ids", TwitterAPI.Controller, :empty_array)
281 get("/qvitter/mutes", TwitterAPI.Controller, :raw_empty_array)
283 get("/externalprofile/show", TwitterAPI.Controller, :external_profile)
287 plug(:accepts, ["xml", "atom", "html", "activity+json"])
290 scope "/", Pleroma.Web do
291 pipe_through(:ostatus)
293 get("/objects/:uuid", OStatus.OStatusController, :object)
294 get("/activities/:uuid", OStatus.OStatusController, :activity)
295 get("/notice/:id", OStatus.OStatusController, :notice)
296 get("/users/:nickname/feed", OStatus.OStatusController, :feed)
297 get("/users/:nickname", OStatus.OStatusController, :feed_redirect)
300 post("/users/:nickname/salmon", OStatus.OStatusController, :salmon_incoming)
301 post("/push/hub/:nickname", Websub.WebsubController, :websub_subscription_request)
302 get("/push/subscriptions/:id", Websub.WebsubController, :websub_subscription_confirmation)
303 post("/push/subscriptions/:id", Websub.WebsubController, :websub_incoming)
307 pipeline :activitypub do
308 plug(:accepts, ["activity+json"])
309 plug(Pleroma.Web.Plugs.HTTPSignaturePlug)
312 scope "/", Pleroma.Web.ActivityPub do
313 # XXX: not really ostatus
314 pipe_through(:ostatus)
316 get("/users/:nickname/followers", ActivityPubController, :followers)
317 get("/users/:nickname/following", ActivityPubController, :following)
318 get("/users/:nickname/outbox", ActivityPubController, :outbox)
323 scope "/", Pleroma.Web.ActivityPub do
324 # XXX: not really ostatus either
325 pipe_through(:ostatus)
326 get("/", ActivityPubController, :relay)
330 scope "/", Pleroma.Web.ActivityPub do
331 pipe_through(:activitypub)
332 post("/users/:nickname/inbox", ActivityPubController, :inbox)
333 post("/inbox", ActivityPubController, :inbox)
336 scope "/.well-known", Pleroma.Web do
337 pipe_through(:well_known)
339 get("/host-meta", WebFinger.WebFingerController, :host_meta)
340 get("/webfinger", WebFinger.WebFingerController, :webfinger)
341 get("/nodeinfo", Nodeinfo.NodeinfoController, :schemas)
344 scope "/nodeinfo", Pleroma.Web do
345 get("/:version", Nodeinfo.NodeinfoController, :nodeinfo)
349 scope "/", Pleroma.Web.MastodonAPI do
350 pipe_through(:mastodon_html)
352 get("/web/login", MastodonAPIController, :login)
353 post("/web/login", MastodonAPIController, :login_post)
354 get("/web/*path", MastodonAPIController, :index)
355 delete("/auth/sign_out", MastodonAPIController, :logout)
358 pipeline :remote_media do
359 plug(:accepts, ["html"])
362 scope "/proxy/", Pleroma.Web.MediaProxy do
363 pipe_through(:remote_media)
364 get("/:sig/:url", MediaProxyController, :remote)
367 scope "/", Fallback do
368 get("/*path", RedirectController, :redirector)
372 defmodule Fallback.RedirectController do
373 use Pleroma.Web, :controller
375 def redirector(conn, _params) do
376 if Mix.env() != :test do
378 |> put_resp_content_type("text/html")
379 |> send_file(200, "priv/static/index.html")