router.ex 8.11 KB
Newer Older
lain's avatar
lain committed
1
2
3
defmodule Pleroma.Web.Router do
  use Pleroma.Web, :router

4
  alias Pleroma.{Repo, User, Web.Router}
5
6
7
8
9

  def user_fetcher(username) do
    {:ok, Repo.get_by(User, %{nickname: username})}
  end

lain's avatar
lain committed
10
11
  pipeline :api do
    plug :accepts, ["json"]
lain's avatar
lain committed
12
    plug :fetch_session
lain's avatar
lain committed
13
    plug Pleroma.Plugs.OAuthPlug
14
    plug Pleroma.Plugs.AuthenticationPlug, %{fetcher: &Router.user_fetcher/1, optional: true}
lain's avatar
lain committed
15
16
  end

17
18
19
  pipeline :authenticated_api do
    plug :accepts, ["json"]
    plug :fetch_session
20
    plug Pleroma.Plugs.OAuthPlug
21
    plug Pleroma.Plugs.AuthenticationPlug, %{fetcher: &Router.user_fetcher/1}
lain's avatar
lain committed
22
23
  end

lain's avatar
lain committed
24
25
26
27
  pipeline :well_known do
    plug :accepts, ["xml", "xrd+xml"]
  end

lain's avatar
lain committed
28
29
30
31
  pipeline :config do
    plug :accepts, ["json", "xml"]
  end

32
33
34
35
  pipeline :oauth do
    plug :accepts, ["html", "json"]
  end

eal's avatar
eal committed
36
37
  pipeline :pleroma_api do
    plug :accepts, ["html", "json"]
Roger Braun's avatar
Roger Braun committed
38
39
40
  end

  scope "/api/pleroma", Pleroma.Web.TwitterAPI do
eal's avatar
eal committed
41
    pipe_through :pleroma_api
Roger Braun's avatar
Roger Braun committed
42
43
    get "/password_reset/:token", UtilController, :show_password_reset
    post "/password_reset", UtilController, :password_reset
eal's avatar
eal committed
44
    get "/emoji", UtilController, :emoji
Roger Braun's avatar
Roger Braun committed
45
46
  end

47
48
49
50
51
52
53
54
55
56
  scope "/oauth", Pleroma.Web.OAuth do
    get "/authorize", OAuthController, :authorize
    post "/authorize", OAuthController, :create_authorization
    post "/token", OAuthController, :token_exchange
  end

  scope "/api/v1", Pleroma.Web.MastodonAPI do
    pipe_through :authenticated_api

    get "/accounts/verify_credentials", MastodonAPIController, :verify_credentials
Roger Braun's avatar
Roger Braun committed
57
    get "/accounts/relationships", MastodonAPIController, :relationships
lain's avatar
lain committed
58
    get "/accounts/search", MastodonAPIController, :account_search
59
60
    post "/accounts/:id/follow", MastodonAPIController, :follow
    post "/accounts/:id/unfollow", MastodonAPIController, :unfollow
lain's avatar
lain committed
61
62
    post "/accounts/:id/block", MastodonAPIController, :block
    post "/accounts/:id/unblock", MastodonAPIController, :unblock
63
64
65
    post "/accounts/:id/mute", MastodonAPIController, :relationship_noop
    post "/accounts/:id/unmute", MastodonAPIController, :relationship_noop

eal's avatar
eal committed
66
67
    post "/follows", MastodonAPIController, :follow

lain's avatar
lain committed
68
69
    get "/blocks", MastodonAPIController, :blocks

70
71
72
    get "/domain_blocks", MastodonAPIController, :empty_array
    get "/follow_requests", MastodonAPIController, :empty_array
    get "/mutes", MastodonAPIController, :empty_array
Roger Braun's avatar
Roger Braun committed
73

lain's avatar
lain committed
74
75
    get "/timelines/home", MastodonAPIController, :home_timeline

76
77
    get "/favourites", MastodonAPIController, :favourites

lain's avatar
lain committed
78
    post "/statuses", MastodonAPIController, :post_status
lain's avatar
lain committed
79
    delete "/statuses/:id", MastodonAPIController, :delete_status
lain's avatar
lain committed
80
81

    post "/statuses/:id/reblog", MastodonAPIController, :reblog_status
lain's avatar
lain committed
82
    post "/statuses/:id/favourite", MastodonAPIController, :fav_status
lain's avatar
lain committed
83
    post "/statuses/:id/unfavourite", MastodonAPIController, :unfav_status
84

85
    get "/notifications", MastodonAPIController, :notifications
lain's avatar
lain committed
86
87

    post "/media", MastodonAPIController, :upload
lain's avatar
lain committed
88
89
  end

Roger Braun's avatar
Roger Braun committed
90
91
92
93
94
95
  scope "/api/v1", Pleroma.Web.MastodonAPI do
    pipe_through :api
    get "/instance", MastodonAPIController, :masto_instance
    post "/apps", MastodonAPIController, :create_app

    get "/timelines/public", MastodonAPIController, :public_timeline
Roger Braun's avatar
Roger Braun committed
96
    get "/timelines/tag/:tag", MastodonAPIController, :hashtag_timeline
Roger Braun's avatar
Roger Braun committed
97
98
99

    get "/statuses/:id", MastodonAPIController, :get_status
    get "/statuses/:id/context", MastodonAPIController, :get_context
100
101
    get "/statuses/:id/favourited_by", MastodonAPIController, :favourited_by
    get "/statuses/:id/reblogged_by", MastodonAPIController, :reblogged_by
Roger Braun's avatar
Roger Braun committed
102
103

    get "/accounts/:id/statuses", MastodonAPIController, :user_statuses
104
105
    get "/accounts/:id/followers", MastodonAPIController, :followers
    get "/accounts/:id/following", MastodonAPIController, :following
Roger Braun's avatar
Roger Braun committed
106
    get "/accounts/:id", MastodonAPIController, :user
lain's avatar
lain committed
107
108

    get "/search", MastodonAPIController, :search
Roger Braun's avatar
Roger Braun committed
109
110
  end

lain's avatar
lain committed
111
  scope "/api", Pleroma.Web do
lain's avatar
lain committed
112
    pipe_through :config
dtluna's avatar
dtluna committed
113

dtluna's avatar
dtluna committed
114
    get "/help/test", TwitterAPI.UtilController, :help_test
lain's avatar
lain committed
115
    post "/help/test", TwitterAPI.UtilController, :help_test
dtluna's avatar
dtluna committed
116
    get "/statusnet/config", TwitterAPI.UtilController, :config
lain's avatar
lain committed
117
118
119
    get "/statusnet/version", TwitterAPI.UtilController, :version
  end

120
121
122
  @instance Application.get_env(:pleroma, :instance)
  @registrations_open Keyword.get(@instance, :registrations_open)

lain's avatar
lain committed
123
124
  scope "/api", Pleroma.Web do
    pipe_through :api
dtluna's avatar
dtluna committed
125

lain's avatar
lain committed
126
    get "/statuses/public_timeline", TwitterAPI.Controller, :public_timeline
lain's avatar
lain committed
127
    get "/statuses/public_and_external_timeline", TwitterAPI.Controller, :public_and_external_timeline
lain's avatar
lain committed
128
    get "/statuses/networkpublic_timeline", TwitterAPI.Controller, :public_and_external_timeline
129
    get "/statuses/user_timeline", TwitterAPI.Controller, :user_timeline
lain's avatar
lain committed
130
    get "/qvitter/statuses/user_timeline", TwitterAPI.Controller, :user_timeline
dtluna's avatar
dtluna committed
131

lain's avatar
lain committed
132
    get "/statuses/show/:id", TwitterAPI.Controller, :fetch_status
133
    get "/statusnet/conversation/:id", TwitterAPI.Controller, :fetch_conversation
dtluna's avatar
dtluna committed
134

135
136
137
    if @registrations_open do
      post "/account/register", TwitterAPI.Controller, :register
    end
lain's avatar
lain committed
138

lain's avatar
lain committed
139
    get "/search", TwitterAPI.Controller, :search
140
    get "/statusnet/tags/timeline/:tag", TwitterAPI.Controller, :public_and_external_timeline
lain's avatar
lain committed
141
    get "/externalprofile/show", TwitterAPI.Controller, :external_profile
142
143
  end

lain's avatar
lain committed
144
  scope "/api", Pleroma.Web do
145
146
    pipe_through :authenticated_api

dtluna's avatar
dtluna committed
147
    get "/account/verify_credentials", TwitterAPI.Controller, :verify_credentials
lain's avatar
lain committed
148
    post "/account/verify_credentials", TwitterAPI.Controller, :verify_credentials
dtluna's avatar
dtluna committed
149

lain's avatar
lain committed
150
    post "/account/update_profile", TwitterAPI.Controller, :update_profile
lain's avatar
lain committed
151
152
    post "/account/update_profile_banner", TwitterAPI.Controller, :update_banner
    post "/qvitter/update_background_image", TwitterAPI.Controller, :update_background
lain's avatar
lain committed
153

154
155
    post "/account/most_recent_notification", TwitterAPI.Controller, :update_most_recent_notification

dtluna's avatar
dtluna committed
156
    get "/statuses/home_timeline", TwitterAPI.Controller, :friends_timeline
lain's avatar
lain committed
157
    get "/statuses/friends_timeline", TwitterAPI.Controller, :friends_timeline
dtluna's avatar
dtluna committed
158
    get "/statuses/mentions", TwitterAPI.Controller, :mentions_timeline
dtluna's avatar
dtluna committed
159
    get "/statuses/mentions_timeline", TwitterAPI.Controller, :mentions_timeline
dtluna's avatar
dtluna committed
160
161
162

    post "/statuses/update", TwitterAPI.Controller, :status_update
    post "/statuses/retweet/:id", TwitterAPI.Controller, :retweet
lain's avatar
lain committed
163
    post "/statuses/destroy/:id", TwitterAPI.Controller, :delete_post
dtluna's avatar
dtluna committed
164

lain's avatar
lain committed
165
166
    post "/friendships/create", TwitterAPI.Controller, :follow
    post "/friendships/destroy", TwitterAPI.Controller, :unfollow
dtluna's avatar
dtluna committed
167

lain's avatar
lain committed
168
    post "/statusnet/media/upload", TwitterAPI.Controller, :upload
169
    post "/media/upload", TwitterAPI.Controller, :upload_json
dtluna's avatar
dtluna committed
170

lain's avatar
lain committed
171
    post "/favorites/create/:id", TwitterAPI.Controller, :favorite
172
    post "/favorites/create", TwitterAPI.Controller, :favorite
lain's avatar
lain committed
173
    post "/favorites/destroy/:id", TwitterAPI.Controller, :unfavorite
dtluna's avatar
dtluna committed
174

lain's avatar
lain committed
175
    post "/qvitter/update_avatar", TwitterAPI.Controller, :update_avatar
lain's avatar
lain committed
176
177

    get "/statuses/followers", TwitterAPI.Controller, :followers
lain's avatar
lain committed
178
    get "/statuses/friends", TwitterAPI.Controller, :friends
lain's avatar
lain committed
179
  end
lain's avatar
lain committed
180

lain's avatar
lain committed
181
  pipeline :ostatus do
182
    plug :accepts, ["xml", "atom", "html"]
lain's avatar
lain committed
183
184
  end

lain's avatar
lain committed
185
  scope "/", Pleroma.Web do
lain's avatar
lain committed
186
187
    pipe_through :ostatus

188
    get "/objects/:uuid", OStatus.OStatusController, :object
lain's avatar
lain committed
189
    get "/activities/:uuid", OStatus.OStatusController, :activity
190

lain's avatar
lain committed
191
    get "/users/:nickname/feed", OStatus.OStatusController, :feed
192
    get "/users/:nickname", OStatus.OStatusController, :feed_redirect
193
    post "/users/:nickname/salmon", OStatus.OStatusController, :salmon_incoming
lain's avatar
lain committed
194
    post "/push/hub/:nickname", Websub.WebsubController, :websub_subscription_request
lain's avatar
lain committed
195
196
    get "/push/subscriptions/:id", Websub.WebsubController, :websub_subscription_confirmation
    post "/push/subscriptions/:id", Websub.WebsubController, :websub_incoming
lain's avatar
lain committed
197
198
  end

lain's avatar
lain committed
199
200
201
202
203
204
  scope "/.well-known", Pleroma.Web do
    pipe_through :well_known

    get "/host-meta", WebFinger.WebFingerController, :host_meta
    get "/webfinger", WebFinger.WebFingerController, :webfinger
  end
lain's avatar
lain committed
205
206
207
208
209
210
211
212

  scope "/", Fallback do
    get "/*path", RedirectController, :redirector
  end
end

defmodule Fallback.RedirectController do
  use Pleroma.Web, :controller
lain's avatar
lain committed
213
214
215
216
217
218
219
  def redirector(conn, _params) do
    if Mix.env != :test do
      conn
      |> put_resp_content_type("text/html")
      |> send_file(200, "priv/static/index.html")
    end
  end
lain's avatar
lain committed
220
end