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