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