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