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