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