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