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"]
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
104 get "/timelines/home", MastodonAPIController, :home_timeline
106 get "/favourites", MastodonAPIController, :favourites
108 post "/statuses", MastodonAPIController, :post_status
109 delete "/statuses/:id", MastodonAPIController, :delete_status
111 post "/statuses/:id/reblog", MastodonAPIController, :reblog_status
112 post "/statuses/:id/favourite", MastodonAPIController, :fav_status
113 post "/statuses/:id/unfavourite", MastodonAPIController, :unfav_status
115 post "/notifications/clear", MastodonAPIController, :clear_notifications
116 post "/notifications/dismiss", MastodonAPIController, :dismiss_notification
117 get "/notifications", MastodonAPIController, :notifications
118 get "/notifications/:id", MastodonAPIController, :get_notification
120 post "/media", MastodonAPIController, :upload
123 scope "/api/v1", Pleroma.Web.MastodonAPI do
125 get "/instance", MastodonAPIController, :masto_instance
126 get "/instance/peers", MastodonAPIController, :peers
127 post "/apps", MastodonAPIController, :create_app
128 get "/custom_emojis", MastodonAPIController, :custom_emojis
130 get "/timelines/public", MastodonAPIController, :public_timeline
131 get "/timelines/tag/:tag", MastodonAPIController, :hashtag_timeline
133 get "/statuses/:id", MastodonAPIController, :get_status
134 get "/statuses/:id/context", MastodonAPIController, :get_context
135 get "/statuses/:id/favourited_by", MastodonAPIController, :favourited_by
136 get "/statuses/:id/reblogged_by", MastodonAPIController, :reblogged_by
138 get "/accounts/:id/statuses", MastodonAPIController, :user_statuses
139 get "/accounts/:id/followers", MastodonAPIController, :followers
140 get "/accounts/:id/following", MastodonAPIController, :following
141 get "/accounts/:id", MastodonAPIController, :user
143 get "/search", MastodonAPIController, :search
146 scope "/api", Pleroma.Web do
149 get "/help/test", TwitterAPI.UtilController, :help_test
150 post "/help/test", TwitterAPI.UtilController, :help_test
151 get "/statusnet/config", TwitterAPI.UtilController, :config
152 get "/statusnet/version", TwitterAPI.UtilController, :version
155 @instance Application.get_env(:pleroma, :instance)
156 @registrations_open Keyword.get(@instance, :registrations_open)
158 scope "/api", Pleroma.Web do
161 get "/statuses/public_timeline", TwitterAPI.Controller, :public_timeline
162 get "/statuses/public_and_external_timeline", TwitterAPI.Controller, :public_and_external_timeline
163 get "/statuses/networkpublic_timeline", TwitterAPI.Controller, :public_and_external_timeline
164 get "/statuses/user_timeline", TwitterAPI.Controller, :user_timeline
165 get "/qvitter/statuses/user_timeline", TwitterAPI.Controller, :user_timeline
166 get "/users/show", TwitterAPI.Controller, :show_user
168 get "/statuses/followers", TwitterAPI.Controller, :followers
169 get "/statuses/friends", TwitterAPI.Controller, :friends
170 get "/statuses/show/:id", TwitterAPI.Controller, :fetch_status
171 get "/statusnet/conversation/:id", TwitterAPI.Controller, :fetch_conversation
173 if @registrations_open do
174 post "/account/register", TwitterAPI.Controller, :register
177 get "/search", TwitterAPI.Controller, :search
178 get "/statusnet/tags/timeline/:tag", TwitterAPI.Controller, :public_and_external_timeline
181 scope "/api", Pleroma.Web do
182 pipe_through :authenticated_api
184 get "/account/verify_credentials", TwitterAPI.Controller, :verify_credentials
185 post "/account/verify_credentials", TwitterAPI.Controller, :verify_credentials
187 post "/account/update_profile", TwitterAPI.Controller, :update_profile
188 post "/account/update_profile_banner", TwitterAPI.Controller, :update_banner
189 post "/qvitter/update_background_image", TwitterAPI.Controller, :update_background
191 post "/account/most_recent_notification", TwitterAPI.Controller, :update_most_recent_notification
193 get "/statuses/home_timeline", TwitterAPI.Controller, :friends_timeline
194 get "/statuses/friends_timeline", TwitterAPI.Controller, :friends_timeline
195 get "/statuses/mentions", TwitterAPI.Controller, :mentions_timeline
196 get "/statuses/mentions_timeline", TwitterAPI.Controller, :mentions_timeline
198 post "/statuses/update", TwitterAPI.Controller, :status_update
199 post "/statuses/retweet/:id", TwitterAPI.Controller, :retweet
200 post "/statuses/destroy/:id", TwitterAPI.Controller, :delete_post
202 post "/friendships/create", TwitterAPI.Controller, :follow
203 post "/friendships/destroy", TwitterAPI.Controller, :unfollow
204 post "/blocks/create", TwitterAPI.Controller, :block
205 post "/blocks/destroy", TwitterAPI.Controller, :unblock
207 post "/statusnet/media/upload", TwitterAPI.Controller, :upload
208 post "/media/upload", TwitterAPI.Controller, :upload_json
210 post "/favorites/create/:id", TwitterAPI.Controller, :favorite
211 post "/favorites/create", TwitterAPI.Controller, :favorite
212 post "/favorites/destroy/:id", TwitterAPI.Controller, :unfavorite
214 post "/qvitter/update_avatar", TwitterAPI.Controller, :update_avatar
216 get "/friends/ids", TwitterAPI.Controller, :friends_ids
217 get "/friendships/no_retweets/ids", TwitterAPI.Controller, :empty_array
219 get "/mutes/users/ids", TwitterAPI.Controller, :empty_array
221 get "/externalprofile/show", TwitterAPI.Controller, :external_profile
225 plug :accepts, ["xml", "atom", "html"]
228 scope "/", Pleroma.Web do
229 pipe_through :ostatus
231 get "/objects/:uuid", OStatus.OStatusController, :object
232 get "/activities/:uuid", OStatus.OStatusController, :activity
233 get "/notice/:id", OStatus.OStatusController, :notice
234 get "/users/:nickname/feed", OStatus.OStatusController, :feed
235 get "/users/:nickname", OStatus.OStatusController, :feed_redirect
238 post "/users/:nickname/salmon", OStatus.OStatusController, :salmon_incoming
239 post "/push/hub/:nickname", Websub.WebsubController, :websub_subscription_request
240 get "/push/subscriptions/:id", Websub.WebsubController, :websub_subscription_confirmation
241 post "/push/subscriptions/:id", Websub.WebsubController, :websub_incoming
247 scope "/.well-known", Pleroma.Web do
248 pipe_through :well_known
250 get "/host-meta", WebFinger.WebFingerController, :host_meta
251 get "/webfinger", WebFinger.WebFingerController, :webfinger
255 scope "/", Pleroma.Web.MastodonAPI do
256 pipe_through :mastodon_html
258 get "/web/login", MastodonAPIController, :login
259 post "/web/login", MastodonAPIController, :login_post
260 get "/web/*path", MastodonAPIController, :index
261 delete "/auth/sign_out", MastodonAPIController, :logout
264 pipeline :remote_media do
265 plug :accepts, ["html"]
267 scope "/proxy/", Pleroma.Web.MediaProxy do
268 pipe_through :remote_media
269 get "/:sig/:url", MediaProxyController, :remote
272 scope "/", Fallback do
273 get "/*path", RedirectController, :redirector
277 defmodule Fallback.RedirectController do
278 use Pleroma.Web, :controller
279 def redirector(conn, _params) do
280 if Mix.env != :test do
282 |> put_resp_content_type("text/html")
283 |> send_file(200, "priv/static/index.html")