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