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