Add Plugs to router.
[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 @instance Application.get_env(:pleroma, :instance)
7 @federating Keyword.get(@instance, :federating)
8 @allow_relay Keyword.get(@instance, :allow_relay)
9 @public Keyword.get(@instance, :public)
10 @registrations_open Keyword.get(@instance, :registrations_open)
11
12 pipeline :api do
13 plug(:accepts, ["json"])
14 plug(:fetch_session)
15 plug(Pleroma.Plugs.OAuthPlug)
16 plug(Pleroma.Plugs.BasicAuthDecoderPlug)
17 plug(Pleroma.Plugs.UserFetcherPlug)
18 plug(Pleroma.Plugs.SessionAuthenticationPlug)
19 plug(Pleroma.Plugs.AuthenticationPlug)
20 plug(Pleroma.Plugs.UserEnabledPlug)
21 plug(Pleroma.Plugs.SetUserSessionIdPlug)
22 plug(Pleroma.Plugs.EnsureUserKeyPlug)
23 end
24
25 pipeline :authenticated_api do
26 plug(:accepts, ["json"])
27 plug(:fetch_session)
28 plug(Pleroma.Plugs.OAuthPlug)
29 plug(Pleroma.Plugs.BasicAuthDecoderPlug)
30 plug(Pleroma.Plugs.UserFetcherPlug)
31 plug(Pleroma.Plugs.SessionAuthenticationPlug)
32 plug(Pleroma.Plugs.AuthenticationPlug)
33 plug(Pleroma.Plugs.UserEnabledPlug)
34 plug(Pleroma.Plugs.SetUserSessionIdPlug)
35 plug(Pleroma.Plugs.EnsureAuthenticatedPlug)
36 end
37
38 pipeline :mastodon_html do
39 plug(:accepts, ["html"])
40 plug(:fetch_session)
41 plug(Pleroma.Plugs.OAuthPlug)
42 plug(Pleroma.Plugs.BasicAuthDecoderPlug)
43 plug(Pleroma.Plugs.UserFetcherPlug)
44 plug(Pleroma.Plugs.SessionAuthenticationPlug)
45 plug(Pleroma.Plugs.AuthenticationPlug)
46 plug(Pleroma.Plugs.UserEnabledPlug)
47 plug(Pleroma.Plugs.SetUserSessionIdPlug)
48 plug(Pleroma.Plugs.EnsureUserKeyPlug)
49 end
50
51 pipeline :pleroma_html do
52 plug(:accepts, ["html"])
53 plug(:fetch_session)
54 plug(Pleroma.Plugs.OAuthPlug)
55 plug(Pleroma.Plugs.BasicAuthDecoderPlug)
56 plug(Pleroma.Plugs.UserFetcherPlug)
57 plug(Pleroma.Plugs.SessionAuthenticationPlug)
58 plug(Pleroma.Plugs.AuthenticationPlug)
59 plug(Pleroma.Plugs.EnsureUserKeyPlug)
60 end
61
62 pipeline :well_known do
63 plug(:accepts, ["json", "jrd+json", "xml", "xrd+xml"])
64 end
65
66 pipeline :config do
67 plug(:accepts, ["json", "xml"])
68 end
69
70 pipeline :oauth do
71 plug(:accepts, ["html", "json"])
72 end
73
74 pipeline :pleroma_api do
75 plug(:accepts, ["html", "json"])
76 end
77
78 scope "/api/pleroma", Pleroma.Web.TwitterAPI do
79 pipe_through(:pleroma_api)
80 get("/password_reset/:token", UtilController, :show_password_reset)
81 post("/password_reset", UtilController, :password_reset)
82 get("/emoji", UtilController, :emoji)
83 end
84
85 scope "/", Pleroma.Web.TwitterAPI do
86 pipe_through(:pleroma_html)
87 get("/ostatus_subscribe", UtilController, :remote_follow)
88 post("/ostatus_subscribe", UtilController, :do_remote_follow)
89 post("/main/ostatus", UtilController, :remote_subscribe)
90 end
91
92 scope "/api/pleroma", Pleroma.Web.TwitterAPI do
93 pipe_through(:authenticated_api)
94 post("/follow_import", UtilController, :follow_import)
95 post("/change_password", UtilController, :change_password)
96 post("/delete_account", UtilController, :delete_account)
97 end
98
99 scope "/oauth", Pleroma.Web.OAuth do
100 get("/authorize", OAuthController, :authorize)
101 post("/authorize", OAuthController, :create_authorization)
102 post("/token", OAuthController, :token_exchange)
103 end
104
105 scope "/api/v1", Pleroma.Web.MastodonAPI do
106 pipe_through(:authenticated_api)
107
108 patch("/accounts/update_credentials", MastodonAPIController, :update_credentials)
109 get("/accounts/verify_credentials", MastodonAPIController, :verify_credentials)
110 get("/accounts/relationships", MastodonAPIController, :relationships)
111 get("/accounts/search", MastodonAPIController, :account_search)
112 post("/accounts/:id/follow", MastodonAPIController, :follow)
113 post("/accounts/:id/unfollow", MastodonAPIController, :unfollow)
114 post("/accounts/:id/block", MastodonAPIController, :block)
115 post("/accounts/:id/unblock", MastodonAPIController, :unblock)
116 post("/accounts/:id/mute", MastodonAPIController, :relationship_noop)
117 post("/accounts/:id/unmute", MastodonAPIController, :relationship_noop)
118
119 get("/follow_requests", MastodonAPIController, :follow_requests)
120 post("/follow_requests/:id/authorize", MastodonAPIController, :authorize_follow_request)
121 post("/follow_requests/:id/reject", MastodonAPIController, :reject_follow_request)
122
123 post("/follows", MastodonAPIController, :follow)
124
125 get("/blocks", MastodonAPIController, :blocks)
126
127 get("/mutes", MastodonAPIController, :empty_array)
128
129 get("/timelines/home", MastodonAPIController, :home_timeline)
130
131 get("/timelines/direct", MastodonAPIController, :dm_timeline)
132
133 get("/favourites", MastodonAPIController, :favourites)
134
135 post("/statuses", MastodonAPIController, :post_status)
136 delete("/statuses/:id", MastodonAPIController, :delete_status)
137
138 post("/statuses/:id/reblog", MastodonAPIController, :reblog_status)
139 post("/statuses/:id/unreblog", MastodonAPIController, :unreblog_status)
140 post("/statuses/:id/favourite", MastodonAPIController, :fav_status)
141 post("/statuses/:id/unfavourite", MastodonAPIController, :unfav_status)
142
143 post("/notifications/clear", MastodonAPIController, :clear_notifications)
144 post("/notifications/dismiss", MastodonAPIController, :dismiss_notification)
145 get("/notifications", MastodonAPIController, :notifications)
146 get("/notifications/:id", MastodonAPIController, :get_notification)
147
148 post("/media", MastodonAPIController, :upload)
149 put("/media/:id", MastodonAPIController, :update_media)
150
151 get("/lists", MastodonAPIController, :get_lists)
152 get("/lists/:id", MastodonAPIController, :get_list)
153 delete("/lists/:id", MastodonAPIController, :delete_list)
154 post("/lists", MastodonAPIController, :create_list)
155 put("/lists/:id", MastodonAPIController, :rename_list)
156 get("/lists/:id/accounts", MastodonAPIController, :list_accounts)
157 post("/lists/:id/accounts", MastodonAPIController, :add_to_list)
158 delete("/lists/:id/accounts", MastodonAPIController, :remove_from_list)
159
160 get("/domain_blocks", MastodonAPIController, :domain_blocks)
161 post("/domain_blocks", MastodonAPIController, :block_domain)
162 delete("/domain_blocks", MastodonAPIController, :unblock_domain)
163
164 get("/filters", MastodonAPIController, :get_filters)
165 post("/filters", MastodonAPIController, :create_filter)
166 get("/filters/:id", MastodonAPIController, :get_filter)
167 put("/filters/:id", MastodonAPIController, :update_filter)
168 delete("/filters/:id", MastodonAPIController, :delete_filter)
169
170 get("/suggestions", MastodonAPIController, :suggestions)
171 end
172
173 scope "/api/web", Pleroma.Web.MastodonAPI do
174 pipe_through(:authenticated_api)
175
176 put("/settings", MastodonAPIController, :put_settings)
177 end
178
179 scope "/api/v1", Pleroma.Web.MastodonAPI do
180 pipe_through(:api)
181 get("/instance", MastodonAPIController, :masto_instance)
182 get("/instance/peers", MastodonAPIController, :peers)
183 post("/apps", MastodonAPIController, :create_app)
184 get("/custom_emojis", MastodonAPIController, :custom_emojis)
185
186 get("/timelines/public", MastodonAPIController, :public_timeline)
187 get("/timelines/tag/:tag", MastodonAPIController, :hashtag_timeline)
188 get("/timelines/list/:list_id", MastodonAPIController, :list_timeline)
189
190 get("/statuses/:id", MastodonAPIController, :get_status)
191 get("/statuses/:id/context", MastodonAPIController, :get_context)
192 get("/statuses/:id/card", MastodonAPIController, :empty_object)
193 get("/statuses/:id/favourited_by", MastodonAPIController, :favourited_by)
194 get("/statuses/:id/reblogged_by", MastodonAPIController, :reblogged_by)
195
196 get("/accounts/:id/statuses", MastodonAPIController, :user_statuses)
197 get("/accounts/:id/followers", MastodonAPIController, :followers)
198 get("/accounts/:id/following", MastodonAPIController, :following)
199 get("/accounts/:id", MastodonAPIController, :user)
200
201 get("/trends", MastodonAPIController, :empty_array)
202
203 get("/search", MastodonAPIController, :search)
204 end
205
206 scope "/api/v2", Pleroma.Web.MastodonAPI do
207 pipe_through(:api)
208 get("/search", MastodonAPIController, :search2)
209 end
210
211 scope "/api", Pleroma.Web do
212 pipe_through(:config)
213
214 get("/help/test", TwitterAPI.UtilController, :help_test)
215 post("/help/test", TwitterAPI.UtilController, :help_test)
216 get("/statusnet/config", TwitterAPI.UtilController, :config)
217 get("/statusnet/version", TwitterAPI.UtilController, :version)
218 end
219
220 scope "/api", Pleroma.Web do
221 pipe_through(:api)
222
223 get("/statuses/user_timeline", TwitterAPI.Controller, :user_timeline)
224 get("/qvitter/statuses/user_timeline", TwitterAPI.Controller, :user_timeline)
225 get("/users/show", TwitterAPI.Controller, :show_user)
226
227 get("/statuses/followers", TwitterAPI.Controller, :followers)
228 get("/statuses/friends", TwitterAPI.Controller, :friends)
229 get("/statuses/show/:id", TwitterAPI.Controller, :fetch_status)
230 get("/statusnet/conversation/:id", TwitterAPI.Controller, :fetch_conversation)
231
232 post("/account/register", TwitterAPI.Controller, :register)
233
234 get("/search", TwitterAPI.Controller, :search)
235 get("/statusnet/tags/timeline/:tag", TwitterAPI.Controller, :public_and_external_timeline)
236 end
237
238 scope "/api", Pleroma.Web do
239 if @public do
240 pipe_through(:api)
241 else
242 pipe_through(:authenticated_api)
243 end
244
245 get("/statuses/public_timeline", TwitterAPI.Controller, :public_timeline)
246
247 get(
248 "/statuses/public_and_external_timeline",
249 TwitterAPI.Controller,
250 :public_and_external_timeline
251 )
252
253 get("/statuses/networkpublic_timeline", TwitterAPI.Controller, :public_and_external_timeline)
254 end
255
256 scope "/api", Pleroma.Web do
257 pipe_through(:authenticated_api)
258
259 get("/account/verify_credentials", TwitterAPI.Controller, :verify_credentials)
260 post("/account/verify_credentials", TwitterAPI.Controller, :verify_credentials)
261
262 post("/account/update_profile", TwitterAPI.Controller, :update_profile)
263 post("/account/update_profile_banner", TwitterAPI.Controller, :update_banner)
264 post("/qvitter/update_background_image", TwitterAPI.Controller, :update_background)
265
266 post(
267 "/account/most_recent_notification",
268 TwitterAPI.Controller,
269 :update_most_recent_notification
270 )
271
272 get("/statuses/home_timeline", TwitterAPI.Controller, :friends_timeline)
273 get("/statuses/friends_timeline", TwitterAPI.Controller, :friends_timeline)
274 get("/statuses/mentions", TwitterAPI.Controller, :mentions_timeline)
275 get("/statuses/mentions_timeline", TwitterAPI.Controller, :mentions_timeline)
276 get("/qvitter/statuses/notifications", TwitterAPI.Controller, :notifications)
277
278 post("/statuses/update", TwitterAPI.Controller, :status_update)
279 post("/statuses/retweet/:id", TwitterAPI.Controller, :retweet)
280 post("/statuses/unretweet/:id", TwitterAPI.Controller, :unretweet)
281 post("/statuses/destroy/:id", TwitterAPI.Controller, :delete_post)
282
283 get("/pleroma/friend_requests", TwitterAPI.Controller, :friend_requests)
284 post("/pleroma/friendships/approve", TwitterAPI.Controller, :approve_friend_request)
285 post("/pleroma/friendships/deny", TwitterAPI.Controller, :deny_friend_request)
286
287 post("/friendships/create", TwitterAPI.Controller, :follow)
288 post("/friendships/destroy", TwitterAPI.Controller, :unfollow)
289 post("/blocks/create", TwitterAPI.Controller, :block)
290 post("/blocks/destroy", TwitterAPI.Controller, :unblock)
291
292 post("/statusnet/media/upload", TwitterAPI.Controller, :upload)
293 post("/media/upload", TwitterAPI.Controller, :upload_json)
294
295 post("/favorites/create/:id", TwitterAPI.Controller, :favorite)
296 post("/favorites/create", TwitterAPI.Controller, :favorite)
297 post("/favorites/destroy/:id", TwitterAPI.Controller, :unfavorite)
298
299 post("/qvitter/update_avatar", TwitterAPI.Controller, :update_avatar)
300
301 get("/friends/ids", TwitterAPI.Controller, :friends_ids)
302 get("/friendships/no_retweets/ids", TwitterAPI.Controller, :empty_array)
303
304 get("/mutes/users/ids", TwitterAPI.Controller, :empty_array)
305 get("/qvitter/mutes", TwitterAPI.Controller, :raw_empty_array)
306
307 get("/externalprofile/show", TwitterAPI.Controller, :external_profile)
308 end
309
310 pipeline :ap_relay do
311 plug(:accepts, ["activity+json"])
312 end
313
314 pipeline :ostatus do
315 plug(:accepts, ["xml", "atom", "html", "activity+json"])
316 end
317
318 scope "/", Pleroma.Web do
319 pipe_through(:ostatus)
320
321 get("/objects/:uuid", OStatus.OStatusController, :object)
322 get("/activities/:uuid", OStatus.OStatusController, :activity)
323 get("/notice/:id", OStatus.OStatusController, :notice)
324 get("/users/:nickname/feed", OStatus.OStatusController, :feed)
325 get("/users/:nickname", OStatus.OStatusController, :feed_redirect)
326
327 if @federating do
328 post("/users/:nickname/salmon", OStatus.OStatusController, :salmon_incoming)
329 post("/push/hub/:nickname", Websub.WebsubController, :websub_subscription_request)
330 get("/push/subscriptions/:id", Websub.WebsubController, :websub_subscription_confirmation)
331 post("/push/subscriptions/:id", Websub.WebsubController, :websub_incoming)
332 end
333 end
334
335 pipeline :activitypub do
336 plug(:accepts, ["activity+json"])
337 plug(Pleroma.Web.Plugs.HTTPSignaturePlug)
338 end
339
340 scope "/", Pleroma.Web.ActivityPub do
341 # XXX: not really ostatus
342 pipe_through(:ostatus)
343
344 get("/users/:nickname/followers", ActivityPubController, :followers)
345 get("/users/:nickname/following", ActivityPubController, :following)
346 get("/users/:nickname/outbox", ActivityPubController, :outbox)
347 end
348
349 if @federating do
350 if @allow_relay do
351 scope "/relay", Pleroma.Web.ActivityPub do
352 pipe_through(:ap_relay)
353 get("/", ActivityPubController, :relay)
354 end
355 end
356
357 scope "/", Pleroma.Web.ActivityPub do
358 pipe_through(:activitypub)
359 post("/users/:nickname/inbox", ActivityPubController, :inbox)
360 post("/inbox", ActivityPubController, :inbox)
361 end
362
363 scope "/.well-known", Pleroma.Web do
364 pipe_through(:well_known)
365
366 get("/host-meta", WebFinger.WebFingerController, :host_meta)
367 get("/webfinger", WebFinger.WebFingerController, :webfinger)
368 get("/nodeinfo", Nodeinfo.NodeinfoController, :schemas)
369 end
370
371 scope "/nodeinfo", Pleroma.Web do
372 get("/:version", Nodeinfo.NodeinfoController, :nodeinfo)
373 end
374 end
375
376 scope "/", Pleroma.Web.MastodonAPI do
377 pipe_through(:mastodon_html)
378
379 get("/web/login", MastodonAPIController, :login)
380 post("/web/login", MastodonAPIController, :login_post)
381 get("/web/*path", MastodonAPIController, :index)
382 delete("/auth/sign_out", MastodonAPIController, :logout)
383 end
384
385 pipeline :remote_media do
386 plug(:accepts, ["html"])
387 end
388
389 scope "/proxy/", Pleroma.Web.MediaProxy do
390 pipe_through(:remote_media)
391 get("/:sig/:url", MediaProxyController, :remote)
392 end
393
394 scope "/", Fallback do
395 get("/registration/:token", RedirectController, :registration_page)
396 get("/*path", RedirectController, :redirector)
397 end
398 end
399
400 defmodule Fallback.RedirectController do
401 use Pleroma.Web, :controller
402
403 def redirector(conn, _params) do
404 if Mix.env() != :test do
405 conn
406 |> put_resp_content_type("text/html")
407 |> send_file(200, "priv/static/index.html")
408 end
409 end
410
411 def registration_page(conn, params) do
412 redirector(conn, params)
413 end
414 end