d324efb7e042b1e8f6c16a480485fe7a6282e7a4
[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
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 end
176
177 scope "/api/web", Pleroma.Web.MastodonAPI do
178 pipe_through(:authenticated_api)
179
180 put("/settings", MastodonAPIController, :put_settings)
181 end
182
183 scope "/api/v1", Pleroma.Web.MastodonAPI do
184 pipe_through(:api)
185 get("/instance", MastodonAPIController, :masto_instance)
186 get("/instance/peers", MastodonAPIController, :peers)
187 post("/apps", MastodonAPIController, :create_app)
188 get("/custom_emojis", MastodonAPIController, :custom_emojis)
189
190 get("/timelines/public", MastodonAPIController, :public_timeline)
191 get("/timelines/tag/:tag", MastodonAPIController, :hashtag_timeline)
192 get("/timelines/list/:list_id", MastodonAPIController, :list_timeline)
193
194 get("/statuses/:id", MastodonAPIController, :get_status)
195 get("/statuses/:id/context", MastodonAPIController, :get_context)
196 get("/statuses/:id/card", MastodonAPIController, :empty_object)
197 get("/statuses/:id/favourited_by", MastodonAPIController, :favourited_by)
198 get("/statuses/:id/reblogged_by", MastodonAPIController, :reblogged_by)
199
200 get("/accounts/:id/statuses", MastodonAPIController, :user_statuses)
201 get("/accounts/:id/followers", MastodonAPIController, :followers)
202 get("/accounts/:id/following", MastodonAPIController, :following)
203 get("/accounts/:id", MastodonAPIController, :user)
204
205 get("/trends", MastodonAPIController, :empty_array)
206
207 get("/search", MastodonAPIController, :search)
208 end
209
210 scope "/api/v2", Pleroma.Web.MastodonAPI do
211 pipe_through(:api)
212 get("/search", MastodonAPIController, :search2)
213 end
214
215 scope "/api", Pleroma.Web do
216 pipe_through(:config)
217
218 get("/help/test", TwitterAPI.UtilController, :help_test)
219 post("/help/test", TwitterAPI.UtilController, :help_test)
220 get("/statusnet/config", TwitterAPI.UtilController, :config)
221 get("/statusnet/version", TwitterAPI.UtilController, :version)
222 end
223
224 scope "/api", Pleroma.Web do
225 pipe_through(:api)
226
227 get("/statuses/user_timeline", TwitterAPI.Controller, :user_timeline)
228 get("/qvitter/statuses/user_timeline", TwitterAPI.Controller, :user_timeline)
229 get("/users/show", TwitterAPI.Controller, :show_user)
230
231 get("/statuses/followers", TwitterAPI.Controller, :followers)
232 get("/statuses/friends", TwitterAPI.Controller, :friends)
233 get("/statuses/show/:id", TwitterAPI.Controller, :fetch_status)
234 get("/statusnet/conversation/:id", TwitterAPI.Controller, :fetch_conversation)
235
236 post("/account/register", TwitterAPI.Controller, :register)
237
238 get("/search", TwitterAPI.Controller, :search)
239 get("/statusnet/tags/timeline/:tag", TwitterAPI.Controller, :public_and_external_timeline)
240 end
241
242 scope "/api", Pleroma.Web do
243 if @public do
244 pipe_through(:api)
245 else
246 pipe_through(:authenticated_api)
247 end
248
249 get("/statuses/public_timeline", TwitterAPI.Controller, :public_timeline)
250
251 get(
252 "/statuses/public_and_external_timeline",
253 TwitterAPI.Controller,
254 :public_and_external_timeline
255 )
256
257 get("/statuses/networkpublic_timeline", TwitterAPI.Controller, :public_and_external_timeline)
258 end
259
260 scope "/api", Pleroma.Web do
261 pipe_through(:authenticated_api)
262
263 get("/account/verify_credentials", TwitterAPI.Controller, :verify_credentials)
264 post("/account/verify_credentials", TwitterAPI.Controller, :verify_credentials)
265
266 post("/account/update_profile", TwitterAPI.Controller, :update_profile)
267 post("/account/update_profile_banner", TwitterAPI.Controller, :update_banner)
268 post("/qvitter/update_background_image", TwitterAPI.Controller, :update_background)
269
270 post(
271 "/account/most_recent_notification",
272 TwitterAPI.Controller,
273 :update_most_recent_notification
274 )
275
276 get("/statuses/home_timeline", TwitterAPI.Controller, :friends_timeline)
277 get("/statuses/friends_timeline", TwitterAPI.Controller, :friends_timeline)
278 get("/statuses/mentions", TwitterAPI.Controller, :mentions_timeline)
279 get("/statuses/mentions_timeline", TwitterAPI.Controller, :mentions_timeline)
280 get("/qvitter/statuses/notifications", TwitterAPI.Controller, :notifications)
281
282 post("/statuses/update", TwitterAPI.Controller, :status_update)
283 post("/statuses/retweet/:id", TwitterAPI.Controller, :retweet)
284 post("/statuses/unretweet/:id", TwitterAPI.Controller, :unretweet)
285 post("/statuses/destroy/:id", TwitterAPI.Controller, :delete_post)
286
287 get("/pleroma/friend_requests", TwitterAPI.Controller, :friend_requests)
288 post("/pleroma/friendships/approve", TwitterAPI.Controller, :approve_friend_request)
289 post("/pleroma/friendships/deny", TwitterAPI.Controller, :deny_friend_request)
290
291 post("/friendships/create", TwitterAPI.Controller, :follow)
292 post("/friendships/destroy", TwitterAPI.Controller, :unfollow)
293 post("/blocks/create", TwitterAPI.Controller, :block)
294 post("/blocks/destroy", TwitterAPI.Controller, :unblock)
295
296 post("/statusnet/media/upload", TwitterAPI.Controller, :upload)
297 post("/media/upload", TwitterAPI.Controller, :upload_json)
298
299 post("/favorites/create/:id", TwitterAPI.Controller, :favorite)
300 post("/favorites/create", TwitterAPI.Controller, :favorite)
301 post("/favorites/destroy/:id", TwitterAPI.Controller, :unfavorite)
302
303 post("/qvitter/update_avatar", TwitterAPI.Controller, :update_avatar)
304
305 get("/friends/ids", TwitterAPI.Controller, :friends_ids)
306 get("/friendships/no_retweets/ids", TwitterAPI.Controller, :empty_array)
307
308 get("/mutes/users/ids", TwitterAPI.Controller, :empty_array)
309 get("/qvitter/mutes", TwitterAPI.Controller, :raw_empty_array)
310
311 get("/externalprofile/show", TwitterAPI.Controller, :external_profile)
312 end
313
314 pipeline :ap_relay do
315 plug(:accepts, ["activity+json"])
316 end
317
318 pipeline :ostatus do
319 plug(:accepts, ["xml", "atom", "html", "activity+json"])
320 end
321
322 scope "/", Pleroma.Web do
323 pipe_through(:ostatus)
324
325 get("/objects/:uuid", OStatus.OStatusController, :object)
326 get("/activities/:uuid", OStatus.OStatusController, :activity)
327 get("/notice/:id", OStatus.OStatusController, :notice)
328 get("/users/:nickname/feed", OStatus.OStatusController, :feed)
329 get("/users/:nickname", OStatus.OStatusController, :feed_redirect)
330
331 if @federating do
332 post("/users/:nickname/salmon", OStatus.OStatusController, :salmon_incoming)
333 post("/push/hub/:nickname", Websub.WebsubController, :websub_subscription_request)
334 get("/push/subscriptions/:id", Websub.WebsubController, :websub_subscription_confirmation)
335 post("/push/subscriptions/:id", Websub.WebsubController, :websub_incoming)
336 end
337 end
338
339 pipeline :activitypub do
340 plug(:accepts, ["activity+json"])
341 plug(Pleroma.Web.Plugs.HTTPSignaturePlug)
342 end
343
344 scope "/", Pleroma.Web.ActivityPub do
345 # XXX: not really ostatus
346 pipe_through(:ostatus)
347
348 get("/users/:nickname/followers", ActivityPubController, :followers)
349 get("/users/:nickname/following", ActivityPubController, :following)
350 get("/users/:nickname/outbox", ActivityPubController, :outbox)
351 end
352
353 if @federating do
354 if @allow_relay do
355 scope "/relay", Pleroma.Web.ActivityPub do
356 pipe_through(:ap_relay)
357 get("/", ActivityPubController, :relay)
358 end
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 end
402 end
403
404 defmodule Fallback.RedirectController do
405 use Pleroma.Web, :controller
406
407 def redirector(conn, _params) do
408 if Mix.env() != :test do
409 conn
410 |> put_resp_content_type("text/html")
411 |> send_file(200, "priv/static/index.html")
412 end
413 end
414
415 def registration_page(conn, params) do
416 redirector(conn, params)
417 end
418 end