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