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