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