Format.
[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 :mastodon_html do
35 plug(:accepts, ["html"])
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.EnsureUserKeyPlug)
46 end
47
48 pipeline :pleroma_html do
49 plug(:accepts, ["html"])
50 plug(:fetch_session)
51 plug(Pleroma.Plugs.OAuthPlug)
52 plug(Pleroma.Plugs.BasicAuthDecoderPlug)
53 plug(Pleroma.Plugs.UserFetcherPlug)
54 plug(Pleroma.Plugs.SessionAuthenticationPlug)
55 plug(Pleroma.Plugs.AuthenticationPlug)
56 plug(Pleroma.Plugs.EnsureUserKeyPlug)
57 end
58
59 pipeline :well_known do
60 plug(:accepts, ["json", "jrd+json", "xml", "xrd+xml"])
61 end
62
63 pipeline :config do
64 plug(:accepts, ["json", "xml"])
65 end
66
67 pipeline :oauth do
68 plug(:accepts, ["html", "json"])
69 end
70
71 pipeline :pleroma_api do
72 plug(:accepts, ["html", "json"])
73 end
74
75 scope "/api/pleroma", Pleroma.Web.TwitterAPI do
76 pipe_through(:pleroma_api)
77 get("/password_reset/:token", UtilController, :show_password_reset)
78 post("/password_reset", UtilController, :password_reset)
79 get("/emoji", UtilController, :emoji)
80 end
81
82 scope "/", Pleroma.Web.TwitterAPI do
83 pipe_through(:pleroma_html)
84 get("/ostatus_subscribe", UtilController, :remote_follow)
85 post("/ostatus_subscribe", UtilController, :do_remote_follow)
86 post("/main/ostatus", UtilController, :remote_subscribe)
87 end
88
89 scope "/api/pleroma", Pleroma.Web.TwitterAPI do
90 pipe_through(:authenticated_api)
91 post("/follow_import", UtilController, :follow_import)
92 post("/change_password", UtilController, :change_password)
93 post("/delete_account", UtilController, :delete_account)
94 end
95
96 scope "/oauth", Pleroma.Web.OAuth do
97 get("/authorize", OAuthController, :authorize)
98 post("/authorize", OAuthController, :create_authorization)
99 post("/token", OAuthController, :token_exchange)
100 post("/revoke", OAuthController, :token_revoke)
101 end
102
103 scope "/api/v1", Pleroma.Web.MastodonAPI do
104 pipe_through(:authenticated_api)
105
106 patch("/accounts/update_credentials", MastodonAPIController, :update_credentials)
107 get("/accounts/verify_credentials", MastodonAPIController, :verify_credentials)
108 get("/accounts/relationships", MastodonAPIController, :relationships)
109 get("/accounts/search", MastodonAPIController, :account_search)
110 post("/accounts/:id/follow", MastodonAPIController, :follow)
111 post("/accounts/:id/unfollow", MastodonAPIController, :unfollow)
112 post("/accounts/:id/block", MastodonAPIController, :block)
113 post("/accounts/:id/unblock", MastodonAPIController, :unblock)
114 post("/accounts/:id/mute", MastodonAPIController, :relationship_noop)
115 post("/accounts/:id/unmute", MastodonAPIController, :relationship_noop)
116 get("/accounts/:id/lists", MastodonAPIController, :account_lists)
117
118 get("/follow_requests", MastodonAPIController, :follow_requests)
119 post("/follow_requests/:id/authorize", MastodonAPIController, :authorize_follow_request)
120 post("/follow_requests/:id/reject", MastodonAPIController, :reject_follow_request)
121
122 post("/follows", MastodonAPIController, :follow)
123
124 get("/blocks", MastodonAPIController, :blocks)
125
126 get("/mutes", MastodonAPIController, :empty_array)
127
128 get("/timelines/home", MastodonAPIController, :home_timeline)
129
130 get("/timelines/direct", MastodonAPIController, :dm_timeline)
131
132 get("/favourites", MastodonAPIController, :favourites)
133
134 post("/statuses", MastodonAPIController, :post_status)
135 delete("/statuses/:id", MastodonAPIController, :delete_status)
136
137 post("/statuses/:id/reblog", MastodonAPIController, :reblog_status)
138 post("/statuses/:id/unreblog", MastodonAPIController, :unreblog_status)
139 post("/statuses/:id/favourite", MastodonAPIController, :fav_status)
140 post("/statuses/:id/unfavourite", MastodonAPIController, :unfav_status)
141
142 post("/notifications/clear", MastodonAPIController, :clear_notifications)
143 post("/notifications/dismiss", MastodonAPIController, :dismiss_notification)
144 get("/notifications", MastodonAPIController, :notifications)
145 get("/notifications/:id", MastodonAPIController, :get_notification)
146
147 post("/media", MastodonAPIController, :upload)
148 put("/media/:id", MastodonAPIController, :update_media)
149
150 get("/lists", MastodonAPIController, :get_lists)
151 get("/lists/:id", MastodonAPIController, :get_list)
152 delete("/lists/:id", MastodonAPIController, :delete_list)
153 post("/lists", MastodonAPIController, :create_list)
154 put("/lists/:id", MastodonAPIController, :rename_list)
155 get("/lists/:id/accounts", MastodonAPIController, :list_accounts)
156 post("/lists/:id/accounts", MastodonAPIController, :add_to_list)
157 delete("/lists/:id/accounts", MastodonAPIController, :remove_from_list)
158
159 get("/domain_blocks", MastodonAPIController, :domain_blocks)
160 post("/domain_blocks", MastodonAPIController, :block_domain)
161 delete("/domain_blocks", MastodonAPIController, :unblock_domain)
162
163 get("/filters", MastodonAPIController, :get_filters)
164 post("/filters", MastodonAPIController, :create_filter)
165 get("/filters/:id", MastodonAPIController, :get_filter)
166 put("/filters/:id", MastodonAPIController, :update_filter)
167 delete("/filters/:id", MastodonAPIController, :delete_filter)
168
169 get("/suggestions", MastodonAPIController, :suggestions)
170
171 get("/endorsements", MastodonAPIController, :empty_array)
172 end
173
174 scope "/api/web", Pleroma.Web.MastodonAPI do
175 pipe_through(:authenticated_api)
176
177 put("/settings", MastodonAPIController, :put_settings)
178 end
179
180 scope "/api/v1", Pleroma.Web.MastodonAPI do
181 pipe_through(:api)
182 get("/instance", MastodonAPIController, :masto_instance)
183 get("/instance/peers", MastodonAPIController, :peers)
184 post("/apps", MastodonAPIController, :create_app)
185 get("/custom_emojis", MastodonAPIController, :custom_emojis)
186
187 get("/timelines/public", MastodonAPIController, :public_timeline)
188 get("/timelines/tag/:tag", MastodonAPIController, :hashtag_timeline)
189 get("/timelines/list/:list_id", MastodonAPIController, :list_timeline)
190
191 get("/statuses/:id", MastodonAPIController, :get_status)
192 get("/statuses/:id/context", MastodonAPIController, :get_context)
193 get("/statuses/:id/card", MastodonAPIController, :empty_object)
194 get("/statuses/:id/favourited_by", MastodonAPIController, :favourited_by)
195 get("/statuses/:id/reblogged_by", MastodonAPIController, :reblogged_by)
196
197 get("/accounts/:id/statuses", MastodonAPIController, :user_statuses)
198 get("/accounts/:id/followers", MastodonAPIController, :followers)
199 get("/accounts/:id/following", MastodonAPIController, :following)
200 get("/accounts/:id", MastodonAPIController, :user)
201
202 get("/trends", MastodonAPIController, :empty_array)
203
204 get("/search", MastodonAPIController, :search)
205 end
206
207 scope "/api/v2", Pleroma.Web.MastodonAPI do
208 pipe_through(:api)
209 get("/search", MastodonAPIController, :search2)
210 end
211
212 scope "/api", Pleroma.Web do
213 pipe_through(:config)
214
215 get("/help/test", TwitterAPI.UtilController, :help_test)
216 post("/help/test", TwitterAPI.UtilController, :help_test)
217 get("/statusnet/config", TwitterAPI.UtilController, :config)
218 get("/statusnet/version", TwitterAPI.UtilController, :version)
219 end
220
221 scope "/api", Pleroma.Web do
222 pipe_through(:api)
223
224 get("/statuses/user_timeline", TwitterAPI.Controller, :user_timeline)
225 get("/qvitter/statuses/user_timeline", TwitterAPI.Controller, :user_timeline)
226 get("/users/show", TwitterAPI.Controller, :show_user)
227
228 get("/statuses/followers", TwitterAPI.Controller, :followers)
229 get("/statuses/friends", TwitterAPI.Controller, :friends)
230 get("/statuses/show/:id", TwitterAPI.Controller, :fetch_status)
231 get("/statusnet/conversation/:id", TwitterAPI.Controller, :fetch_conversation)
232
233 post("/account/register", TwitterAPI.Controller, :register)
234
235 get("/search", TwitterAPI.Controller, :search)
236 get("/statusnet/tags/timeline/:tag", TwitterAPI.Controller, :public_and_external_timeline)
237 end
238
239 scope "/api", Pleroma.Web do
240 pipe_through(:api)
241
242 get("/statuses/public_timeline", TwitterAPI.Controller, :public_timeline)
243
244 get(
245 "/statuses/public_and_external_timeline",
246 TwitterAPI.Controller,
247 :public_and_external_timeline
248 )
249
250 get("/statuses/networkpublic_timeline", TwitterAPI.Controller, :public_and_external_timeline)
251 end
252
253 scope "/api", Pleroma.Web, as: :twitter_api_search do
254 pipe_through(:api)
255 get("/pleroma/search_user", TwitterAPI.Controller, :search_user)
256 end
257
258 scope "/api", Pleroma.Web, as: :authenticated_twitter_api do
259 pipe_through(:authenticated_api)
260
261 get("/account/verify_credentials", TwitterAPI.Controller, :verify_credentials)
262 post("/account/verify_credentials", TwitterAPI.Controller, :verify_credentials)
263
264 post("/account/update_profile", TwitterAPI.Controller, :update_profile)
265 post("/account/update_profile_banner", TwitterAPI.Controller, :update_banner)
266 post("/qvitter/update_background_image", TwitterAPI.Controller, :update_background)
267
268 post(
269 "/account/most_recent_notification",
270 TwitterAPI.Controller,
271 :update_most_recent_notification
272 )
273
274 get("/statuses/home_timeline", TwitterAPI.Controller, :friends_timeline)
275 get("/statuses/friends_timeline", TwitterAPI.Controller, :friends_timeline)
276 get("/statuses/mentions", TwitterAPI.Controller, :mentions_timeline)
277 get("/statuses/mentions_timeline", TwitterAPI.Controller, :mentions_timeline)
278 get("/statuses/dm_timeline", TwitterAPI.Controller, :dm_timeline)
279 get("/qvitter/statuses/notifications", TwitterAPI.Controller, :notifications)
280
281 # XXX: this is really a pleroma API, but we want to keep the pleroma namespace clean
282 # for now.
283 post("/qvitter/statuses/notifications/read", TwitterAPI.Controller, :notifications_read)
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 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
340 pipeline :activitypub do
341 plug(:accepts, ["activity+json"])
342 plug(Pleroma.Web.Plugs.HTTPSignaturePlug)
343 end
344
345 scope "/", Pleroma.Web.ActivityPub do
346 # XXX: not really ostatus
347 pipe_through(:ostatus)
348
349 get("/users/:nickname/followers", ActivityPubController, :followers)
350 get("/users/:nickname/following", ActivityPubController, :following)
351 get("/users/:nickname/outbox", ActivityPubController, :outbox)
352 end
353
354 scope "/relay", Pleroma.Web.ActivityPub do
355 pipe_through(:ap_relay)
356 get("/", ActivityPubController, :relay)
357 end
358
359 scope "/", Pleroma.Web.ActivityPub do
360 pipe_through(:activitypub)
361 post("/users/:nickname/inbox", ActivityPubController, :inbox)
362 post("/inbox", ActivityPubController, :inbox)
363 end
364
365 scope "/.well-known", Pleroma.Web do
366 pipe_through(:well_known)
367
368 get("/host-meta", WebFinger.WebFingerController, :host_meta)
369 get("/webfinger", WebFinger.WebFingerController, :webfinger)
370 get("/nodeinfo", Nodeinfo.NodeinfoController, :schemas)
371 end
372
373 scope "/nodeinfo", Pleroma.Web do
374 get("/:version", Nodeinfo.NodeinfoController, :nodeinfo)
375 end
376
377 scope "/", Pleroma.Web.MastodonAPI do
378 pipe_through(:mastodon_html)
379
380 get("/web/login", MastodonAPIController, :login)
381 post("/web/login", MastodonAPIController, :login_post)
382 get("/web/*path", MastodonAPIController, :index)
383 delete("/auth/sign_out", MastodonAPIController, :logout)
384 end
385
386 pipeline :remote_media do
387 end
388
389 scope "/proxy/", Pleroma.Web.MediaProxy do
390 pipe_through(:remote_media)
391 get("/:sig/:url", MediaProxyController, :remote)
392 get("/:sig/:url/:filename", MediaProxyController, :remote)
393 end
394
395 scope "/", Fallback do
396 get("/registration/:token", RedirectController, :registration_page)
397 get("/*path", RedirectController, :redirector)
398
399 options("/*path", RedirectController, :empty)
400 end
401 end
402
403 defmodule Fallback.RedirectController do
404 use Pleroma.Web, :controller
405
406 def redirector(conn, _params) do
407 if Mix.env() != :test do
408 conn
409 |> put_resp_content_type("text/html")
410 |> send_file(200, "priv/static/index.html")
411 end
412 end
413
414 def registration_page(conn, params) do
415 redirector(conn, params)
416 end
417
418 def empty(conn, _params) do
419 conn
420 |> put_status(204)
421 |> text("")
422 end
423 end