Mastodon API: Support push subscription CRUD
[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 post("/push/subscription", MastodonAPIController, :create_push_subscription)
175 get("/push/subscription", MastodonAPIController, :get_push_subscription)
176 put("/push/subscription", MastodonAPIController, :update_push_subscription)
177 delete("/push/subscription", MastodonAPIController, :delete_push_subscription)
178
179 get("/suggestions", MastodonAPIController, :suggestions)
180
181 get("/endorsements", MastodonAPIController, :empty_array)
182 end
183
184 scope "/api/web", Pleroma.Web.MastodonAPI do
185 pipe_through(:authenticated_api)
186
187 put("/settings", MastodonAPIController, :put_settings)
188 end
189
190 scope "/api/v1", Pleroma.Web.MastodonAPI do
191 pipe_through(:api)
192 get("/instance", MastodonAPIController, :masto_instance)
193 get("/instance/peers", MastodonAPIController, :peers)
194 post("/apps", MastodonAPIController, :create_app)
195 get("/custom_emojis", MastodonAPIController, :custom_emojis)
196
197 get("/timelines/public", MastodonAPIController, :public_timeline)
198 get("/timelines/tag/:tag", MastodonAPIController, :hashtag_timeline)
199 get("/timelines/list/:list_id", MastodonAPIController, :list_timeline)
200
201 get("/statuses/:id", MastodonAPIController, :get_status)
202 get("/statuses/:id/context", MastodonAPIController, :get_context)
203 get("/statuses/:id/card", MastodonAPIController, :empty_object)
204 get("/statuses/:id/favourited_by", MastodonAPIController, :favourited_by)
205 get("/statuses/:id/reblogged_by", MastodonAPIController, :reblogged_by)
206
207 get("/accounts/:id/statuses", MastodonAPIController, :user_statuses)
208 get("/accounts/:id/followers", MastodonAPIController, :followers)
209 get("/accounts/:id/following", MastodonAPIController, :following)
210 get("/accounts/:id", MastodonAPIController, :user)
211
212 get("/trends", MastodonAPIController, :empty_array)
213
214 get("/search", MastodonAPIController, :search)
215 end
216
217 scope "/api/v2", Pleroma.Web.MastodonAPI do
218 pipe_through(:api)
219 get("/search", MastodonAPIController, :search2)
220 end
221
222 scope "/api", Pleroma.Web do
223 pipe_through(:config)
224
225 get("/help/test", TwitterAPI.UtilController, :help_test)
226 post("/help/test", TwitterAPI.UtilController, :help_test)
227 get("/statusnet/config", TwitterAPI.UtilController, :config)
228 get("/statusnet/version", TwitterAPI.UtilController, :version)
229 end
230
231 scope "/api", Pleroma.Web do
232 pipe_through(:api)
233
234 get("/statuses/user_timeline", TwitterAPI.Controller, :user_timeline)
235 get("/qvitter/statuses/user_timeline", TwitterAPI.Controller, :user_timeline)
236 get("/users/show", TwitterAPI.Controller, :show_user)
237
238 get("/statuses/followers", TwitterAPI.Controller, :followers)
239 get("/statuses/friends", TwitterAPI.Controller, :friends)
240 get("/statuses/show/:id", TwitterAPI.Controller, :fetch_status)
241 get("/statusnet/conversation/:id", TwitterAPI.Controller, :fetch_conversation)
242
243 post("/account/register", TwitterAPI.Controller, :register)
244
245 get("/search", TwitterAPI.Controller, :search)
246 get("/statusnet/tags/timeline/:tag", TwitterAPI.Controller, :public_and_external_timeline)
247 end
248
249 scope "/api", Pleroma.Web do
250 if @public do
251 pipe_through(:api)
252 else
253 pipe_through(:authenticated_api)
254 end
255
256 get("/statuses/public_timeline", TwitterAPI.Controller, :public_timeline)
257
258 get(
259 "/statuses/public_and_external_timeline",
260 TwitterAPI.Controller,
261 :public_and_external_timeline
262 )
263
264 get("/statuses/networkpublic_timeline", TwitterAPI.Controller, :public_and_external_timeline)
265 end
266
267 scope "/api", Pleroma.Web do
268 pipe_through(:authenticated_api)
269
270 get("/account/verify_credentials", TwitterAPI.Controller, :verify_credentials)
271 post("/account/verify_credentials", TwitterAPI.Controller, :verify_credentials)
272
273 post("/account/update_profile", TwitterAPI.Controller, :update_profile)
274 post("/account/update_profile_banner", TwitterAPI.Controller, :update_banner)
275 post("/qvitter/update_background_image", TwitterAPI.Controller, :update_background)
276
277 post(
278 "/account/most_recent_notification",
279 TwitterAPI.Controller,
280 :update_most_recent_notification
281 )
282
283 get("/statuses/home_timeline", TwitterAPI.Controller, :friends_timeline)
284 get("/statuses/friends_timeline", TwitterAPI.Controller, :friends_timeline)
285 get("/statuses/mentions", TwitterAPI.Controller, :mentions_timeline)
286 get("/statuses/mentions_timeline", TwitterAPI.Controller, :mentions_timeline)
287 get("/qvitter/statuses/notifications", TwitterAPI.Controller, :notifications)
288
289 post("/statuses/update", TwitterAPI.Controller, :status_update)
290 post("/statuses/retweet/:id", TwitterAPI.Controller, :retweet)
291 post("/statuses/unretweet/:id", TwitterAPI.Controller, :unretweet)
292 post("/statuses/destroy/:id", TwitterAPI.Controller, :delete_post)
293
294 get("/pleroma/friend_requests", TwitterAPI.Controller, :friend_requests)
295 post("/pleroma/friendships/approve", TwitterAPI.Controller, :approve_friend_request)
296 post("/pleroma/friendships/deny", TwitterAPI.Controller, :deny_friend_request)
297
298 post("/friendships/create", TwitterAPI.Controller, :follow)
299 post("/friendships/destroy", TwitterAPI.Controller, :unfollow)
300 post("/blocks/create", TwitterAPI.Controller, :block)
301 post("/blocks/destroy", TwitterAPI.Controller, :unblock)
302
303 post("/statusnet/media/upload", TwitterAPI.Controller, :upload)
304 post("/media/upload", TwitterAPI.Controller, :upload_json)
305
306 post("/favorites/create/:id", TwitterAPI.Controller, :favorite)
307 post("/favorites/create", TwitterAPI.Controller, :favorite)
308 post("/favorites/destroy/:id", TwitterAPI.Controller, :unfavorite)
309
310 post("/qvitter/update_avatar", TwitterAPI.Controller, :update_avatar)
311
312 get("/friends/ids", TwitterAPI.Controller, :friends_ids)
313 get("/friendships/no_retweets/ids", TwitterAPI.Controller, :empty_array)
314
315 get("/mutes/users/ids", TwitterAPI.Controller, :empty_array)
316 get("/qvitter/mutes", TwitterAPI.Controller, :raw_empty_array)
317
318 get("/externalprofile/show", TwitterAPI.Controller, :external_profile)
319 end
320
321 pipeline :ap_relay do
322 plug(:accepts, ["activity+json"])
323 end
324
325 pipeline :ostatus do
326 plug(:accepts, ["xml", "atom", "html", "activity+json"])
327 end
328
329 scope "/", Pleroma.Web do
330 pipe_through(:ostatus)
331
332 get("/objects/:uuid", OStatus.OStatusController, :object)
333 get("/activities/:uuid", OStatus.OStatusController, :activity)
334 get("/notice/:id", OStatus.OStatusController, :notice)
335 get("/users/:nickname/feed", OStatus.OStatusController, :feed)
336 get("/users/:nickname", OStatus.OStatusController, :feed_redirect)
337
338 if @federating do
339 post("/users/:nickname/salmon", OStatus.OStatusController, :salmon_incoming)
340 post("/push/hub/:nickname", Websub.WebsubController, :websub_subscription_request)
341 get("/push/subscriptions/:id", Websub.WebsubController, :websub_subscription_confirmation)
342 post("/push/subscriptions/:id", Websub.WebsubController, :websub_incoming)
343 end
344 end
345
346 pipeline :activitypub do
347 plug(:accepts, ["activity+json"])
348 plug(Pleroma.Web.Plugs.HTTPSignaturePlug)
349 end
350
351 scope "/", Pleroma.Web.ActivityPub do
352 # XXX: not really ostatus
353 pipe_through(:ostatus)
354
355 get("/users/:nickname/followers", ActivityPubController, :followers)
356 get("/users/:nickname/following", ActivityPubController, :following)
357 get("/users/:nickname/outbox", ActivityPubController, :outbox)
358 end
359
360 if @federating do
361 if @allow_relay do
362 scope "/relay", Pleroma.Web.ActivityPub do
363 pipe_through(:ap_relay)
364 get("/", ActivityPubController, :relay)
365 end
366 end
367
368 scope "/", Pleroma.Web.ActivityPub do
369 pipe_through(:activitypub)
370 post("/users/:nickname/inbox", ActivityPubController, :inbox)
371 post("/inbox", ActivityPubController, :inbox)
372 end
373
374 scope "/.well-known", Pleroma.Web do
375 pipe_through(:well_known)
376
377 get("/host-meta", WebFinger.WebFingerController, :host_meta)
378 get("/webfinger", WebFinger.WebFingerController, :webfinger)
379 get("/nodeinfo", Nodeinfo.NodeinfoController, :schemas)
380 end
381
382 scope "/nodeinfo", Pleroma.Web do
383 get("/:version", Nodeinfo.NodeinfoController, :nodeinfo)
384 end
385 end
386
387 scope "/", Pleroma.Web.MastodonAPI do
388 pipe_through(:mastodon_html)
389
390 get("/web/login", MastodonAPIController, :login)
391 post("/web/login", MastodonAPIController, :login_post)
392 get("/web/*path", MastodonAPIController, :index)
393 delete("/auth/sign_out", MastodonAPIController, :logout)
394 end
395
396 pipeline :remote_media do
397 plug(:accepts, ["html"])
398 end
399
400 scope "/proxy/", Pleroma.Web.MediaProxy do
401 pipe_through(:remote_media)
402 get("/:sig/:url", MediaProxyController, :remote)
403 end
404
405 scope "/", Fallback do
406 get("/registration/:token", RedirectController, :registration_page)
407 get("/*path", RedirectController, :redirector)
408
409 options("/*path", RedirectController, :empty)
410 end
411 end
412
413 defmodule Fallback.RedirectController do
414 use Pleroma.Web, :controller
415
416 def redirector(conn, _params) do
417 if Mix.env() != :test do
418 conn
419 |> put_resp_content_type("text/html")
420 |> send_file(200, "priv/static/index.html")
421 end
422 end
423
424 def registration_page(conn, params) do
425 redirector(conn, params)
426 end
427
428 def empty(conn, _params) do
429 conn
430 |> put_status(204)
431 |> text("")
432 end
433 end