Merge branch 'oauth2' into 'develop'
[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 :api
44 get "/instance", MastodonAPIController, :masto_instance
45 post "/apps", MastodonAPIController, :create_app
46
47 get "/timelines/public", MastodonAPIController, :public_timeline
48
49 get "/statuses/:id", MastodonAPIController, :get_status
50 get "/statuses/:id/context", MastodonAPIController, :get_context
51
52 get "/accounts/:id/statuses", MastodonAPIController, :user_statuses
53 end
54
55 scope "/api/v1", Pleroma.Web.MastodonAPI do
56 pipe_through :authenticated_api
57
58 get "/accounts/verify_credentials", MastodonAPIController, :verify_credentials
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 end
70
71 scope "/api", Pleroma.Web do
72 pipe_through :config
73
74 get "/help/test", TwitterAPI.UtilController, :help_test
75 post "/help/test", TwitterAPI.UtilController, :help_test
76 get "/statusnet/config", TwitterAPI.UtilController, :config
77 get "/statusnet/version", TwitterAPI.UtilController, :version
78 end
79
80 scope "/api", Pleroma.Web do
81 pipe_through :api
82
83 get "/statuses/public_timeline", TwitterAPI.Controller, :public_timeline
84 get "/statuses/public_and_external_timeline", TwitterAPI.Controller, :public_and_external_timeline
85 get "/statuses/networkpublic_timeline", TwitterAPI.Controller, :public_and_external_timeline
86 get "/statuses/user_timeline", TwitterAPI.Controller, :user_timeline
87 get "/qvitter/statuses/user_timeline", TwitterAPI.Controller, :user_timeline
88
89 get "/statuses/show/:id", TwitterAPI.Controller, :fetch_status
90 get "/statusnet/conversation/:id", TwitterAPI.Controller, :fetch_conversation
91
92 post "/account/register", TwitterAPI.Controller, :register
93
94 get "/externalprofile/show", TwitterAPI.Controller, :external_profile
95 end
96
97 scope "/api", Pleroma.Web do
98 pipe_through :authenticated_api
99
100 get "/account/verify_credentials", TwitterAPI.Controller, :verify_credentials
101 post "/account/verify_credentials", TwitterAPI.Controller, :verify_credentials
102
103 post "/account/update_profile", TwitterAPI.Controller, :update_profile
104 post "/account/update_profile_banner", TwitterAPI.Controller, :update_banner
105 post "/qvitter/update_background_image", TwitterAPI.Controller, :update_background
106
107 post "/account/most_recent_notification", TwitterAPI.Controller, :update_most_recent_notification
108
109 get "/statuses/home_timeline", TwitterAPI.Controller, :friends_timeline
110 get "/statuses/friends_timeline", TwitterAPI.Controller, :friends_timeline
111 get "/statuses/mentions", TwitterAPI.Controller, :mentions_timeline
112 get "/statuses/mentions_timeline", TwitterAPI.Controller, :mentions_timeline
113
114 post "/statuses/update", TwitterAPI.Controller, :status_update
115 post "/statuses/retweet/:id", TwitterAPI.Controller, :retweet
116 post "/statuses/destroy/:id", TwitterAPI.Controller, :delete_post
117
118 post "/friendships/create", TwitterAPI.Controller, :follow
119 post "/friendships/destroy", TwitterAPI.Controller, :unfollow
120
121 post "/statusnet/media/upload", TwitterAPI.Controller, :upload
122 post "/media/upload", TwitterAPI.Controller, :upload_json
123
124 post "/favorites/create/:id", TwitterAPI.Controller, :favorite
125 post "/favorites/create", TwitterAPI.Controller, :favorite
126 post "/favorites/destroy/:id", TwitterAPI.Controller, :unfavorite
127
128 post "/qvitter/update_avatar", TwitterAPI.Controller, :update_avatar
129
130 get "/statuses/followers", TwitterAPI.Controller, :followers
131 get "/statuses/friends", TwitterAPI.Controller, :friends
132 end
133
134 pipeline :ostatus do
135 plug :accepts, ["xml", "atom", "html"]
136 end
137
138 scope "/", Pleroma.Web do
139 pipe_through :ostatus
140
141 get "/objects/:uuid", OStatus.OStatusController, :object
142 get "/activities/:uuid", OStatus.OStatusController, :activity
143
144 get "/users/:nickname/feed", OStatus.OStatusController, :feed
145 get "/users/:nickname", OStatus.OStatusController, :feed_redirect
146 post "/users/:nickname/salmon", OStatus.OStatusController, :salmon_incoming
147 post "/push/hub/:nickname", Websub.WebsubController, :websub_subscription_request
148 get "/push/subscriptions/:id", Websub.WebsubController, :websub_subscription_confirmation
149 post "/push/subscriptions/:id", Websub.WebsubController, :websub_incoming
150 end
151
152 scope "/.well-known", Pleroma.Web do
153 pipe_through :well_known
154
155 get "/host-meta", WebFinger.WebFingerController, :host_meta
156 get "/webfinger", WebFinger.WebFingerController, :webfinger
157 end
158
159 scope "/", Fallback do
160 get "/*path", RedirectController, :redirector
161 end
162 end
163
164 defmodule Fallback.RedirectController do
165 use Pleroma.Web, :controller
166 def redirector(conn, _params) do
167 if Mix.env != :test do
168 conn
169 |> put_resp_content_type("text/html")
170 |> send_file(200, "priv/static/index.html")
171 end
172 end
173 end