1 defmodule Pleroma.Web.Router do
2 use Pleroma.Web, :router
4 alias Pleroma.{Repo, User, Web.Router}
6 def user_fetcher(username) do
7 {:ok, Repo.get_by(User, %{nickname: username})}
11 plug :accepts, ["json"]
13 plug Pleroma.Plugs.OAuthPlug
14 plug Pleroma.Plugs.AuthenticationPlug, %{fetcher: &Router.user_fetcher/1, optional: true}
17 pipeline :authenticated_api do
18 plug :accepts, ["json"]
20 plug Pleroma.Plugs.OAuthPlug
21 plug Pleroma.Plugs.AuthenticationPlug, %{fetcher: &Router.user_fetcher/1}
24 pipeline :mastodon_html do
25 plug :accepts, ["html"]
27 plug Pleroma.Plugs.OAuthPlug
28 plug Pleroma.Plugs.AuthenticationPlug, %{fetcher: &Router.user_fetcher/1, optional: true}
31 pipeline :well_known do
32 plug :accepts, ["xml", "xrd+xml"]
36 plug :accepts, ["json", "xml"]
40 plug :accepts, ["html", "json"]
43 pipeline :pleroma_api do
44 plug :accepts, ["html", "json"]
47 scope "/api/pleroma", Pleroma.Web.TwitterAPI do
48 pipe_through :pleroma_api
49 get "/password_reset/:token", UtilController, :show_password_reset
50 post "/password_reset", UtilController, :password_reset
51 get "/emoji", UtilController, :emoji
54 scope "/oauth", Pleroma.Web.OAuth do
55 get "/authorize", OAuthController, :authorize
56 post "/authorize", OAuthController, :create_authorization
57 post "/token", OAuthController, :token_exchange
60 scope "/api/v1", Pleroma.Web.MastodonAPI do
61 pipe_through :authenticated_api
63 patch "/accounts/update_credentials", MastodonAPIController, :update_credentials
64 get "/accounts/verify_credentials", MastodonAPIController, :verify_credentials
65 get "/accounts/relationships", MastodonAPIController, :relationships
66 get "/accounts/search", MastodonAPIController, :account_search
67 post "/accounts/:id/follow", MastodonAPIController, :follow
68 post "/accounts/:id/unfollow", MastodonAPIController, :unfollow
69 post "/accounts/:id/block", MastodonAPIController, :block
70 post "/accounts/:id/unblock", MastodonAPIController, :unblock
71 post "/accounts/:id/mute", MastodonAPIController, :relationship_noop
72 post "/accounts/:id/unmute", MastodonAPIController, :relationship_noop
74 post "/follows", MastodonAPIController, :follow
76 get "/blocks", MastodonAPIController, :blocks
78 get "/domain_blocks", MastodonAPIController, :empty_array
79 get "/follow_requests", MastodonAPIController, :empty_array
80 get "/mutes", MastodonAPIController, :empty_array
82 get "/timelines/home", MastodonAPIController, :home_timeline
84 get "/favourites", MastodonAPIController, :favourites
86 post "/statuses", MastodonAPIController, :post_status
87 delete "/statuses/:id", MastodonAPIController, :delete_status
89 post "/statuses/:id/reblog", MastodonAPIController, :reblog_status
90 post "/statuses/:id/favourite", MastodonAPIController, :fav_status
91 post "/statuses/:id/unfavourite", MastodonAPIController, :unfav_status
93 post "/notifications/clear", MastodonAPIController, :clear_notifications
94 post "/notifications/dismiss", MastodonAPIController, :dismiss_notification
95 get "/notifications", MastodonAPIController, :notifications
96 get "/notifications/:id", MastodonAPIController, :get_notification
98 post "/media", MastodonAPIController, :upload
101 scope "/api/v1", Pleroma.Web.MastodonAPI do
103 get "/instance", MastodonAPIController, :masto_instance
104 post "/apps", MastodonAPIController, :create_app
105 get "/custom_emojis", MastodonAPIController, :custom_emojis
107 get "/timelines/public", MastodonAPIController, :public_timeline
108 get "/timelines/tag/:tag", MastodonAPIController, :hashtag_timeline
110 get "/statuses/:id", MastodonAPIController, :get_status
111 get "/statuses/:id/context", MastodonAPIController, :get_context
112 get "/statuses/:id/favourited_by", MastodonAPIController, :favourited_by
113 get "/statuses/:id/reblogged_by", MastodonAPIController, :reblogged_by
115 get "/accounts/:id/statuses", MastodonAPIController, :user_statuses
116 get "/accounts/:id/followers", MastodonAPIController, :followers
117 get "/accounts/:id/following", MastodonAPIController, :following
118 get "/accounts/:id", MastodonAPIController, :user
120 get "/search", MastodonAPIController, :search
123 scope "/api", Pleroma.Web do
126 get "/help/test", TwitterAPI.UtilController, :help_test
127 post "/help/test", TwitterAPI.UtilController, :help_test
128 get "/statusnet/config", TwitterAPI.UtilController, :config
129 get "/statusnet/version", TwitterAPI.UtilController, :version
132 @instance Application.get_env(:pleroma, :instance)
133 @registrations_open Keyword.get(@instance, :registrations_open)
135 scope "/api", Pleroma.Web do
138 get "/statuses/public_timeline", TwitterAPI.Controller, :public_timeline
139 get "/statuses/public_and_external_timeline", TwitterAPI.Controller, :public_and_external_timeline
140 get "/statuses/networkpublic_timeline", TwitterAPI.Controller, :public_and_external_timeline
141 get "/statuses/user_timeline", TwitterAPI.Controller, :user_timeline
142 get "/qvitter/statuses/user_timeline", TwitterAPI.Controller, :user_timeline
143 get "/users/show", TwitterAPI.Controller, :show_user
145 get "/statuses/followers", TwitterAPI.Controller, :followers
146 get "/statuses/friends", TwitterAPI.Controller, :friends
147 get "/statuses/show/:id", TwitterAPI.Controller, :fetch_status
148 get "/statusnet/conversation/:id", TwitterAPI.Controller, :fetch_conversation
150 if @registrations_open do
151 post "/account/register", TwitterAPI.Controller, :register
154 get "/search", TwitterAPI.Controller, :search
155 get "/statusnet/tags/timeline/:tag", TwitterAPI.Controller, :public_and_external_timeline
158 scope "/api", Pleroma.Web do
159 pipe_through :authenticated_api
161 get "/account/verify_credentials", TwitterAPI.Controller, :verify_credentials
162 post "/account/verify_credentials", TwitterAPI.Controller, :verify_credentials
164 post "/account/update_profile", TwitterAPI.Controller, :update_profile
165 post "/account/update_profile_banner", TwitterAPI.Controller, :update_banner
166 post "/qvitter/update_background_image", TwitterAPI.Controller, :update_background
168 post "/account/most_recent_notification", TwitterAPI.Controller, :update_most_recent_notification
170 get "/statuses/home_timeline", TwitterAPI.Controller, :friends_timeline
171 get "/statuses/friends_timeline", TwitterAPI.Controller, :friends_timeline
172 get "/statuses/mentions", TwitterAPI.Controller, :mentions_timeline
173 get "/statuses/mentions_timeline", TwitterAPI.Controller, :mentions_timeline
175 post "/statuses/update", TwitterAPI.Controller, :status_update
176 post "/statuses/retweet/:id", TwitterAPI.Controller, :retweet
177 post "/statuses/destroy/:id", TwitterAPI.Controller, :delete_post
179 post "/friendships/create", TwitterAPI.Controller, :follow
180 post "/friendships/destroy", TwitterAPI.Controller, :unfollow
181 post "/blocks/create", TwitterAPI.Controller, :block
182 post "/blocks/destroy", TwitterAPI.Controller, :unblock
184 post "/statusnet/media/upload", TwitterAPI.Controller, :upload
185 post "/media/upload", TwitterAPI.Controller, :upload_json
187 post "/favorites/create/:id", TwitterAPI.Controller, :favorite
188 post "/favorites/create", TwitterAPI.Controller, :favorite
189 post "/favorites/destroy/:id", TwitterAPI.Controller, :unfavorite
191 post "/qvitter/update_avatar", TwitterAPI.Controller, :update_avatar
193 get "/friends/ids", TwitterAPI.Controller, :friends_ids
194 get "/friendships/no_retweets/ids", TwitterAPI.Controller, :empty_array
196 get "/mutes/users/ids", TwitterAPI.Controller, :empty_array
198 get "/externalprofile/show", TwitterAPI.Controller, :external_profile
202 plug :accepts, ["xml", "atom", "html"]
205 scope "/", Pleroma.Web do
206 pipe_through :ostatus
208 get "/objects/:uuid", OStatus.OStatusController, :object
209 get "/activities/:uuid", OStatus.OStatusController, :activity
210 get "/notice/:id", OStatus.OStatusController, :notice
212 get "/users/:nickname/feed", OStatus.OStatusController, :feed
213 get "/users/:nickname", OStatus.OStatusController, :feed_redirect
214 post "/users/:nickname/salmon", OStatus.OStatusController, :salmon_incoming
215 post "/push/hub/:nickname", Websub.WebsubController, :websub_subscription_request
216 get "/push/subscriptions/:id", Websub.WebsubController, :websub_subscription_confirmation
217 post "/push/subscriptions/:id", Websub.WebsubController, :websub_incoming
220 scope "/.well-known", Pleroma.Web do
221 pipe_through :well_known
223 get "/host-meta", WebFinger.WebFingerController, :host_meta
224 get "/webfinger", WebFinger.WebFingerController, :webfinger
227 scope "/", Pleroma.Web.MastodonAPI do
228 pipe_through :mastodon_html
230 get "/web/login", MastodonAPIController, :login
231 post "/web/login", MastodonAPIController, :login_post
232 get "/web/*path", MastodonAPIController, :index
233 delete "/auth/sign_out", MastodonAPIController, :logout
236 scope "/", Fallback do
237 get "/*path", RedirectController, :redirector
241 defmodule Fallback.RedirectController do
242 use Pleroma.Web, :controller
243 def redirector(conn, _params) do
244 if Mix.env != :test do
246 |> put_resp_content_type("text/html")
247 |> send_file(200, "priv/static/index.html")