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