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