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