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 "/api/pleroma", Pleroma.Web.TwitterAPI do
55 pipe_through :authenticated_api
56 post "/follow_import", UtilController, :follow_import
59 scope "/oauth", Pleroma.Web.OAuth do
60 get "/authorize", OAuthController, :authorize
61 post "/authorize", OAuthController, :create_authorization
62 post "/token", OAuthController, :token_exchange
65 scope "/api/v1", Pleroma.Web.MastodonAPI do
66 pipe_through :authenticated_api
68 patch "/accounts/update_credentials", MastodonAPIController, :update_credentials
69 get "/accounts/verify_credentials", MastodonAPIController, :verify_credentials
70 get "/accounts/relationships", MastodonAPIController, :relationships
71 get "/accounts/search", MastodonAPIController, :account_search
72 post "/accounts/:id/follow", MastodonAPIController, :follow
73 post "/accounts/:id/unfollow", MastodonAPIController, :unfollow
74 post "/accounts/:id/block", MastodonAPIController, :block
75 post "/accounts/:id/unblock", MastodonAPIController, :unblock
76 post "/accounts/:id/mute", MastodonAPIController, :relationship_noop
77 post "/accounts/:id/unmute", MastodonAPIController, :relationship_noop
79 post "/follows", MastodonAPIController, :follow
81 get "/blocks", MastodonAPIController, :blocks
83 get "/domain_blocks", MastodonAPIController, :empty_array
84 get "/follow_requests", MastodonAPIController, :empty_array
85 get "/mutes", MastodonAPIController, :empty_array
87 get "/timelines/home", MastodonAPIController, :home_timeline
89 get "/favourites", MastodonAPIController, :favourites
91 post "/statuses", MastodonAPIController, :post_status
92 delete "/statuses/:id", MastodonAPIController, :delete_status
94 post "/statuses/:id/reblog", MastodonAPIController, :reblog_status
95 post "/statuses/:id/favourite", MastodonAPIController, :fav_status
96 post "/statuses/:id/unfavourite", MastodonAPIController, :unfav_status
98 post "/notifications/clear", MastodonAPIController, :clear_notifications
99 post "/notifications/dismiss", MastodonAPIController, :dismiss_notification
100 get "/notifications", MastodonAPIController, :notifications
101 get "/notifications/:id", MastodonAPIController, :get_notification
103 post "/media", MastodonAPIController, :upload
106 scope "/api/v1", Pleroma.Web.MastodonAPI do
108 get "/instance", MastodonAPIController, :masto_instance
109 post "/apps", MastodonAPIController, :create_app
110 get "/custom_emojis", MastodonAPIController, :custom_emojis
112 get "/timelines/public", MastodonAPIController, :public_timeline
113 get "/timelines/tag/:tag", MastodonAPIController, :hashtag_timeline
115 get "/statuses/:id", MastodonAPIController, :get_status
116 get "/statuses/:id/context", MastodonAPIController, :get_context
117 get "/statuses/:id/favourited_by", MastodonAPIController, :favourited_by
118 get "/statuses/:id/reblogged_by", MastodonAPIController, :reblogged_by
120 get "/accounts/:id/statuses", MastodonAPIController, :user_statuses
121 get "/accounts/:id/followers", MastodonAPIController, :followers
122 get "/accounts/:id/following", MastodonAPIController, :following
123 get "/accounts/:id", MastodonAPIController, :user
125 get "/search", MastodonAPIController, :search
128 scope "/api", Pleroma.Web do
131 get "/help/test", TwitterAPI.UtilController, :help_test
132 post "/help/test", TwitterAPI.UtilController, :help_test
133 get "/statusnet/config", TwitterAPI.UtilController, :config
134 get "/statusnet/version", TwitterAPI.UtilController, :version
137 @instance Application.get_env(:pleroma, :instance)
138 @registrations_open Keyword.get(@instance, :registrations_open)
140 scope "/api", Pleroma.Web do
143 get "/statuses/public_timeline", TwitterAPI.Controller, :public_timeline
144 get "/statuses/public_and_external_timeline", TwitterAPI.Controller, :public_and_external_timeline
145 get "/statuses/networkpublic_timeline", TwitterAPI.Controller, :public_and_external_timeline
146 get "/statuses/user_timeline", TwitterAPI.Controller, :user_timeline
147 get "/qvitter/statuses/user_timeline", TwitterAPI.Controller, :user_timeline
148 get "/users/show", TwitterAPI.Controller, :show_user
150 get "/statuses/show/:id", TwitterAPI.Controller, :fetch_status
151 get "/statusnet/conversation/:id", TwitterAPI.Controller, :fetch_conversation
153 if @registrations_open do
154 post "/account/register", TwitterAPI.Controller, :register
157 get "/search", TwitterAPI.Controller, :search
158 get "/statusnet/tags/timeline/:tag", TwitterAPI.Controller, :public_and_external_timeline
161 scope "/api", Pleroma.Web do
162 pipe_through :authenticated_api
164 get "/account/verify_credentials", TwitterAPI.Controller, :verify_credentials
165 post "/account/verify_credentials", TwitterAPI.Controller, :verify_credentials
167 post "/account/update_profile", TwitterAPI.Controller, :update_profile
168 post "/account/update_profile_banner", TwitterAPI.Controller, :update_banner
169 post "/qvitter/update_background_image", TwitterAPI.Controller, :update_background
171 post "/account/most_recent_notification", TwitterAPI.Controller, :update_most_recent_notification
173 get "/statuses/home_timeline", TwitterAPI.Controller, :friends_timeline
174 get "/statuses/friends_timeline", TwitterAPI.Controller, :friends_timeline
175 get "/statuses/mentions", TwitterAPI.Controller, :mentions_timeline
176 get "/statuses/mentions_timeline", TwitterAPI.Controller, :mentions_timeline
178 post "/statuses/update", TwitterAPI.Controller, :status_update
179 post "/statuses/retweet/:id", TwitterAPI.Controller, :retweet
180 post "/statuses/destroy/:id", TwitterAPI.Controller, :delete_post
182 post "/friendships/create", TwitterAPI.Controller, :follow
183 post "/friendships/destroy", TwitterAPI.Controller, :unfollow
184 post "/blocks/create", TwitterAPI.Controller, :block
185 post "/blocks/destroy", TwitterAPI.Controller, :unblock
187 post "/statusnet/media/upload", TwitterAPI.Controller, :upload
188 post "/media/upload", TwitterAPI.Controller, :upload_json
190 post "/favorites/create/:id", TwitterAPI.Controller, :favorite
191 post "/favorites/create", TwitterAPI.Controller, :favorite
192 post "/favorites/destroy/:id", TwitterAPI.Controller, :unfavorite
194 post "/qvitter/update_avatar", TwitterAPI.Controller, :update_avatar
196 get "/statuses/followers", TwitterAPI.Controller, :followers
197 get "/statuses/friends", TwitterAPI.Controller, :friends
198 get "/friends/ids", TwitterAPI.Controller, :friends_ids
199 get "/friendships/no_retweets/ids", TwitterAPI.Controller, :empty_array
201 get "/mutes/users/ids", TwitterAPI.Controller, :empty_array
203 get "/externalprofile/show", TwitterAPI.Controller, :external_profile
207 plug :accepts, ["xml", "atom", "html"]
210 scope "/", Pleroma.Web do
211 pipe_through :ostatus
213 get "/objects/:uuid", OStatus.OStatusController, :object
214 get "/activities/:uuid", OStatus.OStatusController, :activity
215 get "/notice/:id", OStatus.OStatusController, :notice
217 get "/users/:nickname/feed", OStatus.OStatusController, :feed
218 get "/users/:nickname", OStatus.OStatusController, :feed_redirect
219 post "/users/:nickname/salmon", OStatus.OStatusController, :salmon_incoming
220 post "/push/hub/:nickname", Websub.WebsubController, :websub_subscription_request
221 get "/push/subscriptions/:id", Websub.WebsubController, :websub_subscription_confirmation
222 post "/push/subscriptions/:id", Websub.WebsubController, :websub_incoming
225 scope "/.well-known", Pleroma.Web do
226 pipe_through :well_known
228 get "/host-meta", WebFinger.WebFingerController, :host_meta
229 get "/webfinger", WebFinger.WebFingerController, :webfinger
232 scope "/", Pleroma.Web.MastodonAPI do
233 pipe_through :mastodon_html
235 get "/web/login", MastodonAPIController, :login
236 post "/web/login", MastodonAPIController, :login_post
237 get "/web/*path", MastodonAPIController, :index
238 delete "/auth/sign_out", MastodonAPIController, :logout
241 scope "/", Fallback do
242 get "/*path", RedirectController, :redirector
246 defmodule Fallback.RedirectController do
247 use Pleroma.Web, :controller
248 def redirector(conn, _params) do
249 if Mix.env != :test do
251 |> put_resp_content_type("text/html")
252 |> send_file(200, "priv/static/index.html")