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