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 @public Keyword.get(@instance, :public)
9 @registrations_open Keyword.get(@instance, :registrations_open)
11 def user_fetcher(username) do
12 {:ok, Repo.get_by(User, %{nickname: username})}
16 plug(:accepts, ["json"])
18 plug(Pleroma.Plugs.OAuthPlug)
19 plug(Pleroma.Plugs.AuthenticationPlug, %{fetcher: &Router.user_fetcher/1, optional: true})
22 pipeline :authenticated_api do
23 plug(:accepts, ["json"])
25 plug(Pleroma.Plugs.OAuthPlug)
26 plug(Pleroma.Plugs.AuthenticationPlug, %{fetcher: &Router.user_fetcher/1})
29 pipeline :mastodon_html do
30 plug(:accepts, ["html"])
32 plug(Pleroma.Plugs.OAuthPlug)
33 plug(Pleroma.Plugs.AuthenticationPlug, %{fetcher: &Router.user_fetcher/1, optional: true})
36 pipeline :pleroma_html do
37 plug(:accepts, ["html"])
39 plug(Pleroma.Plugs.OAuthPlug)
40 plug(Pleroma.Plugs.AuthenticationPlug, %{fetcher: &Router.user_fetcher/1, optional: true})
43 pipeline :well_known do
44 plug(:accepts, ["xml", "xrd+xml", "json", "jrd+json"])
48 plug(:accepts, ["json", "xml"])
52 plug(:accepts, ["html", "json"])
55 pipeline :pleroma_api do
56 plug(:accepts, ["html", "json"])
59 scope "/api/pleroma", Pleroma.Web.TwitterAPI do
60 pipe_through(:pleroma_api)
61 get("/password_reset/:token", UtilController, :show_password_reset)
62 post("/password_reset", UtilController, :password_reset)
63 get("/emoji", UtilController, :emoji)
66 scope "/", Pleroma.Web.TwitterAPI do
67 pipe_through(:pleroma_html)
68 get("/ostatus_subscribe", UtilController, :remote_follow)
69 post("/ostatus_subscribe", UtilController, :do_remote_follow)
70 post("/main/ostatus", UtilController, :remote_subscribe)
73 scope "/api/pleroma", Pleroma.Web.TwitterAPI do
74 pipe_through(:authenticated_api)
75 post("/follow_import", UtilController, :follow_import)
76 post("/delete_account", UtilController, :delete_account)
79 scope "/oauth", Pleroma.Web.OAuth do
80 get("/authorize", OAuthController, :authorize)
81 post("/authorize", OAuthController, :create_authorization)
82 post("/token", OAuthController, :token_exchange)
85 scope "/api/v1", Pleroma.Web.MastodonAPI do
86 pipe_through(:authenticated_api)
88 patch("/accounts/update_credentials", MastodonAPIController, :update_credentials)
89 get("/accounts/verify_credentials", MastodonAPIController, :verify_credentials)
90 get("/accounts/relationships", MastodonAPIController, :relationships)
91 get("/accounts/search", MastodonAPIController, :account_search)
92 post("/accounts/:id/follow", MastodonAPIController, :follow)
93 post("/accounts/:id/unfollow", MastodonAPIController, :unfollow)
94 post("/accounts/:id/block", MastodonAPIController, :block)
95 post("/accounts/:id/unblock", MastodonAPIController, :unblock)
96 post("/accounts/:id/mute", MastodonAPIController, :relationship_noop)
97 post("/accounts/:id/unmute", MastodonAPIController, :relationship_noop)
99 post("/follows", MastodonAPIController, :follow)
101 get("/blocks", MastodonAPIController, :blocks)
103 get("/domain_blocks", MastodonAPIController, :empty_array)
104 get("/follow_requests", MastodonAPIController, :empty_array)
105 get("/mutes", MastodonAPIController, :empty_array)
106 get("/lists", MastodonAPIController, :empty_array)
108 get("/timelines/home", MastodonAPIController, :home_timeline)
110 get("/timelines/direct", MastodonAPIController, :dm_timeline)
112 get("/favourites", MastodonAPIController, :favourites)
114 post("/statuses", MastodonAPIController, :post_status)
115 delete("/statuses/:id", MastodonAPIController, :delete_status)
117 post("/statuses/:id/reblog", MastodonAPIController, :reblog_status)
118 post("/statuses/:id/unreblog", MastodonAPIController, :unreblog_status)
119 post("/statuses/:id/favourite", MastodonAPIController, :fav_status)
120 post("/statuses/:id/unfavourite", MastodonAPIController, :unfav_status)
122 post("/notifications/clear", MastodonAPIController, :clear_notifications)
123 post("/notifications/dismiss", MastodonAPIController, :dismiss_notification)
124 get("/notifications", MastodonAPIController, :notifications)
125 get("/notifications/:id", MastodonAPIController, :get_notification)
127 post("/media", MastodonAPIController, :upload)
130 scope "/api/web", Pleroma.Web.MastodonAPI do
131 pipe_through(:authenticated_api)
133 put("/settings", MastodonAPIController, :put_settings)
136 scope "/api/v1", Pleroma.Web.MastodonAPI do
138 get("/instance", MastodonAPIController, :masto_instance)
139 get("/instance/peers", MastodonAPIController, :peers)
140 post("/apps", MastodonAPIController, :create_app)
141 get("/custom_emojis", MastodonAPIController, :custom_emojis)
143 get("/timelines/public", MastodonAPIController, :public_timeline)
144 get("/timelines/tag/:tag", MastodonAPIController, :hashtag_timeline)
146 get("/statuses/:id", MastodonAPIController, :get_status)
147 get("/statuses/:id/context", MastodonAPIController, :get_context)
148 get("/statuses/:id/card", MastodonAPIController, :empty_object)
149 get("/statuses/:id/favourited_by", MastodonAPIController, :favourited_by)
150 get("/statuses/:id/reblogged_by", MastodonAPIController, :reblogged_by)
152 get("/accounts/:id/statuses", MastodonAPIController, :user_statuses)
153 get("/accounts/:id/followers", MastodonAPIController, :followers)
154 get("/accounts/:id/following", MastodonAPIController, :following)
155 get("/accounts/:id", MastodonAPIController, :user)
157 get("/search", MastodonAPIController, :search)
160 scope "/api", Pleroma.Web do
161 pipe_through(:config)
163 get("/help/test", TwitterAPI.UtilController, :help_test)
164 post("/help/test", TwitterAPI.UtilController, :help_test)
165 get("/statusnet/config", TwitterAPI.UtilController, :config)
166 get("/statusnet/version", TwitterAPI.UtilController, :version)
169 scope "/api", Pleroma.Web do
172 get("/statuses/user_timeline", TwitterAPI.Controller, :user_timeline)
173 get("/qvitter/statuses/user_timeline", TwitterAPI.Controller, :user_timeline)
174 get("/users/show", TwitterAPI.Controller, :show_user)
176 get("/statuses/followers", TwitterAPI.Controller, :followers)
177 get("/statuses/friends", TwitterAPI.Controller, :friends)
178 get("/statuses/show/:id", TwitterAPI.Controller, :fetch_status)
179 get("/statusnet/conversation/:id", TwitterAPI.Controller, :fetch_conversation)
181 if @registrations_open do
182 post("/account/register", TwitterAPI.Controller, :register)
185 get("/search", TwitterAPI.Controller, :search)
186 get("/statusnet/tags/timeline/:tag", TwitterAPI.Controller, :public_and_external_timeline)
189 scope "/api", Pleroma.Web do
193 pipe_through(:authenticated_api)
196 get("/statuses/public_timeline", TwitterAPI.Controller, :public_timeline)
199 "/statuses/public_and_external_timeline",
200 TwitterAPI.Controller,
201 :public_and_external_timeline
204 get("/statuses/networkpublic_timeline", TwitterAPI.Controller, :public_and_external_timeline)
207 scope "/api", Pleroma.Web do
208 pipe_through(:authenticated_api)
210 get("/account/verify_credentials", TwitterAPI.Controller, :verify_credentials)
211 post("/account/verify_credentials", TwitterAPI.Controller, :verify_credentials)
213 post("/account/update_profile", TwitterAPI.Controller, :update_profile)
214 post("/account/update_profile_banner", TwitterAPI.Controller, :update_banner)
215 post("/qvitter/update_background_image", TwitterAPI.Controller, :update_background)
218 "/account/most_recent_notification",
219 TwitterAPI.Controller,
220 :update_most_recent_notification
223 get("/statuses/home_timeline", TwitterAPI.Controller, :friends_timeline)
224 get("/statuses/friends_timeline", TwitterAPI.Controller, :friends_timeline)
225 get("/statuses/mentions", TwitterAPI.Controller, :mentions_timeline)
226 get("/statuses/mentions_timeline", TwitterAPI.Controller, :mentions_timeline)
227 get("/qvitter/statuses/notifications", TwitterAPI.Controller, :notifications)
229 post("/statuses/update", TwitterAPI.Controller, :status_update)
230 post("/statuses/retweet/:id", TwitterAPI.Controller, :retweet)
231 post("/statuses/destroy/:id", TwitterAPI.Controller, :delete_post)
233 post("/friendships/create", TwitterAPI.Controller, :follow)
234 post("/friendships/destroy", TwitterAPI.Controller, :unfollow)
235 post("/blocks/create", TwitterAPI.Controller, :block)
236 post("/blocks/destroy", TwitterAPI.Controller, :unblock)
238 post("/statusnet/media/upload", TwitterAPI.Controller, :upload)
239 post("/media/upload", TwitterAPI.Controller, :upload_json)
241 post("/favorites/create/:id", TwitterAPI.Controller, :favorite)
242 post("/favorites/create", TwitterAPI.Controller, :favorite)
243 post("/favorites/destroy/:id", TwitterAPI.Controller, :unfavorite)
245 post("/qvitter/update_avatar", TwitterAPI.Controller, :update_avatar)
247 get("/friends/ids", TwitterAPI.Controller, :friends_ids)
248 get("/friendships/no_retweets/ids", TwitterAPI.Controller, :empty_array)
250 get("/mutes/users/ids", TwitterAPI.Controller, :empty_array)
252 get("/externalprofile/show", TwitterAPI.Controller, :external_profile)
256 plug(:accepts, ["xml", "atom", "html", "activity+json"])
259 scope "/", Pleroma.Web do
260 pipe_through(:ostatus)
262 get("/objects/:uuid", OStatus.OStatusController, :object)
263 get("/activities/:uuid", OStatus.OStatusController, :activity)
264 get("/notice/:id", OStatus.OStatusController, :notice)
265 get("/users/:nickname/feed", OStatus.OStatusController, :feed)
266 get("/users/:nickname", OStatus.OStatusController, :feed_redirect)
269 post("/users/:nickname/salmon", OStatus.OStatusController, :salmon_incoming)
270 post("/push/hub/:nickname", Websub.WebsubController, :websub_subscription_request)
271 get("/push/subscriptions/:id", Websub.WebsubController, :websub_subscription_confirmation)
272 post("/push/subscriptions/:id", Websub.WebsubController, :websub_incoming)
276 pipeline :activitypub do
277 plug(:accepts, ["activity+json"])
278 plug(Pleroma.Web.Plugs.HTTPSignaturePlug)
281 scope "/", Pleroma.Web.ActivityPub do
282 # XXX: not really ostatus
283 pipe_through(:ostatus)
285 get("/users/:nickname/followers", ActivityPubController, :followers)
286 get("/users/:nickname/following", ActivityPubController, :following)
287 get("/users/:nickname/outbox", ActivityPubController, :outbox)
291 scope "/", Pleroma.Web.ActivityPub do
292 pipe_through(:activitypub)
293 post("/users/:nickname/inbox", ActivityPubController, :inbox)
294 post("/inbox", ActivityPubController, :inbox)
297 scope "/.well-known", Pleroma.Web do
298 pipe_through(:well_known)
300 get("/host-meta", WebFinger.WebFingerController, :host_meta)
301 get("/webfinger", WebFinger.WebFingerController, :webfinger)
302 get("/nodeinfo", Nodeinfo.NodeinfoController, :schemas)
305 scope "/nodeinfo", Pleroma.Web do
306 get("/:version", Nodeinfo.NodeinfoController, :nodeinfo)
310 scope "/", Pleroma.Web.MastodonAPI do
311 pipe_through(:mastodon_html)
313 get("/web/login", MastodonAPIController, :login)
314 post("/web/login", MastodonAPIController, :login_post)
315 get("/web/*path", MastodonAPIController, :index)
316 delete("/auth/sign_out", MastodonAPIController, :logout)
319 pipeline :remote_media do
320 plug(:accepts, ["html"])
323 scope "/proxy/", Pleroma.Web.MediaProxy do
324 pipe_through(:remote_media)
325 get("/:sig/:url", MediaProxyController, :remote)
328 scope "/", Fallback do
329 get("/*path", RedirectController, :redirector)
333 defmodule Fallback.RedirectController do
334 use Pleroma.Web, :controller
336 def redirector(conn, _params) do
337 if Mix.env() != :test do
339 |> put_resp_content_type("text/html")
340 |> send_file(200, "priv/static/index.html")