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