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