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