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 :pleroma_html do
32 plug :accepts, ["html"]
34 plug Pleroma.Plugs.OAuthPlug
35 plug Pleroma.Plugs.AuthenticationPlug, %{fetcher: &Router.user_fetcher/1, optional: true}
38 pipeline :well_known do
39 plug :accepts, ["xml", "xrd+xml"]
43 plug :accepts, ["json", "xml"]
47 plug :accepts, ["html", "json"]
50 pipeline :pleroma_api do
51 plug :accepts, ["html", "json"]
54 scope "/api/pleroma", Pleroma.Web.TwitterAPI do
55 pipe_through :pleroma_api
56 get "/password_reset/:token", UtilController, :show_password_reset
57 post "/password_reset", UtilController, :password_reset
58 get "/emoji", UtilController, :emoji
61 scope "/", Pleroma.Web.TwitterAPI do
62 pipe_through :pleroma_html
63 get "/ostatus_subscribe", UtilController, :remote_follow
64 post "/ostatus_subscribe", UtilController, :do_remote_follow
67 scope "/api/pleroma", Pleroma.Web.TwitterAPI do
68 pipe_through :authenticated_api
69 post "/follow_import", UtilController, :follow_import
72 scope "/oauth", Pleroma.Web.OAuth do
73 get "/authorize", OAuthController, :authorize
74 post "/authorize", OAuthController, :create_authorization
75 post "/token", OAuthController, :token_exchange
78 scope "/api/v1", Pleroma.Web.MastodonAPI do
79 pipe_through :authenticated_api
81 patch "/accounts/update_credentials", MastodonAPIController, :update_credentials
82 get "/accounts/verify_credentials", MastodonAPIController, :verify_credentials
83 get "/accounts/relationships", MastodonAPIController, :relationships
84 get "/accounts/search", MastodonAPIController, :account_search
85 post "/accounts/:id/follow", MastodonAPIController, :follow
86 post "/accounts/:id/unfollow", MastodonAPIController, :unfollow
87 post "/accounts/:id/block", MastodonAPIController, :block
88 post "/accounts/:id/unblock", MastodonAPIController, :unblock
89 post "/accounts/:id/mute", MastodonAPIController, :relationship_noop
90 post "/accounts/:id/unmute", MastodonAPIController, :relationship_noop
92 post "/follows", MastodonAPIController, :follow
94 get "/blocks", MastodonAPIController, :blocks
96 get "/domain_blocks", MastodonAPIController, :empty_array
97 get "/follow_requests", MastodonAPIController, :empty_array
98 get "/mutes", MastodonAPIController, :empty_array
100 get "/timelines/home", MastodonAPIController, :home_timeline
102 get "/favourites", MastodonAPIController, :favourites
104 post "/statuses", MastodonAPIController, :post_status
105 delete "/statuses/:id", MastodonAPIController, :delete_status
107 post "/statuses/:id/reblog", MastodonAPIController, :reblog_status
108 post "/statuses/:id/favourite", MastodonAPIController, :fav_status
109 post "/statuses/:id/unfavourite", MastodonAPIController, :unfav_status
111 post "/notifications/clear", MastodonAPIController, :clear_notifications
112 post "/notifications/dismiss", MastodonAPIController, :dismiss_notification
113 get "/notifications", MastodonAPIController, :notifications
114 get "/notifications/:id", MastodonAPIController, :get_notification
116 post "/media", MastodonAPIController, :upload
119 scope "/api/v1", Pleroma.Web.MastodonAPI do
121 get "/instance", MastodonAPIController, :masto_instance
122 get "/instance/peers", MastodonAPIController, :peers
123 post "/apps", MastodonAPIController, :create_app
124 get "/custom_emojis", MastodonAPIController, :custom_emojis
126 get "/timelines/public", MastodonAPIController, :public_timeline
127 get "/timelines/tag/:tag", MastodonAPIController, :hashtag_timeline
129 get "/statuses/:id", MastodonAPIController, :get_status
130 get "/statuses/:id/context", MastodonAPIController, :get_context
131 get "/statuses/:id/favourited_by", MastodonAPIController, :favourited_by
132 get "/statuses/:id/reblogged_by", MastodonAPIController, :reblogged_by
134 get "/accounts/:id/statuses", MastodonAPIController, :user_statuses
135 get "/accounts/:id/followers", MastodonAPIController, :followers
136 get "/accounts/:id/following", MastodonAPIController, :following
137 get "/accounts/:id", MastodonAPIController, :user
139 get "/search", MastodonAPIController, :search
142 scope "/api", Pleroma.Web do
145 get "/help/test", TwitterAPI.UtilController, :help_test
146 post "/help/test", TwitterAPI.UtilController, :help_test
147 get "/statusnet/config", TwitterAPI.UtilController, :config
148 get "/statusnet/version", TwitterAPI.UtilController, :version
151 @instance Application.get_env(:pleroma, :instance)
152 @registrations_open Keyword.get(@instance, :registrations_open)
154 scope "/api", Pleroma.Web do
157 get "/statuses/public_timeline", TwitterAPI.Controller, :public_timeline
158 get "/statuses/public_and_external_timeline", TwitterAPI.Controller, :public_and_external_timeline
159 get "/statuses/networkpublic_timeline", TwitterAPI.Controller, :public_and_external_timeline
160 get "/statuses/user_timeline", TwitterAPI.Controller, :user_timeline
161 get "/qvitter/statuses/user_timeline", TwitterAPI.Controller, :user_timeline
162 get "/users/show", TwitterAPI.Controller, :show_user
164 get "/statuses/followers", TwitterAPI.Controller, :followers
165 get "/statuses/friends", TwitterAPI.Controller, :friends
166 get "/statuses/show/:id", TwitterAPI.Controller, :fetch_status
167 get "/statusnet/conversation/:id", TwitterAPI.Controller, :fetch_conversation
169 if @registrations_open do
170 post "/account/register", TwitterAPI.Controller, :register
173 get "/search", TwitterAPI.Controller, :search
174 get "/statusnet/tags/timeline/:tag", TwitterAPI.Controller, :public_and_external_timeline
177 scope "/api", Pleroma.Web do
178 pipe_through :authenticated_api
180 get "/account/verify_credentials", TwitterAPI.Controller, :verify_credentials
181 post "/account/verify_credentials", TwitterAPI.Controller, :verify_credentials
183 post "/account/update_profile", TwitterAPI.Controller, :update_profile
184 post "/account/update_profile_banner", TwitterAPI.Controller, :update_banner
185 post "/qvitter/update_background_image", TwitterAPI.Controller, :update_background
187 post "/account/most_recent_notification", TwitterAPI.Controller, :update_most_recent_notification
189 get "/statuses/home_timeline", TwitterAPI.Controller, :friends_timeline
190 get "/statuses/friends_timeline", TwitterAPI.Controller, :friends_timeline
191 get "/statuses/mentions", TwitterAPI.Controller, :mentions_timeline
192 get "/statuses/mentions_timeline", TwitterAPI.Controller, :mentions_timeline
194 post "/statuses/update", TwitterAPI.Controller, :status_update
195 post "/statuses/retweet/:id", TwitterAPI.Controller, :retweet
196 post "/statuses/destroy/:id", TwitterAPI.Controller, :delete_post
198 post "/friendships/create", TwitterAPI.Controller, :follow
199 post "/friendships/destroy", TwitterAPI.Controller, :unfollow
200 post "/blocks/create", TwitterAPI.Controller, :block
201 post "/blocks/destroy", TwitterAPI.Controller, :unblock
203 post "/statusnet/media/upload", TwitterAPI.Controller, :upload
204 post "/media/upload", TwitterAPI.Controller, :upload_json
206 post "/favorites/create/:id", TwitterAPI.Controller, :favorite
207 post "/favorites/create", TwitterAPI.Controller, :favorite
208 post "/favorites/destroy/:id", TwitterAPI.Controller, :unfavorite
210 post "/qvitter/update_avatar", TwitterAPI.Controller, :update_avatar
212 get "/friends/ids", TwitterAPI.Controller, :friends_ids
213 get "/friendships/no_retweets/ids", TwitterAPI.Controller, :empty_array
215 get "/mutes/users/ids", TwitterAPI.Controller, :empty_array
217 get "/externalprofile/show", TwitterAPI.Controller, :external_profile
221 plug :accepts, ["xml", "atom", "html"]
224 scope "/", Pleroma.Web do
225 pipe_through :ostatus
227 get "/objects/:uuid", OStatus.OStatusController, :object
228 get "/activities/:uuid", OStatus.OStatusController, :activity
229 get "/notice/:id", OStatus.OStatusController, :notice
231 get "/users/:nickname/feed", OStatus.OStatusController, :feed
232 get "/users/:nickname", OStatus.OStatusController, :feed_redirect
233 post "/users/:nickname/salmon", OStatus.OStatusController, :salmon_incoming
234 post "/push/hub/:nickname", Websub.WebsubController, :websub_subscription_request
235 get "/push/subscriptions/:id", Websub.WebsubController, :websub_subscription_confirmation
236 post "/push/subscriptions/:id", Websub.WebsubController, :websub_incoming
239 scope "/.well-known", Pleroma.Web do
240 pipe_through :well_known
242 get "/host-meta", WebFinger.WebFingerController, :host_meta
243 get "/webfinger", WebFinger.WebFingerController, :webfinger
246 scope "/", Pleroma.Web.MastodonAPI do
247 pipe_through :mastodon_html
249 get "/web/login", MastodonAPIController, :login
250 post "/web/login", MastodonAPIController, :login_post
251 get "/web/*path", MastodonAPIController, :index
252 delete "/auth/sign_out", MastodonAPIController, :logout
255 pipeline :remote_media do
256 plug :accepts, ["html"]
258 scope "/proxy/", Pleroma.Web.MediaProxy do
259 pipe_through :remote_media
260 get "/:sig/:url", MediaProxyController, :remote
263 scope "/", Fallback do
264 get "/*path", RedirectController, :redirector
268 defmodule Fallback.RedirectController do
269 use Pleroma.Web, :controller
270 def redirector(conn, _params) do
271 if Mix.env != :test do
273 |> put_resp_content_type("text/html")
274 |> send_file(200, "priv/static/index.html")