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