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