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