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