Merge branch 'stats-daemon' into 'develop'
[akkoma] / lib / pleroma / web / router.ex
1 defmodule Pleroma.Web.Router do
2 use Pleroma.Web, :router
3
4 alias Pleroma.{Repo, User, Web.Router}
5
6 def user_fetcher(username) do
7 {:ok, Repo.get_by(User, %{nickname: username})}
8 end
9
10 pipeline :api do
11 plug :accepts, ["json"]
12 plug :fetch_session
13 plug Pleroma.Plugs.OAuthPlug
14 plug Pleroma.Plugs.AuthenticationPlug, %{fetcher: &Router.user_fetcher/1, optional: true}
15 end
16
17 pipeline :authenticated_api do
18 plug :accepts, ["json"]
19 plug :fetch_session
20 plug Pleroma.Plugs.OAuthPlug
21 plug Pleroma.Plugs.AuthenticationPlug, %{fetcher: &Router.user_fetcher/1}
22 end
23
24 pipeline :mastodon_html do
25 plug :accepts, ["html"]
26 plug :fetch_session
27 plug Pleroma.Plugs.OAuthPlug
28 plug Pleroma.Plugs.AuthenticationPlug, %{fetcher: &Router.user_fetcher/1, optional: true}
29 end
30
31 pipeline :well_known do
32 plug :accepts, ["xml", "xrd+xml"]
33 end
34
35 pipeline :config do
36 plug :accepts, ["json", "xml"]
37 end
38
39 pipeline :oauth do
40 plug :accepts, ["html", "json"]
41 end
42
43 pipeline :pleroma_api do
44 plug :accepts, ["html", "json"]
45 end
46
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
52 end
53
54 scope "/api/pleroma", Pleroma.Web.TwitterAPI do
55 pipe_through :authenticated_api
56 post "/follow_import", UtilController, :follow_import
57 end
58
59 scope "/oauth", Pleroma.Web.OAuth do
60 get "/authorize", OAuthController, :authorize
61 post "/authorize", OAuthController, :create_authorization
62 post "/token", OAuthController, :token_exchange
63 end
64
65 scope "/api/v1", Pleroma.Web.MastodonAPI do
66 pipe_through :authenticated_api
67
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
78
79 post "/follows", MastodonAPIController, :follow
80
81 get "/blocks", MastodonAPIController, :blocks
82
83 get "/domain_blocks", MastodonAPIController, :empty_array
84 get "/follow_requests", MastodonAPIController, :empty_array
85 get "/mutes", MastodonAPIController, :empty_array
86
87 get "/timelines/home", MastodonAPIController, :home_timeline
88
89 get "/favourites", MastodonAPIController, :favourites
90
91 post "/statuses", MastodonAPIController, :post_status
92 delete "/statuses/:id", MastodonAPIController, :delete_status
93
94 post "/statuses/:id/reblog", MastodonAPIController, :reblog_status
95 post "/statuses/:id/favourite", MastodonAPIController, :fav_status
96 post "/statuses/:id/unfavourite", MastodonAPIController, :unfav_status
97
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
102
103 post "/media", MastodonAPIController, :upload
104 end
105
106 scope "/api/v1", Pleroma.Web.MastodonAPI do
107 pipe_through :api
108 get "/instance", MastodonAPIController, :masto_instance
109 get "/instance/peers", MastodonAPIController, :peers
110 post "/apps", MastodonAPIController, :create_app
111 get "/custom_emojis", MastodonAPIController, :custom_emojis
112
113 get "/timelines/public", MastodonAPIController, :public_timeline
114 get "/timelines/tag/:tag", MastodonAPIController, :hashtag_timeline
115
116 get "/statuses/:id", MastodonAPIController, :get_status
117 get "/statuses/:id/context", MastodonAPIController, :get_context
118 get "/statuses/:id/favourited_by", MastodonAPIController, :favourited_by
119 get "/statuses/:id/reblogged_by", MastodonAPIController, :reblogged_by
120
121 get "/accounts/:id/statuses", MastodonAPIController, :user_statuses
122 get "/accounts/:id/followers", MastodonAPIController, :followers
123 get "/accounts/:id/following", MastodonAPIController, :following
124 get "/accounts/:id", MastodonAPIController, :user
125
126 get "/search", MastodonAPIController, :search
127 end
128
129 scope "/api", Pleroma.Web do
130 pipe_through :config
131
132 get "/help/test", TwitterAPI.UtilController, :help_test
133 post "/help/test", TwitterAPI.UtilController, :help_test
134 get "/statusnet/config", TwitterAPI.UtilController, :config
135 get "/statusnet/version", TwitterAPI.UtilController, :version
136 end
137
138 @instance Application.get_env(:pleroma, :instance)
139 @registrations_open Keyword.get(@instance, :registrations_open)
140
141 scope "/api", Pleroma.Web do
142 pipe_through :api
143
144 get "/statuses/public_timeline", TwitterAPI.Controller, :public_timeline
145 get "/statuses/public_and_external_timeline", TwitterAPI.Controller, :public_and_external_timeline
146 get "/statuses/networkpublic_timeline", TwitterAPI.Controller, :public_and_external_timeline
147 get "/statuses/user_timeline", TwitterAPI.Controller, :user_timeline
148 get "/qvitter/statuses/user_timeline", TwitterAPI.Controller, :user_timeline
149 get "/users/show", TwitterAPI.Controller, :show_user
150
151 get "/statuses/followers", TwitterAPI.Controller, :followers
152 get "/statuses/friends", TwitterAPI.Controller, :friends
153 get "/statuses/show/:id", TwitterAPI.Controller, :fetch_status
154 get "/statusnet/conversation/:id", TwitterAPI.Controller, :fetch_conversation
155
156 if @registrations_open do
157 post "/account/register", TwitterAPI.Controller, :register
158 end
159
160 get "/search", TwitterAPI.Controller, :search
161 get "/statusnet/tags/timeline/:tag", TwitterAPI.Controller, :public_and_external_timeline
162 end
163
164 scope "/api", Pleroma.Web do
165 pipe_through :authenticated_api
166
167 get "/account/verify_credentials", TwitterAPI.Controller, :verify_credentials
168 post "/account/verify_credentials", TwitterAPI.Controller, :verify_credentials
169
170 post "/account/update_profile", TwitterAPI.Controller, :update_profile
171 post "/account/update_profile_banner", TwitterAPI.Controller, :update_banner
172 post "/qvitter/update_background_image", TwitterAPI.Controller, :update_background
173
174 post "/account/most_recent_notification", TwitterAPI.Controller, :update_most_recent_notification
175
176 get "/statuses/home_timeline", TwitterAPI.Controller, :friends_timeline
177 get "/statuses/friends_timeline", TwitterAPI.Controller, :friends_timeline
178 get "/statuses/mentions", TwitterAPI.Controller, :mentions_timeline
179 get "/statuses/mentions_timeline", TwitterAPI.Controller, :mentions_timeline
180
181 post "/statuses/update", TwitterAPI.Controller, :status_update
182 post "/statuses/retweet/:id", TwitterAPI.Controller, :retweet
183 post "/statuses/destroy/:id", TwitterAPI.Controller, :delete_post
184
185 post "/friendships/create", TwitterAPI.Controller, :follow
186 post "/friendships/destroy", TwitterAPI.Controller, :unfollow
187 post "/blocks/create", TwitterAPI.Controller, :block
188 post "/blocks/destroy", TwitterAPI.Controller, :unblock
189
190 post "/statusnet/media/upload", TwitterAPI.Controller, :upload
191 post "/media/upload", TwitterAPI.Controller, :upload_json
192
193 post "/favorites/create/:id", TwitterAPI.Controller, :favorite
194 post "/favorites/create", TwitterAPI.Controller, :favorite
195 post "/favorites/destroy/:id", TwitterAPI.Controller, :unfavorite
196
197 post "/qvitter/update_avatar", TwitterAPI.Controller, :update_avatar
198
199 get "/friends/ids", TwitterAPI.Controller, :friends_ids
200 get "/friendships/no_retweets/ids", TwitterAPI.Controller, :empty_array
201
202 get "/mutes/users/ids", TwitterAPI.Controller, :empty_array
203
204 get "/externalprofile/show", TwitterAPI.Controller, :external_profile
205 end
206
207 pipeline :ostatus do
208 plug :accepts, ["xml", "atom", "html"]
209 end
210
211 scope "/", Pleroma.Web do
212 pipe_through :ostatus
213
214 get "/objects/:uuid", OStatus.OStatusController, :object
215 get "/activities/:uuid", OStatus.OStatusController, :activity
216 get "/notice/:id", OStatus.OStatusController, :notice
217
218 get "/users/:nickname/feed", OStatus.OStatusController, :feed
219 get "/users/:nickname", OStatus.OStatusController, :feed_redirect
220 post "/users/:nickname/salmon", OStatus.OStatusController, :salmon_incoming
221 post "/push/hub/:nickname", Websub.WebsubController, :websub_subscription_request
222 get "/push/subscriptions/:id", Websub.WebsubController, :websub_subscription_confirmation
223 post "/push/subscriptions/:id", Websub.WebsubController, :websub_incoming
224 end
225
226 scope "/.well-known", Pleroma.Web do
227 pipe_through :well_known
228
229 get "/host-meta", WebFinger.WebFingerController, :host_meta
230 get "/webfinger", WebFinger.WebFingerController, :webfinger
231 end
232
233 scope "/", Pleroma.Web.MastodonAPI do
234 pipe_through :mastodon_html
235
236 get "/web/login", MastodonAPIController, :login
237 post "/web/login", MastodonAPIController, :login_post
238 get "/web/*path", MastodonAPIController, :index
239 delete "/auth/sign_out", MastodonAPIController, :logout
240 end
241
242 pipeline :remote_media do
243 plug :accepts, ["html"]
244 end
245 scope "/proxy/", Pleroma.Web.MediaProxy do
246 pipe_through :remote_media
247 get "/:sig/:url", MediaProxyController, :remote
248 end
249
250 scope "/", Fallback do
251 get "/*path", RedirectController, :redirector
252 end
253 end
254
255 defmodule Fallback.RedirectController do
256 use Pleroma.Web, :controller
257 def redirector(conn, _params) do
258 if Mix.env != :test do
259 conn
260 |> put_resp_content_type("text/html")
261 |> send_file(200, "priv/static/index.html")
262 end
263 end
264 end