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