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 :well_known do
25 plug :accepts, ["xml", "xrd+xml"]
29 plug :accepts, ["json", "xml"]
33 plug :accepts, ["html", "json"]
36 scope "/oauth", Pleroma.Web.OAuth do
37 get "/authorize", OAuthController, :authorize
38 post "/authorize", OAuthController, :create_authorization
39 post "/token", OAuthController, :token_exchange
42 scope "/api/v1", Pleroma.Web.MastodonAPI do
43 pipe_through :authenticated_api
45 get "/accounts/verify_credentials", MastodonAPIController, :verify_credentials
46 get "/accounts/relationships", MastodonAPIController, :relationships
47 post "/accounts/:id/follow", MastodonAPIController, :follow
48 post "/accounts/:id/unfollow", MastodonAPIController, :unfollow
49 post "/accounts/:id/block", MastodonAPIController, :relationship_noop
50 post "/accounts/:id/unblock", MastodonAPIController, :relationship_noop
51 post "/accounts/:id/mute", MastodonAPIController, :relationship_noop
52 post "/accounts/:id/unmute", MastodonAPIController, :relationship_noop
54 get "/blocks", MastodonAPIController, :empty_array
55 get "/domain_blocks", MastodonAPIController, :empty_array
56 get "/follow_requests", MastodonAPIController, :empty_array
57 get "/mutes", MastodonAPIController, :empty_array
59 get "/timelines/home", MastodonAPIController, :home_timeline
61 post "/statuses", MastodonAPIController, :post_status
62 delete "/statuses/:id", MastodonAPIController, :delete_status
64 post "/statuses/:id/reblog", MastodonAPIController, :reblog_status
65 post "/statuses/:id/favourite", MastodonAPIController, :fav_status
66 post "/statuses/:id/unfavourite", MastodonAPIController, :unfav_status
68 get "/notifications", MastodonAPIController, :notifications
70 post "/media", MastodonAPIController, :upload
73 scope "/api/v1", Pleroma.Web.MastodonAPI do
75 get "/instance", MastodonAPIController, :masto_instance
76 post "/apps", MastodonAPIController, :create_app
78 get "/timelines/public", MastodonAPIController, :public_timeline
79 get "/timelines/tag/:tag", MastodonAPIController, :hashtag_timeline
81 get "/statuses/:id", MastodonAPIController, :get_status
82 get "/statuses/:id/context", MastodonAPIController, :get_context
83 get "/statuses/:id/favourited_by", MastodonAPIController, :favourited_by
84 get "/statuses/:id/reblogged_by", MastodonAPIController, :reblogged_by
86 get "/accounts/:id/statuses", MastodonAPIController, :user_statuses
87 get "/accounts/:id/followers", MastodonAPIController, :followers
88 get "/accounts/:id/following", MastodonAPIController, :following
89 get "/accounts/:id", MastodonAPIController, :user
91 get "/search", MastodonAPIController, :search
94 scope "/api", Pleroma.Web do
97 get "/help/test", TwitterAPI.UtilController, :help_test
98 post "/help/test", TwitterAPI.UtilController, :help_test
99 get "/statusnet/config", TwitterAPI.UtilController, :config
100 get "/statusnet/version", TwitterAPI.UtilController, :version
103 @instance Application.get_env(:pleroma, :instance)
104 @registrations_open Keyword.get(@instance, :registrations_open)
106 scope "/api", Pleroma.Web do
109 get "/statuses/public_timeline", TwitterAPI.Controller, :public_timeline
110 get "/statuses/public_and_external_timeline", TwitterAPI.Controller, :public_and_external_timeline
111 get "/statuses/networkpublic_timeline", TwitterAPI.Controller, :public_and_external_timeline
112 get "/statuses/user_timeline", TwitterAPI.Controller, :user_timeline
113 get "/qvitter/statuses/user_timeline", TwitterAPI.Controller, :user_timeline
115 get "/statuses/show/:id", TwitterAPI.Controller, :fetch_status
116 get "/statusnet/conversation/:id", TwitterAPI.Controller, :fetch_conversation
118 if @registrations_open do
119 post "/account/register", TwitterAPI.Controller, :register
122 get "/externalprofile/show", TwitterAPI.Controller, :external_profile
125 scope "/api", Pleroma.Web do
126 pipe_through :authenticated_api
128 get "/account/verify_credentials", TwitterAPI.Controller, :verify_credentials
129 post "/account/verify_credentials", TwitterAPI.Controller, :verify_credentials
131 post "/account/update_profile", TwitterAPI.Controller, :update_profile
132 post "/account/update_profile_banner", TwitterAPI.Controller, :update_banner
133 post "/qvitter/update_background_image", TwitterAPI.Controller, :update_background
135 post "/account/most_recent_notification", TwitterAPI.Controller, :update_most_recent_notification
137 get "/statuses/home_timeline", TwitterAPI.Controller, :friends_timeline
138 get "/statuses/friends_timeline", TwitterAPI.Controller, :friends_timeline
139 get "/statuses/mentions", TwitterAPI.Controller, :mentions_timeline
140 get "/statuses/mentions_timeline", TwitterAPI.Controller, :mentions_timeline
142 post "/statuses/update", TwitterAPI.Controller, :status_update
143 post "/statuses/retweet/:id", TwitterAPI.Controller, :retweet
144 post "/statuses/destroy/:id", TwitterAPI.Controller, :delete_post
146 post "/friendships/create", TwitterAPI.Controller, :follow
147 post "/friendships/destroy", TwitterAPI.Controller, :unfollow
149 post "/statusnet/media/upload", TwitterAPI.Controller, :upload
150 post "/media/upload", TwitterAPI.Controller, :upload_json
152 post "/favorites/create/:id", TwitterAPI.Controller, :favorite
153 post "/favorites/create", TwitterAPI.Controller, :favorite
154 post "/favorites/destroy/:id", TwitterAPI.Controller, :unfavorite
156 post "/qvitter/update_avatar", TwitterAPI.Controller, :update_avatar
158 get "/statuses/followers", TwitterAPI.Controller, :followers
159 get "/statuses/friends", TwitterAPI.Controller, :friends
163 plug :accepts, ["xml", "atom", "html"]
166 scope "/", Pleroma.Web do
167 pipe_through :ostatus
169 get "/objects/:uuid", OStatus.OStatusController, :object
170 get "/activities/:uuid", OStatus.OStatusController, :activity
172 get "/users/:nickname/feed", OStatus.OStatusController, :feed
173 get "/users/:nickname", OStatus.OStatusController, :feed_redirect
174 post "/users/:nickname/salmon", OStatus.OStatusController, :salmon_incoming
175 post "/push/hub/:nickname", Websub.WebsubController, :websub_subscription_request
176 get "/push/subscriptions/:id", Websub.WebsubController, :websub_subscription_confirmation
177 post "/push/subscriptions/:id", Websub.WebsubController, :websub_incoming
180 scope "/.well-known", Pleroma.Web do
181 pipe_through :well_known
183 get "/host-meta", WebFinger.WebFingerController, :host_meta
184 get "/webfinger", WebFinger.WebFingerController, :webfinger
187 scope "/", Fallback do
188 get "/*path", RedirectController, :redirector
192 defmodule Fallback.RedirectController do
193 use Pleroma.Web, :controller
194 def redirector(conn, _params) do
195 if Mix.env != :test do
197 |> put_resp_content_type("text/html")
198 |> send_file(200, "priv/static/index.html")