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)
9 def user_fetcher(username) do
10 {:ok, Repo.get_by(User, %{nickname: username})}
14 plug(:accepts, ["json"])
16 plug(Pleroma.Plugs.OAuthPlug)
17 plug(Pleroma.Plugs.AuthenticationPlug, %{fetcher: &Router.user_fetcher/1, optional: true})
20 pipeline :authenticated_api do
21 plug(:accepts, ["json"])
23 plug(Pleroma.Plugs.OAuthPlug)
24 plug(Pleroma.Plugs.AuthenticationPlug, %{fetcher: &Router.user_fetcher/1})
27 pipeline :mastodon_html do
28 plug(:accepts, ["html"])
30 plug(Pleroma.Plugs.OAuthPlug)
31 plug(Pleroma.Plugs.AuthenticationPlug, %{fetcher: &Router.user_fetcher/1, optional: true})
34 pipeline :pleroma_html do
35 plug(:accepts, ["html"])
37 plug(Pleroma.Plugs.OAuthPlug)
38 plug(Pleroma.Plugs.AuthenticationPlug, %{fetcher: &Router.user_fetcher/1, optional: true})
41 pipeline :well_known do
42 plug(:accepts, ["xml", "xrd+xml", "json", "jrd+json"])
46 plug(:accepts, ["json", "xml"])
50 plug(:accepts, ["html", "json"])
53 pipeline :pleroma_api do
54 plug(:accepts, ["html", "json"])
57 scope "/api/pleroma", Pleroma.Web.TwitterAPI do
58 pipe_through(:pleroma_api)
59 get("/password_reset/:token", UtilController, :show_password_reset)
60 post("/password_reset", UtilController, :password_reset)
61 get("/emoji", UtilController, :emoji)
64 scope "/", Pleroma.Web.TwitterAPI do
65 pipe_through(:pleroma_html)
66 get("/ostatus_subscribe", UtilController, :remote_follow)
67 post("/ostatus_subscribe", UtilController, :do_remote_follow)
68 post("/main/ostatus", UtilController, :remote_subscribe)
71 scope "/api/pleroma", Pleroma.Web.TwitterAPI do
72 pipe_through(:authenticated_api)
73 post("/follow_import", UtilController, :follow_import)
76 scope "/oauth", Pleroma.Web.OAuth do
77 get("/authorize", OAuthController, :authorize)
78 post("/authorize", OAuthController, :create_authorization)
79 post("/token", OAuthController, :token_exchange)
82 scope "/api/v1", Pleroma.Web.MastodonAPI do
83 pipe_through(:authenticated_api)
85 patch("/accounts/update_credentials", MastodonAPIController, :update_credentials)
86 get("/accounts/verify_credentials", MastodonAPIController, :verify_credentials)
87 get("/accounts/relationships", MastodonAPIController, :relationships)
88 get("/accounts/search", MastodonAPIController, :account_search)
89 post("/accounts/:id/follow", MastodonAPIController, :follow)
90 post("/accounts/:id/unfollow", MastodonAPIController, :unfollow)
91 post("/accounts/:id/block", MastodonAPIController, :block)
92 post("/accounts/:id/unblock", MastodonAPIController, :unblock)
93 post("/accounts/:id/mute", MastodonAPIController, :relationship_noop)
94 post("/accounts/:id/unmute", MastodonAPIController, :relationship_noop)
96 post("/follows", MastodonAPIController, :follow)
98 get("/blocks", MastodonAPIController, :blocks)
100 get("/domain_blocks", MastodonAPIController, :empty_array)
101 get("/follow_requests", MastodonAPIController, :empty_array)
102 get("/mutes", MastodonAPIController, :empty_array)
103 get("/lists", MastodonAPIController, :empty_array)
105 get("/timelines/home", MastodonAPIController, :home_timeline)
107 get("/favourites", MastodonAPIController, :favourites)
109 post("/statuses", MastodonAPIController, :post_status)
110 delete("/statuses/:id", MastodonAPIController, :delete_status)
112 post("/statuses/:id/reblog", MastodonAPIController, :reblog_status)
113 post("/statuses/:id/unreblog", MastodonAPIController, :unreblog_status)
114 post("/statuses/:id/favourite", MastodonAPIController, :fav_status)
115 post("/statuses/:id/unfavourite", MastodonAPIController, :unfav_status)
117 post("/notifications/clear", MastodonAPIController, :clear_notifications)
118 post("/notifications/dismiss", MastodonAPIController, :dismiss_notification)
119 get("/notifications", MastodonAPIController, :notifications)
120 get("/notifications/:id", MastodonAPIController, :get_notification)
122 post("/media", MastodonAPIController, :upload)
125 scope "/api/web", Pleroma.Web.MastodonAPI do
126 pipe_through(:authenticated_api)
128 put("/settings", MastodonAPIController, :put_settings)
131 scope "/api/v1", Pleroma.Web.MastodonAPI do
133 get("/instance", MastodonAPIController, :masto_instance)
134 get("/instance/peers", MastodonAPIController, :peers)
135 post("/apps", MastodonAPIController, :create_app)
136 get("/custom_emojis", MastodonAPIController, :custom_emojis)
138 get("/timelines/public", MastodonAPIController, :public_timeline)
139 get("/timelines/tag/:tag", MastodonAPIController, :hashtag_timeline)
141 get("/statuses/:id", MastodonAPIController, :get_status)
142 get("/statuses/:id/context", MastodonAPIController, :get_context)
143 get("/statuses/:id/card", MastodonAPIController, :empty_object)
144 get("/statuses/:id/favourited_by", MastodonAPIController, :favourited_by)
145 get("/statuses/:id/reblogged_by", MastodonAPIController, :reblogged_by)
147 get("/accounts/:id/statuses", MastodonAPIController, :user_statuses)
148 get("/accounts/:id/followers", MastodonAPIController, :followers)
149 get("/accounts/:id/following", MastodonAPIController, :following)
150 get("/accounts/:id", MastodonAPIController, :user)
152 get("/search", MastodonAPIController, :search)
155 scope "/api", Pleroma.Web do
156 pipe_through(:config)
158 get("/help/test", TwitterAPI.UtilController, :help_test)
159 post("/help/test", TwitterAPI.UtilController, :help_test)
160 get("/statusnet/config", TwitterAPI.UtilController, :config)
161 get("/statusnet/version", TwitterAPI.UtilController, :version)
164 @instance Application.get_env(:pleroma, :instance)
165 @registrations_open Keyword.get(@instance, :registrations_open)
167 scope "/api", Pleroma.Web do
170 get("/statuses/public_timeline", TwitterAPI.Controller, :public_timeline)
173 "/statuses/public_and_external_timeline",
174 TwitterAPI.Controller,
175 :public_and_external_timeline
178 get("/statuses/networkpublic_timeline", TwitterAPI.Controller, :public_and_external_timeline)
179 get("/statuses/user_timeline", TwitterAPI.Controller, :user_timeline)
180 get("/qvitter/statuses/user_timeline", TwitterAPI.Controller, :user_timeline)
181 get("/users/show", TwitterAPI.Controller, :show_user)
183 get("/statuses/followers", TwitterAPI.Controller, :followers)
184 get("/statuses/friends", TwitterAPI.Controller, :friends)
185 get("/statuses/show/:id", TwitterAPI.Controller, :fetch_status)
186 get("/statusnet/conversation/:id", TwitterAPI.Controller, :fetch_conversation)
188 if @registrations_open do
189 post("/account/register", TwitterAPI.Controller, :register)
192 get("/search", TwitterAPI.Controller, :search)
193 get("/statusnet/tags/timeline/:tag", TwitterAPI.Controller, :public_and_external_timeline)
196 scope "/api", Pleroma.Web do
197 pipe_through(:authenticated_api)
199 get("/account/verify_credentials", TwitterAPI.Controller, :verify_credentials)
200 post("/account/verify_credentials", TwitterAPI.Controller, :verify_credentials)
202 post("/account/update_profile", TwitterAPI.Controller, :update_profile)
203 post("/account/update_profile_banner", TwitterAPI.Controller, :update_banner)
204 post("/qvitter/update_background_image", TwitterAPI.Controller, :update_background)
207 "/account/most_recent_notification",
208 TwitterAPI.Controller,
209 :update_most_recent_notification
212 get("/statuses/home_timeline", TwitterAPI.Controller, :friends_timeline)
213 get("/statuses/friends_timeline", TwitterAPI.Controller, :friends_timeline)
214 get("/statuses/mentions", TwitterAPI.Controller, :mentions_timeline)
215 get("/statuses/mentions_timeline", TwitterAPI.Controller, :mentions_timeline)
216 get("/qvitter/statuses/notifications", TwitterAPI.Controller, :notifications)
218 post("/statuses/update", TwitterAPI.Controller, :status_update)
219 post("/statuses/retweet/:id", TwitterAPI.Controller, :retweet)
220 post("/statuses/destroy/:id", TwitterAPI.Controller, :delete_post)
222 post("/friendships/create", TwitterAPI.Controller, :follow)
223 post("/friendships/destroy", TwitterAPI.Controller, :unfollow)
224 post("/blocks/create", TwitterAPI.Controller, :block)
225 post("/blocks/destroy", TwitterAPI.Controller, :unblock)
227 post("/statusnet/media/upload", TwitterAPI.Controller, :upload)
228 post("/media/upload", TwitterAPI.Controller, :upload_json)
230 post("/favorites/create/:id", TwitterAPI.Controller, :favorite)
231 post("/favorites/create", TwitterAPI.Controller, :favorite)
232 post("/favorites/destroy/:id", TwitterAPI.Controller, :unfavorite)
234 post("/qvitter/update_avatar", TwitterAPI.Controller, :update_avatar)
236 get("/friends/ids", TwitterAPI.Controller, :friends_ids)
237 get("/friendships/no_retweets/ids", TwitterAPI.Controller, :empty_array)
239 get("/mutes/users/ids", TwitterAPI.Controller, :empty_array)
241 get("/externalprofile/show", TwitterAPI.Controller, :external_profile)
245 plug(:accepts, ["xml", "atom", "html", "activity+json"])
248 scope "/", Pleroma.Web do
249 pipe_through(:ostatus)
251 get("/objects/:uuid", OStatus.OStatusController, :object)
252 get("/activities/:uuid", OStatus.OStatusController, :activity)
253 get("/notice/:id", OStatus.OStatusController, :notice)
254 get("/users/:nickname/feed", OStatus.OStatusController, :feed)
255 get("/users/:nickname", OStatus.OStatusController, :feed_redirect)
258 post("/users/:nickname/salmon", OStatus.OStatusController, :salmon_incoming)
259 post("/push/hub/:nickname", Websub.WebsubController, :websub_subscription_request)
260 get("/push/subscriptions/:id", Websub.WebsubController, :websub_subscription_confirmation)
261 post("/push/subscriptions/:id", Websub.WebsubController, :websub_incoming)
265 pipeline :activitypub do
266 plug(:accepts, ["activity+json"])
267 plug(Pleroma.Web.Plugs.HTTPSignaturePlug)
270 scope "/", Pleroma.Web.ActivityPub do
271 # XXX: not really ostatus
272 pipe_through(:ostatus)
274 get("/users/:nickname/followers", ActivityPubController, :followers)
275 get("/users/:nickname/following", ActivityPubController, :following)
276 get("/users/:nickname/outbox", ActivityPubController, :outbox)
280 scope "/", Pleroma.Web.ActivityPub do
281 pipe_through(:activitypub)
282 post("/users/:nickname/inbox", ActivityPubController, :inbox)
283 post("/inbox", ActivityPubController, :inbox)
286 scope "/.well-known", Pleroma.Web do
287 pipe_through(:well_known)
289 get("/host-meta", WebFinger.WebFingerController, :host_meta)
290 get("/webfinger", WebFinger.WebFingerController, :webfinger)
294 scope "/", Pleroma.Web.MastodonAPI do
295 pipe_through(:mastodon_html)
297 get("/web/login", MastodonAPIController, :login)
298 post("/web/login", MastodonAPIController, :login_post)
299 get("/web/*path", MastodonAPIController, :index)
300 delete("/auth/sign_out", MastodonAPIController, :logout)
303 pipeline :remote_media do
304 plug(:accepts, ["html"])
307 scope "/proxy/", Pleroma.Web.MediaProxy do
308 pipe_through(:remote_media)
309 get("/:sig/:url", MediaProxyController, :remote)
312 scope "/", Fallback do
313 get("/*path", RedirectController, :redirector)
317 defmodule Fallback.RedirectController do
318 use Pleroma.Web, :controller
320 def redirector(conn, _params) do
321 if Mix.env() != :test do
323 |> put_resp_content_type("text/html")
324 |> send_file(200, "priv/static/index.html")