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