Add remote follow pages.
[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 def user_fetcher(username) do
7 {:ok, Repo.get_by(User, %{nickname: username})}
8 end
9
10 pipeline :api do
11 plug :accepts, ["json"]
12 plug :fetch_session
13 plug Pleroma.Plugs.OAuthPlug
14 plug Pleroma.Plugs.AuthenticationPlug, %{fetcher: &Router.user_fetcher/1, optional: true}
15 end
16
17 pipeline :authenticated_api do
18 plug :accepts, ["json"]
19 plug :fetch_session
20 plug Pleroma.Plugs.OAuthPlug
21 plug Pleroma.Plugs.AuthenticationPlug, %{fetcher: &Router.user_fetcher/1}
22 end
23
24 pipeline :mastodon_html do
25 plug :accepts, ["html"]
26 plug :fetch_session
27 plug Pleroma.Plugs.OAuthPlug
28 plug Pleroma.Plugs.AuthenticationPlug, %{fetcher: &Router.user_fetcher/1, optional: true}
29 end
30
31 pipeline :pleroma_html do
32 plug :accepts, ["html"]
33 plug :fetch_session
34 plug Pleroma.Plugs.OAuthPlug
35 plug Pleroma.Plugs.AuthenticationPlug, %{fetcher: &Router.user_fetcher/1, optional: true}
36 end
37
38 pipeline :well_known do
39 plug :accepts, ["xml", "xrd+xml"]
40 end
41
42 pipeline :config do
43 plug :accepts, ["json", "xml"]
44 end
45
46 pipeline :oauth do
47 plug :accepts, ["html", "json"]
48 end
49
50 pipeline :pleroma_api do
51 plug :accepts, ["html", "json"]
52 end
53
54 scope "/api/pleroma", Pleroma.Web.TwitterAPI do
55 pipe_through :pleroma_api
56 get "/password_reset/:token", UtilController, :show_password_reset
57 post "/password_reset", UtilController, :password_reset
58 get "/emoji", UtilController, :emoji
59 end
60
61 scope "/", Pleroma.Web.TwitterAPI do
62 pipe_through :pleroma_html
63 get "/ostatus_subscribe", UtilController, :remote_follow
64 post "/ostatus_subscribe", UtilController, :do_remote_follow
65 end
66
67 scope "/api/pleroma", Pleroma.Web.TwitterAPI do
68 pipe_through :authenticated_api
69 post "/follow_import", UtilController, :follow_import
70 end
71
72 scope "/oauth", Pleroma.Web.OAuth do
73 get "/authorize", OAuthController, :authorize
74 post "/authorize", OAuthController, :create_authorization
75 post "/token", OAuthController, :token_exchange
76 end
77
78 scope "/api/v1", Pleroma.Web.MastodonAPI do
79 pipe_through :authenticated_api
80
81 patch "/accounts/update_credentials", MastodonAPIController, :update_credentials
82 get "/accounts/verify_credentials", MastodonAPIController, :verify_credentials
83 get "/accounts/relationships", MastodonAPIController, :relationships
84 get "/accounts/search", MastodonAPIController, :account_search
85 post "/accounts/:id/follow", MastodonAPIController, :follow
86 post "/accounts/:id/unfollow", MastodonAPIController, :unfollow
87 post "/accounts/:id/block", MastodonAPIController, :block
88 post "/accounts/:id/unblock", MastodonAPIController, :unblock
89 post "/accounts/:id/mute", MastodonAPIController, :relationship_noop
90 post "/accounts/:id/unmute", MastodonAPIController, :relationship_noop
91
92 post "/follows", MastodonAPIController, :follow
93
94 get "/blocks", MastodonAPIController, :blocks
95
96 get "/domain_blocks", MastodonAPIController, :empty_array
97 get "/follow_requests", MastodonAPIController, :empty_array
98 get "/mutes", MastodonAPIController, :empty_array
99
100 get "/timelines/home", MastodonAPIController, :home_timeline
101
102 get "/favourites", MastodonAPIController, :favourites
103
104 post "/statuses", MastodonAPIController, :post_status
105 delete "/statuses/:id", MastodonAPIController, :delete_status
106
107 post "/statuses/:id/reblog", MastodonAPIController, :reblog_status
108 post "/statuses/:id/favourite", MastodonAPIController, :fav_status
109 post "/statuses/:id/unfavourite", MastodonAPIController, :unfav_status
110
111 post "/notifications/clear", MastodonAPIController, :clear_notifications
112 post "/notifications/dismiss", MastodonAPIController, :dismiss_notification
113 get "/notifications", MastodonAPIController, :notifications
114 get "/notifications/:id", MastodonAPIController, :get_notification
115
116 post "/media", MastodonAPIController, :upload
117 end
118
119 scope "/api/v1", Pleroma.Web.MastodonAPI do
120 pipe_through :api
121 get "/instance", MastodonAPIController, :masto_instance
122 get "/instance/peers", MastodonAPIController, :peers
123 post "/apps", MastodonAPIController, :create_app
124 get "/custom_emojis", MastodonAPIController, :custom_emojis
125
126 get "/timelines/public", MastodonAPIController, :public_timeline
127 get "/timelines/tag/:tag", MastodonAPIController, :hashtag_timeline
128
129 get "/statuses/:id", MastodonAPIController, :get_status
130 get "/statuses/:id/context", MastodonAPIController, :get_context
131 get "/statuses/:id/favourited_by", MastodonAPIController, :favourited_by
132 get "/statuses/:id/reblogged_by", MastodonAPIController, :reblogged_by
133
134 get "/accounts/:id/statuses", MastodonAPIController, :user_statuses
135 get "/accounts/:id/followers", MastodonAPIController, :followers
136 get "/accounts/:id/following", MastodonAPIController, :following
137 get "/accounts/:id", MastodonAPIController, :user
138
139 get "/search", MastodonAPIController, :search
140 end
141
142 scope "/api", Pleroma.Web do
143 pipe_through :config
144
145 get "/help/test", TwitterAPI.UtilController, :help_test
146 post "/help/test", TwitterAPI.UtilController, :help_test
147 get "/statusnet/config", TwitterAPI.UtilController, :config
148 get "/statusnet/version", TwitterAPI.UtilController, :version
149 end
150
151 @instance Application.get_env(:pleroma, :instance)
152 @registrations_open Keyword.get(@instance, :registrations_open)
153
154 scope "/api", Pleroma.Web do
155 pipe_through :api
156
157 get "/statuses/public_timeline", TwitterAPI.Controller, :public_timeline
158 get "/statuses/public_and_external_timeline", TwitterAPI.Controller, :public_and_external_timeline
159 get "/statuses/networkpublic_timeline", TwitterAPI.Controller, :public_and_external_timeline
160 get "/statuses/user_timeline", TwitterAPI.Controller, :user_timeline
161 get "/qvitter/statuses/user_timeline", TwitterAPI.Controller, :user_timeline
162 get "/users/show", TwitterAPI.Controller, :show_user
163
164 get "/statuses/followers", TwitterAPI.Controller, :followers
165 get "/statuses/friends", TwitterAPI.Controller, :friends
166 get "/statuses/show/:id", TwitterAPI.Controller, :fetch_status
167 get "/statusnet/conversation/:id", TwitterAPI.Controller, :fetch_conversation
168
169 if @registrations_open do
170 post "/account/register", TwitterAPI.Controller, :register
171 end
172
173 get "/search", TwitterAPI.Controller, :search
174 get "/statusnet/tags/timeline/:tag", TwitterAPI.Controller, :public_and_external_timeline
175 end
176
177 scope "/api", Pleroma.Web do
178 pipe_through :authenticated_api
179
180 get "/account/verify_credentials", TwitterAPI.Controller, :verify_credentials
181 post "/account/verify_credentials", TwitterAPI.Controller, :verify_credentials
182
183 post "/account/update_profile", TwitterAPI.Controller, :update_profile
184 post "/account/update_profile_banner", TwitterAPI.Controller, :update_banner
185 post "/qvitter/update_background_image", TwitterAPI.Controller, :update_background
186
187 post "/account/most_recent_notification", TwitterAPI.Controller, :update_most_recent_notification
188
189 get "/statuses/home_timeline", TwitterAPI.Controller, :friends_timeline
190 get "/statuses/friends_timeline", TwitterAPI.Controller, :friends_timeline
191 get "/statuses/mentions", TwitterAPI.Controller, :mentions_timeline
192 get "/statuses/mentions_timeline", TwitterAPI.Controller, :mentions_timeline
193
194 post "/statuses/update", TwitterAPI.Controller, :status_update
195 post "/statuses/retweet/:id", TwitterAPI.Controller, :retweet
196 post "/statuses/destroy/:id", TwitterAPI.Controller, :delete_post
197
198 post "/friendships/create", TwitterAPI.Controller, :follow
199 post "/friendships/destroy", TwitterAPI.Controller, :unfollow
200 post "/blocks/create", TwitterAPI.Controller, :block
201 post "/blocks/destroy", TwitterAPI.Controller, :unblock
202
203 post "/statusnet/media/upload", TwitterAPI.Controller, :upload
204 post "/media/upload", TwitterAPI.Controller, :upload_json
205
206 post "/favorites/create/:id", TwitterAPI.Controller, :favorite
207 post "/favorites/create", TwitterAPI.Controller, :favorite
208 post "/favorites/destroy/:id", TwitterAPI.Controller, :unfavorite
209
210 post "/qvitter/update_avatar", TwitterAPI.Controller, :update_avatar
211
212 get "/friends/ids", TwitterAPI.Controller, :friends_ids
213 get "/friendships/no_retweets/ids", TwitterAPI.Controller, :empty_array
214
215 get "/mutes/users/ids", TwitterAPI.Controller, :empty_array
216
217 get "/externalprofile/show", TwitterAPI.Controller, :external_profile
218 end
219
220 pipeline :ostatus do
221 plug :accepts, ["xml", "atom", "html"]
222 end
223
224 scope "/", Pleroma.Web do
225 pipe_through :ostatus
226
227 get "/objects/:uuid", OStatus.OStatusController, :object
228 get "/activities/:uuid", OStatus.OStatusController, :activity
229 get "/notice/:id", OStatus.OStatusController, :notice
230
231 get "/users/:nickname/feed", OStatus.OStatusController, :feed
232 get "/users/:nickname", OStatus.OStatusController, :feed_redirect
233 post "/users/:nickname/salmon", OStatus.OStatusController, :salmon_incoming
234 post "/push/hub/:nickname", Websub.WebsubController, :websub_subscription_request
235 get "/push/subscriptions/:id", Websub.WebsubController, :websub_subscription_confirmation
236 post "/push/subscriptions/:id", Websub.WebsubController, :websub_incoming
237 end
238
239 scope "/.well-known", Pleroma.Web do
240 pipe_through :well_known
241
242 get "/host-meta", WebFinger.WebFingerController, :host_meta
243 get "/webfinger", WebFinger.WebFingerController, :webfinger
244 end
245
246 scope "/", Pleroma.Web.MastodonAPI do
247 pipe_through :mastodon_html
248
249 get "/web/login", MastodonAPIController, :login
250 post "/web/login", MastodonAPIController, :login_post
251 get "/web/*path", MastodonAPIController, :index
252 delete "/auth/sign_out", MastodonAPIController, :logout
253 end
254
255 pipeline :remote_media do
256 plug :accepts, ["html"]
257 end
258 scope "/proxy/", Pleroma.Web.MediaProxy do
259 pipe_through :remote_media
260 get "/:sig/:url", MediaProxyController, :remote
261 end
262
263 scope "/", Fallback do
264 get "/*path", RedirectController, :redirector
265 end
266 end
267
268 defmodule Fallback.RedirectController do
269 use Pleroma.Web, :controller
270 def redirector(conn, _params) do
271 if Mix.env != :test do
272 conn
273 |> put_resp_content_type("text/html")
274 |> send_file(200, "priv/static/index.html")
275 end
276 end
277 end