6081016d68de1f4da0e7d05d809125b18f4a6852
[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.AuthenticationPlug, %{fetcher: &Router.user_fetcher/1, optional: true}
14 end
15
16 pipeline :authenticated_api do
17 plug :accepts, ["json"]
18 plug :fetch_session
19 plug Pleroma.Plugs.OAuthPlug
20 plug Pleroma.Plugs.AuthenticationPlug, %{fetcher: &Router.user_fetcher/1}
21 end
22
23 pipeline :well_known do
24 plug :accepts, ["xml", "xrd+xml"]
25 end
26
27 pipeline :config do
28 plug :accepts, ["json", "xml"]
29 end
30
31 pipeline :masto_config do
32 plug :accepts, ["json"]
33 end
34
35 pipeline :oauth do
36 plug :accepts, ["html", "json"]
37 end
38
39 scope "/oauth", Pleroma.Web.OAuth do
40 get "/authorize", OAuthController, :authorize
41 post "/authorize", OAuthController, :create_authorization
42 post "/token", OAuthController, :token_exchange
43 end
44
45 scope "/api/v1", Pleroma.Web do
46 pipe_through :masto_config
47 # TODO: Move this
48 get "/instance", TwitterAPI.UtilController, :masto_instance
49 post "/apps", MastodonAPI.MastodonAPIController, :create_app
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 end
57
58 scope "/api", Pleroma.Web do
59 pipe_through :config
60
61 get "/help/test", TwitterAPI.UtilController, :help_test
62 post "/help/test", TwitterAPI.UtilController, :help_test
63 get "/statusnet/config", TwitterAPI.UtilController, :config
64 get "/statusnet/version", TwitterAPI.UtilController, :version
65 end
66
67 scope "/api", Pleroma.Web do
68 pipe_through :api
69
70 get "/statuses/public_timeline", TwitterAPI.Controller, :public_timeline
71 get "/statuses/public_and_external_timeline", TwitterAPI.Controller, :public_and_external_timeline
72 get "/statuses/networkpublic_timeline", TwitterAPI.Controller, :public_and_external_timeline
73 get "/statuses/user_timeline", TwitterAPI.Controller, :user_timeline
74 get "/qvitter/statuses/user_timeline", TwitterAPI.Controller, :user_timeline
75
76 get "/statuses/show/:id", TwitterAPI.Controller, :fetch_status
77 get "/statusnet/conversation/:id", TwitterAPI.Controller, :fetch_conversation
78
79 post "/account/register", TwitterAPI.Controller, :register
80
81 get "/externalprofile/show", TwitterAPI.Controller, :external_profile
82 end
83
84 scope "/api", Pleroma.Web do
85 pipe_through :authenticated_api
86
87 get "/account/verify_credentials", TwitterAPI.Controller, :verify_credentials
88 post "/account/verify_credentials", TwitterAPI.Controller, :verify_credentials
89
90 post "/account/update_profile", TwitterAPI.Controller, :update_profile
91 post "/account/update_profile_banner", TwitterAPI.Controller, :update_banner
92 post "/qvitter/update_background_image", TwitterAPI.Controller, :update_background
93
94 post "/account/most_recent_notification", TwitterAPI.Controller, :update_most_recent_notification
95
96 get "/statuses/home_timeline", TwitterAPI.Controller, :friends_timeline
97 get "/statuses/friends_timeline", TwitterAPI.Controller, :friends_timeline
98 get "/statuses/mentions", TwitterAPI.Controller, :mentions_timeline
99 get "/statuses/mentions_timeline", TwitterAPI.Controller, :mentions_timeline
100
101 post "/statuses/update", TwitterAPI.Controller, :status_update
102 post "/statuses/retweet/:id", TwitterAPI.Controller, :retweet
103 post "/statuses/destroy/:id", TwitterAPI.Controller, :delete_post
104
105 post "/friendships/create", TwitterAPI.Controller, :follow
106 post "/friendships/destroy", TwitterAPI.Controller, :unfollow
107
108 post "/statusnet/media/upload", TwitterAPI.Controller, :upload
109 post "/media/upload", TwitterAPI.Controller, :upload_json
110
111 post "/favorites/create/:id", TwitterAPI.Controller, :favorite
112 post "/favorites/create", TwitterAPI.Controller, :favorite
113 post "/favorites/destroy/:id", TwitterAPI.Controller, :unfavorite
114
115 post "/qvitter/update_avatar", TwitterAPI.Controller, :update_avatar
116
117 get "/statuses/followers", TwitterAPI.Controller, :followers
118 get "/statuses/friends", TwitterAPI.Controller, :friends
119 end
120
121 pipeline :ostatus do
122 plug :accepts, ["xml", "atom", "html"]
123 end
124
125 scope "/", Pleroma.Web do
126 pipe_through :ostatus
127
128 get "/objects/:uuid", OStatus.OStatusController, :object
129 get "/activities/:uuid", OStatus.OStatusController, :activity
130
131 get "/users/:nickname/feed", OStatus.OStatusController, :feed
132 get "/users/:nickname", OStatus.OStatusController, :feed_redirect
133 post "/users/:nickname/salmon", OStatus.OStatusController, :salmon_incoming
134 post "/push/hub/:nickname", Websub.WebsubController, :websub_subscription_request
135 get "/push/subscriptions/:id", Websub.WebsubController, :websub_subscription_confirmation
136 post "/push/subscriptions/:id", Websub.WebsubController, :websub_incoming
137 end
138
139 scope "/.well-known", Pleroma.Web do
140 pipe_through :well_known
141
142 get "/host-meta", WebFinger.WebFingerController, :host_meta
143 get "/webfinger", WebFinger.WebFingerController, :webfinger
144 end
145
146 scope "/", Fallback do
147 get "/*path", RedirectController, :redirector
148 end
149 end
150
151 defmodule Fallback.RedirectController do
152 use Pleroma.Web, :controller
153 def redirector(conn, _params) do
154 if Mix.env != :test do
155 conn
156 |> put_resp_content_type("text/html")
157 |> send_file(200, "priv/static/index.html")
158 end
159 end
160 end