router.ex 6.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 36 37 38 39 40 41
  pipeline :oauth do
    plug :accepts, ["html", "json"]
  end

  scope "/oauth", Pleroma.Web.OAuth do
    get "/authorize", OAuthController, :authorize
    post "/authorize", OAuthController, :create_authorization
    post "/token", OAuthController, :token_exchange
  end

lain's avatar
lain committed
42 43
  scope "/api/v1", Pleroma.Web.MastodonAPI do
    pipe_through :api
lain's avatar
lain committed
44
    get "/instance", MastodonAPIController, :masto_instance
lain's avatar
lain committed
45
    post "/apps", MastodonAPIController, :create_app
lain's avatar
lain committed
46 47 48 49

    get "/timelines/public", MastodonAPIController, :public_timeline

    get "/statuses/:id", MastodonAPIController, :get_status
lain's avatar
lain committed
50
    get "/statuses/:id/context", MastodonAPIController, :get_context
lain's avatar
lain committed
51 52

    get "/accounts/:id/statuses", MastodonAPIController, :user_statuses
53 54 55 56 57 58
  end

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

    get "/accounts/verify_credentials", MastodonAPIController, :verify_credentials
lain's avatar
lain committed
59 60 61
    get "/timelines/home", MastodonAPIController, :home_timeline

    post "/statuses", MastodonAPIController, :post_status
lain's avatar
lain committed
62
    delete "/statuses/:id", MastodonAPIController, :delete_status
lain's avatar
lain committed
63 64

    post "/statuses/:id/reblog", MastodonAPIController, :reblog_status
lain's avatar
lain committed
65
    post "/statuses/:id/favourite", MastodonAPIController, :fav_status
lain's avatar
lain committed
66
    post "/statuses/:id/unfavourite", MastodonAPIController, :unfav_status
67

68
    get "/notifications", MastodonAPIController, :notifications
lain's avatar
lain committed
69 70
  end

lain's avatar
lain committed
71
  scope "/api", Pleroma.Web do
lain's avatar
lain committed
72
    pipe_through :config
dtluna's avatar
dtluna committed
73

dtluna's avatar
dtluna committed
74
    get "/help/test", TwitterAPI.UtilController, :help_test
lain's avatar
lain committed
75
    post "/help/test", TwitterAPI.UtilController, :help_test
dtluna's avatar
dtluna committed
76
    get "/statusnet/config", TwitterAPI.UtilController, :config
lain's avatar
lain committed
77 78 79 80 81
    get "/statusnet/version", TwitterAPI.UtilController, :version
  end

  scope "/api", Pleroma.Web do
    pipe_through :api
dtluna's avatar
dtluna committed
82

lain's avatar
lain committed
83
    get "/statuses/public_timeline", TwitterAPI.Controller, :public_timeline
lain's avatar
lain committed
84
    get "/statuses/public_and_external_timeline", TwitterAPI.Controller, :public_and_external_timeline
lain's avatar
lain committed
85
    get "/statuses/networkpublic_timeline", TwitterAPI.Controller, :public_and_external_timeline
86
    get "/statuses/user_timeline", TwitterAPI.Controller, :user_timeline
lain's avatar
lain committed
87
    get "/qvitter/statuses/user_timeline", TwitterAPI.Controller, :user_timeline
dtluna's avatar
dtluna committed
88

lain's avatar
lain committed
89
    get "/statuses/show/:id", TwitterAPI.Controller, :fetch_status
90
    get "/statusnet/conversation/:id", TwitterAPI.Controller, :fetch_conversation
dtluna's avatar
dtluna committed
91

92
    post "/account/register", TwitterAPI.Controller, :register
lain's avatar
lain committed
93 94

    get "/externalprofile/show", TwitterAPI.Controller, :external_profile
95 96
  end

lain's avatar
lain committed
97
  scope "/api", Pleroma.Web do
98 99
    pipe_through :authenticated_api

dtluna's avatar
dtluna committed
100
    get "/account/verify_credentials", TwitterAPI.Controller, :verify_credentials
lain's avatar
lain committed
101
    post "/account/verify_credentials", TwitterAPI.Controller, :verify_credentials
dtluna's avatar
dtluna committed
102

lain's avatar
lain committed
103
    post "/account/update_profile", TwitterAPI.Controller, :update_profile
lain's avatar
lain committed
104 105
    post "/account/update_profile_banner", TwitterAPI.Controller, :update_banner
    post "/qvitter/update_background_image", TwitterAPI.Controller, :update_background
lain's avatar
lain committed
106

107 108
    post "/account/most_recent_notification", TwitterAPI.Controller, :update_most_recent_notification

dtluna's avatar
dtluna committed
109
    get "/statuses/home_timeline", TwitterAPI.Controller, :friends_timeline
lain's avatar
lain committed
110
    get "/statuses/friends_timeline", TwitterAPI.Controller, :friends_timeline
dtluna's avatar
dtluna committed
111
    get "/statuses/mentions", TwitterAPI.Controller, :mentions_timeline
dtluna's avatar
dtluna committed
112
    get "/statuses/mentions_timeline", TwitterAPI.Controller, :mentions_timeline
dtluna's avatar
dtluna committed
113 114 115

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

lain's avatar
lain committed
118 119
    post "/friendships/create", TwitterAPI.Controller, :follow
    post "/friendships/destroy", TwitterAPI.Controller, :unfollow
dtluna's avatar
dtluna committed
120

lain's avatar
lain committed
121
    post "/statusnet/media/upload", TwitterAPI.Controller, :upload
122
    post "/media/upload", TwitterAPI.Controller, :upload_json
dtluna's avatar
dtluna committed
123

lain's avatar
lain committed
124
    post "/favorites/create/:id", TwitterAPI.Controller, :favorite
125
    post "/favorites/create", TwitterAPI.Controller, :favorite
lain's avatar
lain committed
126
    post "/favorites/destroy/:id", TwitterAPI.Controller, :unfavorite
dtluna's avatar
dtluna committed
127

lain's avatar
lain committed
128
    post "/qvitter/update_avatar", TwitterAPI.Controller, :update_avatar
lain's avatar
lain committed
129 130

    get "/statuses/followers", TwitterAPI.Controller, :followers
lain's avatar
lain committed
131
    get "/statuses/friends", TwitterAPI.Controller, :friends
lain's avatar
lain committed
132
  end
lain's avatar
lain committed
133

lain's avatar
lain committed
134
  pipeline :ostatus do
135
    plug :accepts, ["xml", "atom", "html"]
lain's avatar
lain committed
136 137
  end

lain's avatar
lain committed
138
  scope "/", Pleroma.Web do
lain's avatar
lain committed
139 140
    pipe_through :ostatus

141
    get "/objects/:uuid", OStatus.OStatusController, :object
lain's avatar
lain committed
142
    get "/activities/:uuid", OStatus.OStatusController, :activity
143

lain's avatar
lain committed
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
lain's avatar
lain committed
147
    post "/push/hub/:nickname", Websub.WebsubController, :websub_subscription_request
lain's avatar
lain committed
148 149
    get "/push/subscriptions/:id", Websub.WebsubController, :websub_subscription_confirmation
    post "/push/subscriptions/:id", Websub.WebsubController, :websub_incoming
lain's avatar
lain committed
150 151
  end

lain's avatar
lain committed
152 153 154 155 156 157
  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
158 159 160 161 162 163 164 165

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

defmodule Fallback.RedirectController do
  use Pleroma.Web, :controller
lain's avatar
lain committed
166 167 168 169 170 171 172
  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
173
end