MastoAPI: add domain blocking.
[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, ["xml", "xrd+xml", "json", "jrd+json"])
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 post("/follows", MastodonAPIController, :follow)
101
102 get("/blocks", MastodonAPIController, :blocks)
103
104 get("/follow_requests", MastodonAPIController, :empty_array)
105 get("/mutes", MastodonAPIController, :empty_array)
106
107 get("/timelines/home", MastodonAPIController, :home_timeline)
108
109 get("/timelines/direct", MastodonAPIController, :dm_timeline)
110
111 get("/favourites", MastodonAPIController, :favourites)
112
113 post("/statuses", MastodonAPIController, :post_status)
114 delete("/statuses/:id", MastodonAPIController, :delete_status)
115
116 post("/statuses/:id/reblog", MastodonAPIController, :reblog_status)
117 post("/statuses/:id/unreblog", MastodonAPIController, :unreblog_status)
118 post("/statuses/:id/favourite", MastodonAPIController, :fav_status)
119 post("/statuses/:id/unfavourite", MastodonAPIController, :unfav_status)
120
121 post("/notifications/clear", MastodonAPIController, :clear_notifications)
122 post("/notifications/dismiss", MastodonAPIController, :dismiss_notification)
123 get("/notifications", MastodonAPIController, :notifications)
124 get("/notifications/:id", MastodonAPIController, :get_notification)
125
126 post("/media", MastodonAPIController, :upload)
127
128 get("/lists", MastodonAPIController, :get_lists)
129 get("/lists/:id", MastodonAPIController, :get_list)
130 delete("/lists/:id", MastodonAPIController, :delete_list)
131 post("/lists", MastodonAPIController, :create_list)
132 put("/lists/:id", MastodonAPIController, :rename_list)
133 get("/lists/:id/accounts", MastodonAPIController, :list_accounts)
134 post("/lists/:id/accounts", MastodonAPIController, :add_to_list)
135 delete("/lists/:id/accounts", MastodonAPIController, :remove_from_list)
136
137 get("/domain_blocks", MastodonAPIController, :domain_blocks)
138 post("/domain_blocks", MastodonAPIController, :block_domain)
139 delete("/domain_blocks", MastodonAPIController, :unblock_domain)
140 end
141
142 scope "/api/web", Pleroma.Web.MastodonAPI do
143 pipe_through(:authenticated_api)
144
145 put("/settings", MastodonAPIController, :put_settings)
146 end
147
148 scope "/api/v1", Pleroma.Web.MastodonAPI do
149 pipe_through(:api)
150 get("/instance", MastodonAPIController, :masto_instance)
151 get("/instance/peers", MastodonAPIController, :peers)
152 post("/apps", MastodonAPIController, :create_app)
153 get("/custom_emojis", MastodonAPIController, :custom_emojis)
154
155 get("/timelines/public", MastodonAPIController, :public_timeline)
156 get("/timelines/tag/:tag", MastodonAPIController, :hashtag_timeline)
157 get("/timelines/list/:list_id", MastodonAPIController, :list_timeline)
158
159 get("/statuses/:id", MastodonAPIController, :get_status)
160 get("/statuses/:id/context", MastodonAPIController, :get_context)
161 get("/statuses/:id/card", MastodonAPIController, :empty_object)
162 get("/statuses/:id/favourited_by", MastodonAPIController, :favourited_by)
163 get("/statuses/:id/reblogged_by", MastodonAPIController, :reblogged_by)
164
165 get("/accounts/:id/statuses", MastodonAPIController, :user_statuses)
166 get("/accounts/:id/followers", MastodonAPIController, :followers)
167 get("/accounts/:id/following", MastodonAPIController, :following)
168 get("/accounts/:id", MastodonAPIController, :user)
169
170 get("/search", MastodonAPIController, :search)
171 end
172
173 scope "/api", Pleroma.Web do
174 pipe_through(:config)
175
176 get("/help/test", TwitterAPI.UtilController, :help_test)
177 post("/help/test", TwitterAPI.UtilController, :help_test)
178 get("/statusnet/config", TwitterAPI.UtilController, :config)
179 get("/statusnet/version", TwitterAPI.UtilController, :version)
180 end
181
182 scope "/api", Pleroma.Web do
183 pipe_through(:api)
184
185 get("/statuses/user_timeline", TwitterAPI.Controller, :user_timeline)
186 get("/qvitter/statuses/user_timeline", TwitterAPI.Controller, :user_timeline)
187 get("/users/show", TwitterAPI.Controller, :show_user)
188
189 get("/statuses/followers", TwitterAPI.Controller, :followers)
190 get("/statuses/friends", TwitterAPI.Controller, :friends)
191 get("/statuses/show/:id", TwitterAPI.Controller, :fetch_status)
192 get("/statusnet/conversation/:id", TwitterAPI.Controller, :fetch_conversation)
193
194 if @registrations_open do
195 post("/account/register", TwitterAPI.Controller, :register)
196 end
197
198 get("/search", TwitterAPI.Controller, :search)
199 get("/statusnet/tags/timeline/:tag", TwitterAPI.Controller, :public_and_external_timeline)
200 end
201
202 scope "/api", Pleroma.Web do
203 if @public do
204 pipe_through(:api)
205 else
206 pipe_through(:authenticated_api)
207 end
208
209 get("/statuses/public_timeline", TwitterAPI.Controller, :public_timeline)
210
211 get(
212 "/statuses/public_and_external_timeline",
213 TwitterAPI.Controller,
214 :public_and_external_timeline
215 )
216
217 get("/statuses/networkpublic_timeline", TwitterAPI.Controller, :public_and_external_timeline)
218 end
219
220 scope "/api", Pleroma.Web do
221 pipe_through(:authenticated_api)
222
223 get("/account/verify_credentials", TwitterAPI.Controller, :verify_credentials)
224 post("/account/verify_credentials", TwitterAPI.Controller, :verify_credentials)
225
226 post("/account/update_profile", TwitterAPI.Controller, :update_profile)
227 post("/account/update_profile_banner", TwitterAPI.Controller, :update_banner)
228 post("/qvitter/update_background_image", TwitterAPI.Controller, :update_background)
229
230 post(
231 "/account/most_recent_notification",
232 TwitterAPI.Controller,
233 :update_most_recent_notification
234 )
235
236 get("/statuses/home_timeline", TwitterAPI.Controller, :friends_timeline)
237 get("/statuses/friends_timeline", TwitterAPI.Controller, :friends_timeline)
238 get("/statuses/mentions", TwitterAPI.Controller, :mentions_timeline)
239 get("/statuses/mentions_timeline", TwitterAPI.Controller, :mentions_timeline)
240 get("/qvitter/statuses/notifications", TwitterAPI.Controller, :notifications)
241
242 post("/statuses/update", TwitterAPI.Controller, :status_update)
243 post("/statuses/retweet/:id", TwitterAPI.Controller, :retweet)
244 post("/statuses/destroy/:id", TwitterAPI.Controller, :delete_post)
245
246 post("/friendships/create", TwitterAPI.Controller, :follow)
247 post("/friendships/destroy", TwitterAPI.Controller, :unfollow)
248 post("/blocks/create", TwitterAPI.Controller, :block)
249 post("/blocks/destroy", TwitterAPI.Controller, :unblock)
250
251 post("/statusnet/media/upload", TwitterAPI.Controller, :upload)
252 post("/media/upload", TwitterAPI.Controller, :upload_json)
253
254 post("/favorites/create/:id", TwitterAPI.Controller, :favorite)
255 post("/favorites/create", TwitterAPI.Controller, :favorite)
256 post("/favorites/destroy/:id", TwitterAPI.Controller, :unfavorite)
257
258 post("/qvitter/update_avatar", TwitterAPI.Controller, :update_avatar)
259
260 get("/friends/ids", TwitterAPI.Controller, :friends_ids)
261 get("/friendships/no_retweets/ids", TwitterAPI.Controller, :empty_array)
262
263 get("/mutes/users/ids", TwitterAPI.Controller, :empty_array)
264
265 get("/externalprofile/show", TwitterAPI.Controller, :external_profile)
266 end
267
268 pipeline :ostatus do
269 plug(:accepts, ["xml", "atom", "html", "activity+json"])
270 end
271
272 scope "/", Pleroma.Web do
273 pipe_through(:ostatus)
274
275 get("/objects/:uuid", OStatus.OStatusController, :object)
276 get("/activities/:uuid", OStatus.OStatusController, :activity)
277 get("/notice/:id", OStatus.OStatusController, :notice)
278 get("/users/:nickname/feed", OStatus.OStatusController, :feed)
279 get("/users/:nickname", OStatus.OStatusController, :feed_redirect)
280
281 if @federating do
282 post("/users/:nickname/salmon", OStatus.OStatusController, :salmon_incoming)
283 post("/push/hub/:nickname", Websub.WebsubController, :websub_subscription_request)
284 get("/push/subscriptions/:id", Websub.WebsubController, :websub_subscription_confirmation)
285 post("/push/subscriptions/:id", Websub.WebsubController, :websub_incoming)
286 end
287 end
288
289 pipeline :activitypub do
290 plug(:accepts, ["activity+json"])
291 plug(Pleroma.Web.Plugs.HTTPSignaturePlug)
292 end
293
294 scope "/", Pleroma.Web.ActivityPub do
295 # XXX: not really ostatus
296 pipe_through(:ostatus)
297
298 get("/users/:nickname/followers", ActivityPubController, :followers)
299 get("/users/:nickname/following", ActivityPubController, :following)
300 get("/users/:nickname/outbox", ActivityPubController, :outbox)
301 end
302
303 if @federating do
304 scope "/", Pleroma.Web.ActivityPub do
305 pipe_through(:activitypub)
306 post("/users/:nickname/inbox", ActivityPubController, :inbox)
307 post("/inbox", ActivityPubController, :inbox)
308 end
309
310 scope "/.well-known", Pleroma.Web do
311 pipe_through(:well_known)
312
313 get("/host-meta", WebFinger.WebFingerController, :host_meta)
314 get("/webfinger", WebFinger.WebFingerController, :webfinger)
315 get("/nodeinfo", Nodeinfo.NodeinfoController, :schemas)
316 end
317
318 scope "/nodeinfo", Pleroma.Web do
319 get("/:version", Nodeinfo.NodeinfoController, :nodeinfo)
320 end
321 end
322
323 scope "/", Pleroma.Web.MastodonAPI do
324 pipe_through(:mastodon_html)
325
326 get("/web/login", MastodonAPIController, :login)
327 post("/web/login", MastodonAPIController, :login_post)
328 get("/web/*path", MastodonAPIController, :index)
329 delete("/auth/sign_out", MastodonAPIController, :logout)
330 end
331
332 pipeline :remote_media do
333 plug(:accepts, ["html"])
334 end
335
336 scope "/proxy/", Pleroma.Web.MediaProxy do
337 pipe_through(:remote_media)
338 get("/:sig/:url", MediaProxyController, :remote)
339 end
340
341 scope "/", Fallback do
342 get("/*path", RedirectController, :redirector)
343 end
344 end
345
346 defmodule Fallback.RedirectController do
347 use Pleroma.Web, :controller
348
349 def redirector(conn, _params) do
350 if Mix.env() != :test do
351 conn
352 |> put_resp_content_type("text/html")
353 |> send_file(200, "priv/static/index.html")
354 end
355 end
356 end