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