Add basic search.
[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
91 get "/search", MastodonAPIController, :search
92 end
93
94 scope "/api", Pleroma.Web do
95 pipe_through :config
96
97 get "/help/test", TwitterAPI.UtilController, :help_test
98 post "/help/test", TwitterAPI.UtilController, :help_test
99 get "/statusnet/config", TwitterAPI.UtilController, :config
100 get "/statusnet/version", TwitterAPI.UtilController, :version
101 end
102
103 @instance Application.get_env(:pleroma, :instance)
104 @registrations_open Keyword.get(@instance, :registrations_open)
105
106 scope "/api", Pleroma.Web do
107 pipe_through :api
108
109 get "/statuses/public_timeline", TwitterAPI.Controller, :public_timeline
110 get "/statuses/public_and_external_timeline", TwitterAPI.Controller, :public_and_external_timeline
111 get "/statuses/networkpublic_timeline", TwitterAPI.Controller, :public_and_external_timeline
112 get "/statuses/user_timeline", TwitterAPI.Controller, :user_timeline
113 get "/qvitter/statuses/user_timeline", TwitterAPI.Controller, :user_timeline
114
115 get "/statuses/show/:id", TwitterAPI.Controller, :fetch_status
116 get "/statusnet/conversation/:id", TwitterAPI.Controller, :fetch_conversation
117
118 if @registrations_open do
119 post "/account/register", TwitterAPI.Controller, :register
120 end
121
122 get "/externalprofile/show", TwitterAPI.Controller, :external_profile
123 end
124
125 scope "/api", Pleroma.Web do
126 pipe_through :authenticated_api
127
128 get "/account/verify_credentials", TwitterAPI.Controller, :verify_credentials
129 post "/account/verify_credentials", TwitterAPI.Controller, :verify_credentials
130
131 post "/account/update_profile", TwitterAPI.Controller, :update_profile
132 post "/account/update_profile_banner", TwitterAPI.Controller, :update_banner
133 post "/qvitter/update_background_image", TwitterAPI.Controller, :update_background
134
135 post "/account/most_recent_notification", TwitterAPI.Controller, :update_most_recent_notification
136
137 get "/statuses/home_timeline", TwitterAPI.Controller, :friends_timeline
138 get "/statuses/friends_timeline", TwitterAPI.Controller, :friends_timeline
139 get "/statuses/mentions", TwitterAPI.Controller, :mentions_timeline
140 get "/statuses/mentions_timeline", TwitterAPI.Controller, :mentions_timeline
141
142 post "/statuses/update", TwitterAPI.Controller, :status_update
143 post "/statuses/retweet/:id", TwitterAPI.Controller, :retweet
144 post "/statuses/destroy/:id", TwitterAPI.Controller, :delete_post
145
146 post "/friendships/create", TwitterAPI.Controller, :follow
147 post "/friendships/destroy", TwitterAPI.Controller, :unfollow
148
149 post "/statusnet/media/upload", TwitterAPI.Controller, :upload
150 post "/media/upload", TwitterAPI.Controller, :upload_json
151
152 post "/favorites/create/:id", TwitterAPI.Controller, :favorite
153 post "/favorites/create", TwitterAPI.Controller, :favorite
154 post "/favorites/destroy/:id", TwitterAPI.Controller, :unfavorite
155
156 post "/qvitter/update_avatar", TwitterAPI.Controller, :update_avatar
157
158 get "/statuses/followers", TwitterAPI.Controller, :followers
159 get "/statuses/friends", TwitterAPI.Controller, :friends
160 end
161
162 pipeline :ostatus do
163 plug :accepts, ["xml", "atom", "html"]
164 end
165
166 scope "/", Pleroma.Web do
167 pipe_through :ostatus
168
169 get "/objects/:uuid", OStatus.OStatusController, :object
170 get "/activities/:uuid", OStatus.OStatusController, :activity
171
172 get "/users/:nickname/feed", OStatus.OStatusController, :feed
173 get "/users/:nickname", OStatus.OStatusController, :feed_redirect
174 post "/users/:nickname/salmon", OStatus.OStatusController, :salmon_incoming
175 post "/push/hub/:nickname", Websub.WebsubController, :websub_subscription_request
176 get "/push/subscriptions/:id", Websub.WebsubController, :websub_subscription_confirmation
177 post "/push/subscriptions/:id", Websub.WebsubController, :websub_incoming
178 end
179
180 scope "/.well-known", Pleroma.Web do
181 pipe_through :well_known
182
183 get "/host-meta", WebFinger.WebFingerController, :host_meta
184 get "/webfinger", WebFinger.WebFingerController, :webfinger
185 end
186
187 scope "/", Fallback do
188 get "/*path", RedirectController, :redirector
189 end
190 end
191
192 defmodule Fallback.RedirectController do
193 use Pleroma.Web, :controller
194 def redirector(conn, _params) do
195 if Mix.env != :test do
196 conn
197 |> put_resp_content_type("text/html")
198 |> send_file(200, "priv/static/index.html")
199 end
200 end
201 end