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