3e9a8ba7b020e52454e0d45778d6b7d682b5003b
[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"]
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 get "/statuses/public_and_external_timeline", TwitterAPI.Controller, :public_and_external_timeline
164 get "/statuses/networkpublic_timeline", TwitterAPI.Controller, :public_and_external_timeline
165 get "/statuses/user_timeline", TwitterAPI.Controller, :user_timeline
166 get "/qvitter/statuses/user_timeline", TwitterAPI.Controller, :user_timeline
167 get "/users/show", TwitterAPI.Controller, :show_user
168
169 get "/statuses/followers", TwitterAPI.Controller, :followers
170 get "/statuses/friends", TwitterAPI.Controller, :friends
171 get "/statuses/show/:id", TwitterAPI.Controller, :fetch_status
172 get "/statusnet/conversation/:id", TwitterAPI.Controller, :fetch_conversation
173
174 if @registrations_open do
175 post "/account/register", TwitterAPI.Controller, :register
176 end
177
178 get "/search", TwitterAPI.Controller, :search
179 get "/statusnet/tags/timeline/:tag", TwitterAPI.Controller, :public_and_external_timeline
180 end
181
182 scope "/api", Pleroma.Web do
183 pipe_through :authenticated_api
184
185 get "/account/verify_credentials", TwitterAPI.Controller, :verify_credentials
186 post "/account/verify_credentials", TwitterAPI.Controller, :verify_credentials
187
188 post "/account/update_profile", TwitterAPI.Controller, :update_profile
189 post "/account/update_profile_banner", TwitterAPI.Controller, :update_banner
190 post "/qvitter/update_background_image", TwitterAPI.Controller, :update_background
191
192 post "/account/most_recent_notification", TwitterAPI.Controller, :update_most_recent_notification
193
194 get "/statuses/home_timeline", TwitterAPI.Controller, :friends_timeline
195 get "/statuses/friends_timeline", TwitterAPI.Controller, :friends_timeline
196 get "/statuses/mentions", TwitterAPI.Controller, :mentions_timeline
197 get "/statuses/mentions_timeline", TwitterAPI.Controller, :mentions_timeline
198
199 post "/statuses/update", TwitterAPI.Controller, :status_update
200 post "/statuses/retweet/:id", TwitterAPI.Controller, :retweet
201 post "/statuses/destroy/:id", TwitterAPI.Controller, :delete_post
202
203 post "/friendships/create", TwitterAPI.Controller, :follow
204 post "/friendships/destroy", TwitterAPI.Controller, :unfollow
205 post "/blocks/create", TwitterAPI.Controller, :block
206 post "/blocks/destroy", TwitterAPI.Controller, :unblock
207
208 post "/statusnet/media/upload", TwitterAPI.Controller, :upload
209 post "/media/upload", TwitterAPI.Controller, :upload_json
210
211 post "/favorites/create/:id", TwitterAPI.Controller, :favorite
212 post "/favorites/create", TwitterAPI.Controller, :favorite
213 post "/favorites/destroy/:id", TwitterAPI.Controller, :unfavorite
214
215 post "/qvitter/update_avatar", TwitterAPI.Controller, :update_avatar
216
217 get "/friends/ids", TwitterAPI.Controller, :friends_ids
218 get "/friendships/no_retweets/ids", TwitterAPI.Controller, :empty_array
219
220 get "/mutes/users/ids", TwitterAPI.Controller, :empty_array
221
222 get "/externalprofile/show", TwitterAPI.Controller, :external_profile
223 end
224
225 pipeline :ostatus do
226 plug :accepts, ["xml", "atom", "html", "activity+json"]
227 end
228
229 scope "/", Pleroma.Web do
230 pipe_through :ostatus
231
232 get "/objects/:uuid", OStatus.OStatusController, :object
233 get "/activities/:uuid", OStatus.OStatusController, :activity
234 get "/notice/:id", OStatus.OStatusController, :notice
235 get "/users/:nickname/feed", OStatus.OStatusController, :feed
236 get "/users/:nickname", OStatus.OStatusController, :feed_redirect
237
238 if @federating do
239 post "/users/:nickname/salmon", OStatus.OStatusController, :salmon_incoming
240 post "/push/hub/:nickname", Websub.WebsubController, :websub_subscription_request
241 get "/push/subscriptions/:id", Websub.WebsubController, :websub_subscription_confirmation
242 post "/push/subscriptions/:id", Websub.WebsubController, :websub_incoming
243 end
244
245 end
246
247 pipeline :activitypub do
248 plug :accepts, ["activity+json"]
249 plug Pleroma.Web.Plugs.HTTPSignaturePlug
250 end
251
252 if @federating do
253 scope "/", Pleroma.Web.ActivityPub do
254 pipe_through :activitypub
255 post "/users/:nickname/inbox", ActivityPubController, :inbox
256 post "/inbox", ActivityPubController, :inbox
257 end
258
259 scope "/.well-known", Pleroma.Web do
260 pipe_through :well_known
261
262 get "/host-meta", WebFinger.WebFingerController, :host_meta
263 get "/webfinger", WebFinger.WebFingerController, :webfinger
264 end
265 end
266
267 scope "/", Pleroma.Web.MastodonAPI do
268 pipe_through :mastodon_html
269
270 get "/web/login", MastodonAPIController, :login
271 post "/web/login", MastodonAPIController, :login_post
272 get "/web/*path", MastodonAPIController, :index
273 delete "/auth/sign_out", MastodonAPIController, :logout
274 end
275
276 pipeline :remote_media do
277 plug :accepts, ["html"]
278 end
279 scope "/proxy/", Pleroma.Web.MediaProxy do
280 pipe_through :remote_media
281 get "/:sig/:url", MediaProxyController, :remote
282 end
283
284 scope "/", Fallback do
285 get "/*path", RedirectController, :redirector
286 end
287 end
288
289 defmodule Fallback.RedirectController do
290 use Pleroma.Web, :controller
291 def redirector(conn, _params) do
292 if Mix.env != :test do
293 conn
294 |> put_resp_content_type("text/html")
295 |> send_file(200, "priv/static/index.html")
296 end
297 end
298 end