router.ex 21.2 KB
Newer Older
1
# Pleroma: A lightweight social networking server
kaniini's avatar
kaniini committed
2
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 4
# SPDX-License-Identifier: AGPL-3.0-only

lain's avatar
lain committed
5 6 7 8
defmodule Pleroma.Web.Router do
  use Pleroma.Web, :router

  pipeline :api do
lain's avatar
lain committed
9 10 11
    plug(:accepts, ["json"])
    plug(:fetch_session)
    plug(Pleroma.Plugs.OAuthPlug)
lain's avatar
lain committed
12 13 14
    plug(Pleroma.Plugs.BasicAuthDecoderPlug)
    plug(Pleroma.Plugs.UserFetcherPlug)
    plug(Pleroma.Plugs.SessionAuthenticationPlug)
lain's avatar
lain committed
15
    plug(Pleroma.Plugs.LegacyAuthenticationPlug)
lain's avatar
lain committed
16
    plug(Pleroma.Plugs.AuthenticationPlug)
lain's avatar
lain committed
17 18
    plug(Pleroma.Plugs.UserEnabledPlug)
    plug(Pleroma.Plugs.SetUserSessionIdPlug)
lain's avatar
lain committed
19
    plug(Pleroma.Plugs.EnsureUserKeyPlug)
lain's avatar
lain committed
20 21
  end

22
  pipeline :authenticated_api do
lain's avatar
lain committed
23 24 25
    plug(:accepts, ["json"])
    plug(:fetch_session)
    plug(Pleroma.Plugs.OAuthPlug)
lain's avatar
lain committed
26 27 28
    plug(Pleroma.Plugs.BasicAuthDecoderPlug)
    plug(Pleroma.Plugs.UserFetcherPlug)
    plug(Pleroma.Plugs.SessionAuthenticationPlug)
lain's avatar
lain committed
29
    plug(Pleroma.Plugs.LegacyAuthenticationPlug)
lain's avatar
lain committed
30
    plug(Pleroma.Plugs.AuthenticationPlug)
lain's avatar
lain committed
31 32
    plug(Pleroma.Plugs.UserEnabledPlug)
    plug(Pleroma.Plugs.SetUserSessionIdPlug)
lain's avatar
lain committed
33
    plug(Pleroma.Plugs.EnsureAuthenticatedPlug)
lain's avatar
lain committed
34 35
  end

Haelwenn's avatar
Haelwenn committed
36 37 38 39 40 41 42 43 44
  pipeline :admin_api do
    plug(:accepts, ["json"])
    plug(:fetch_session)
    plug(Pleroma.Plugs.OAuthPlug)
    plug(Pleroma.Plugs.BasicAuthDecoderPlug)
    plug(Pleroma.Plugs.UserFetcherPlug)
    plug(Pleroma.Plugs.SessionAuthenticationPlug)
    plug(Pleroma.Plugs.LegacyAuthenticationPlug)
    plug(Pleroma.Plugs.AuthenticationPlug)
45
    plug(Pleroma.Plugs.AdminSecretAuthenticationPlug)
Haelwenn's avatar
Haelwenn committed
46 47 48 49 50 51
    plug(Pleroma.Plugs.UserEnabledPlug)
    plug(Pleroma.Plugs.SetUserSessionIdPlug)
    plug(Pleroma.Plugs.EnsureAuthenticatedPlug)
    plug(Pleroma.Plugs.UserIsAdminPlug)
  end

lain's avatar
lain committed
52
  pipeline :mastodon_html do
lain's avatar
lain committed
53 54 55
    plug(:accepts, ["html"])
    plug(:fetch_session)
    plug(Pleroma.Plugs.OAuthPlug)
lain's avatar
lain committed
56 57 58
    plug(Pleroma.Plugs.BasicAuthDecoderPlug)
    plug(Pleroma.Plugs.UserFetcherPlug)
    plug(Pleroma.Plugs.SessionAuthenticationPlug)
lain's avatar
lain committed
59
    plug(Pleroma.Plugs.LegacyAuthenticationPlug)
lain's avatar
lain committed
60
    plug(Pleroma.Plugs.AuthenticationPlug)
lain's avatar
lain committed
61 62
    plug(Pleroma.Plugs.UserEnabledPlug)
    plug(Pleroma.Plugs.SetUserSessionIdPlug)
lain's avatar
lain committed
63
    plug(Pleroma.Plugs.EnsureUserKeyPlug)
lain's avatar
lain committed
64 65
  end

66
  pipeline :pleroma_html do
lain's avatar
lain committed
67 68 69
    plug(:accepts, ["html"])
    plug(:fetch_session)
    plug(Pleroma.Plugs.OAuthPlug)
lain's avatar
lain committed
70 71 72 73 74
    plug(Pleroma.Plugs.BasicAuthDecoderPlug)
    plug(Pleroma.Plugs.UserFetcherPlug)
    plug(Pleroma.Plugs.SessionAuthenticationPlug)
    plug(Pleroma.Plugs.AuthenticationPlug)
    plug(Pleroma.Plugs.EnsureUserKeyPlug)
75 76
  end

lain's avatar
lain committed
77
  pipeline :well_known do
lain's avatar
lain committed
78
    plug(:accepts, ["json", "jrd+json", "xml", "xrd+xml"])
lain's avatar
lain committed
79 80
  end

lain's avatar
lain committed
81
  pipeline :config do
lain's avatar
lain committed
82
    plug(:accepts, ["json", "xml"])
lain's avatar
lain committed
83 84
  end

85
  pipeline :oauth do
lain's avatar
lain committed
86
    plug(:accepts, ["html", "json"])
87 88
  end

eal's avatar
eal committed
89
  pipeline :pleroma_api do
lain's avatar
lain committed
90
    plug(:accepts, ["html", "json"])
Roger Braun's avatar
Roger Braun committed
91 92
  end

93 94 95 96 97 98 99 100 101
  pipeline :mailbox_preview do
    plug(:accepts, ["html"])

    plug(:put_secure_browser_headers, %{
      "content-security-policy" =>
        "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline' 'unsafe-eval'"
    })
  end

Roger Braun's avatar
Roger Braun committed
102
  scope "/api/pleroma", Pleroma.Web.TwitterAPI do
lain's avatar
lain committed
103 104 105 106
    pipe_through(:pleroma_api)
    get("/password_reset/:token", UtilController, :show_password_reset)
    post("/password_reset", UtilController, :password_reset)
    get("/emoji", UtilController, :emoji)
107
    get("/captcha", UtilController, :captcha)
Roger Braun's avatar
Roger Braun committed
108 109
  end

href's avatar
href committed
110 111 112 113 114
  scope "/api/pleroma", Pleroma.Web do
    pipe_through(:pleroma_api)
    post("/uploader_callback/:upload_path", UploaderController, :callback)
  end

Haelwenn's avatar
Haelwenn committed
115 116 117 118
  scope "/api/pleroma/admin", Pleroma.Web.AdminAPI do
    pipe_through(:admin_api)
    delete("/user", AdminAPIController, :user_delete)
    post("/user", AdminAPIController, :user_create)
119
    put("/users/tag", AdminAPIController, :tag_users)
120
    delete("/users/tag", AdminAPIController, :untag_users)
Haelwenn's avatar
Haelwenn committed
121

122 123 124 125
    get("/permission_group/:nickname", AdminAPIController, :right_get)
    get("/permission_group/:nickname/:permission_group", AdminAPIController, :right_get)
    post("/permission_group/:nickname/:permission_group", AdminAPIController, :right_add)
    delete("/permission_group/:nickname/:permission_group", AdminAPIController, :right_delete)
Haelwenn's avatar
Haelwenn committed
126 127 128 129 130

    post("/relay", AdminAPIController, :relay_follow)
    delete("/relay", AdminAPIController, :relay_unfollow)

    get("/invite_token", AdminAPIController, :get_invite_token)
131 132
    post("/email_invite", AdminAPIController, :email_invite)

Haelwenn's avatar
Haelwenn committed
133 134 135
    get("/password_reset", AdminAPIController, :get_password_reset)
  end

136
  scope "/", Pleroma.Web.TwitterAPI do
lain's avatar
lain committed
137 138 139 140
    pipe_through(:pleroma_html)
    get("/ostatus_subscribe", UtilController, :remote_follow)
    post("/ostatus_subscribe", UtilController, :do_remote_follow)
    post("/main/ostatus", UtilController, :remote_subscribe)
141 142
  end

eal's avatar
eal committed
143
  scope "/api/pleroma", Pleroma.Web.TwitterAPI do
lain's avatar
lain committed
144
    pipe_through(:authenticated_api)
145
    post("/blocks_import", UtilController, :blocks_import)
lain's avatar
lain committed
146
    post("/follow_import", UtilController, :follow_import)
147
    post("/change_password", UtilController, :change_password)
148
    post("/delete_account", UtilController, :delete_account)
eal's avatar
eal committed
149 150
  end

151
  scope "/oauth", Pleroma.Web.OAuth do
lain's avatar
lain committed
152 153 154
    get("/authorize", OAuthController, :authorize)
    post("/authorize", OAuthController, :create_authorization)
    post("/token", OAuthController, :token_exchange)
155
    post("/revoke", OAuthController, :token_revoke)
156 157 158
  end

  scope "/api/v1", Pleroma.Web.MastodonAPI do
lain's avatar
lain committed
159
    pipe_through(:authenticated_api)
160

lain's avatar
lain committed
161 162 163 164 165 166 167 168
    patch("/accounts/update_credentials", MastodonAPIController, :update_credentials)
    get("/accounts/verify_credentials", MastodonAPIController, :verify_credentials)
    get("/accounts/relationships", MastodonAPIController, :relationships)
    get("/accounts/search", MastodonAPIController, :account_search)
    post("/accounts/:id/follow", MastodonAPIController, :follow)
    post("/accounts/:id/unfollow", MastodonAPIController, :unfollow)
    post("/accounts/:id/block", MastodonAPIController, :block)
    post("/accounts/:id/unblock", MastodonAPIController, :unblock)
169 170
    post("/accounts/:id/mute", MastodonAPIController, :mute)
    post("/accounts/:id/unmute", MastodonAPIController, :unmute)
171
    get("/accounts/:id/lists", MastodonAPIController, :account_lists)
172

173
    get("/follow_requests", MastodonAPIController, :follow_requests)
kaniini's avatar
kaniini committed
174 175
    post("/follow_requests/:id/authorize", MastodonAPIController, :authorize_follow_request)
    post("/follow_requests/:id/reject", MastodonAPIController, :reject_follow_request)
176

lain's avatar
lain committed
177
    post("/follows", MastodonAPIController, :follow)
eal's avatar
eal committed
178

lain's avatar
lain committed
179
    get("/blocks", MastodonAPIController, :blocks)
lain's avatar
lain committed
180

lain's avatar
lain committed
181
    get("/mutes", MastodonAPIController, :empty_array)
Roger Braun's avatar
Roger Braun committed
182

lain's avatar
lain committed
183
    get("/timelines/home", MastodonAPIController, :home_timeline)
lain's avatar
lain committed
184

185 186
    get("/timelines/direct", MastodonAPIController, :dm_timeline)

lain's avatar
lain committed
187
    get("/favourites", MastodonAPIController, :favourites)
Haelwenn's avatar
Haelwenn committed
188
    get("/bookmarks", MastodonAPIController, :bookmarks)
189

lain's avatar
lain committed
190 191
    post("/statuses", MastodonAPIController, :post_status)
    delete("/statuses/:id", MastodonAPIController, :delete_status)
lain's avatar
lain committed
192

lain's avatar
lain committed
193
    post("/statuses/:id/reblog", MastodonAPIController, :reblog_status)
normandy's avatar
normandy committed
194
    post("/statuses/:id/unreblog", MastodonAPIController, :unreblog_status)
lain's avatar
lain committed
195 196
    post("/statuses/:id/favourite", MastodonAPIController, :fav_status)
    post("/statuses/:id/unfavourite", MastodonAPIController, :unfav_status)
minibikini's avatar
minibikini committed
197 198
    post("/statuses/:id/pin", MastodonAPIController, :pin_status)
    post("/statuses/:id/unpin", MastodonAPIController, :unpin_status)
Haelwenn's avatar
Haelwenn committed
199 200
    post("/statuses/:id/bookmark", MastodonAPIController, :bookmark_status)
    post("/statuses/:id/unbookmark", MastodonAPIController, :unbookmark_status)
201 202
    post("/statuses/:id/mute", MastodonAPIController, :mute_conversation)
    post("/statuses/:id/unmute", MastodonAPIController, :unmute_conversation)
203

lain's avatar
lain committed
204 205 206 207
    post("/notifications/clear", MastodonAPIController, :clear_notifications)
    post("/notifications/dismiss", MastodonAPIController, :dismiss_notification)
    get("/notifications", MastodonAPIController, :notifications)
    get("/notifications/:id", MastodonAPIController, :get_notification)
lain's avatar
lain committed
208

lain's avatar
lain committed
209
    post("/media", MastodonAPIController, :upload)
210
    put("/media/:id", MastodonAPIController, :update_media)
eal's avatar
eal committed
211 212 213 214 215 216 217 218 219

    get("/lists", MastodonAPIController, :get_lists)
    get("/lists/:id", MastodonAPIController, :get_list)
    delete("/lists/:id", MastodonAPIController, :delete_list)
    post("/lists", MastodonAPIController, :create_list)
    put("/lists/:id", MastodonAPIController, :rename_list)
    get("/lists/:id/accounts", MastodonAPIController, :list_accounts)
    post("/lists/:id/accounts", MastodonAPIController, :add_to_list)
    delete("/lists/:id/accounts", MastodonAPIController, :remove_from_list)
eal's avatar
eal committed
220 221 222 223

    get("/domain_blocks", MastodonAPIController, :domain_blocks)
    post("/domain_blocks", MastodonAPIController, :block_domain)
    delete("/domain_blocks", MastodonAPIController, :unblock_domain)
hakabahitoyo's avatar
hakabahitoyo committed
224

Haelwenn's avatar
Haelwenn committed
225 226 227 228 229 230
    get("/filters", MastodonAPIController, :get_filters)
    post("/filters", MastodonAPIController, :create_filter)
    get("/filters/:id", MastodonAPIController, :get_filter)
    put("/filters/:id", MastodonAPIController, :update_filter)
    delete("/filters/:id", MastodonAPIController, :delete_filter)

231 232 233 234 235
    post("/push/subscription", MastodonAPIController, :create_push_subscription)
    get("/push/subscription", MastodonAPIController, :get_push_subscription)
    put("/push/subscription", MastodonAPIController, :update_push_subscription)
    delete("/push/subscription", MastodonAPIController, :delete_push_subscription)

hakabahitoyo's avatar
hakabahitoyo committed
236
    get("/suggestions", MastodonAPIController, :suggestions)
237 238

    get("/endorsements", MastodonAPIController, :empty_array)
239 240 241

    post("/pleroma/flavour/:flavour", MastodonAPIController, :set_flavour)
    get("/pleroma/flavour", MastodonAPIController, :get_flavour)
lain's avatar
lain committed
242 243
  end

244 245 246 247 248 249
  scope "/api/web", Pleroma.Web.MastodonAPI do
    pipe_through(:authenticated_api)

    put("/settings", MastodonAPIController, :put_settings)
  end

Roger Braun's avatar
Roger Braun committed
250
  scope "/api/v1", Pleroma.Web.MastodonAPI do
lain's avatar
lain committed
251 252 253 254 255 256 257 258
    pipe_through(:api)
    get("/instance", MastodonAPIController, :masto_instance)
    get("/instance/peers", MastodonAPIController, :peers)
    post("/apps", MastodonAPIController, :create_app)
    get("/custom_emojis", MastodonAPIController, :custom_emojis)

    get("/timelines/public", MastodonAPIController, :public_timeline)
    get("/timelines/tag/:tag", MastodonAPIController, :hashtag_timeline)
eal's avatar
eal committed
259
    get("/timelines/list/:list_id", MastodonAPIController, :list_timeline)
lain's avatar
lain committed
260 261 262

    get("/statuses/:id", MastodonAPIController, :get_status)
    get("/statuses/:id/context", MastodonAPIController, :get_context)
263
    get("/statuses/:id/card", MastodonAPIController, :status_card)
lain's avatar
lain committed
264 265 266 267 268 269 270 271
    get("/statuses/:id/favourited_by", MastodonAPIController, :favourited_by)
    get("/statuses/:id/reblogged_by", MastodonAPIController, :reblogged_by)

    get("/accounts/:id/statuses", MastodonAPIController, :user_statuses)
    get("/accounts/:id/followers", MastodonAPIController, :followers)
    get("/accounts/:id/following", MastodonAPIController, :following)
    get("/accounts/:id", MastodonAPIController, :user)

Haelwenn's avatar
Haelwenn committed
272 273
    get("/trends", MastodonAPIController, :empty_array)

lain's avatar
lain committed
274
    get("/search", MastodonAPIController, :search)
Roger Braun's avatar
Roger Braun committed
275 276
  end

277 278 279 280 281
  scope "/api/v2", Pleroma.Web.MastodonAPI do
    pipe_through(:api)
    get("/search", MastodonAPIController, :search2)
  end

lain's avatar
lain committed
282
  scope "/api", Pleroma.Web do
lain's avatar
lain committed
283
    pipe_through(:config)
dtluna's avatar
dtluna committed
284

lain's avatar
lain committed
285 286 287 288
    get("/help/test", TwitterAPI.UtilController, :help_test)
    post("/help/test", TwitterAPI.UtilController, :help_test)
    get("/statusnet/config", TwitterAPI.UtilController, :config)
    get("/statusnet/version", TwitterAPI.UtilController, :version)
lain's avatar
lain committed
289
    get("/pleroma/frontend_configurations", TwitterAPI.UtilController, :frontend_configurations)
lain's avatar
lain committed
290 291 292
  end

  scope "/api", Pleroma.Web do
lain's avatar
lain committed
293
    pipe_through(:api)
dtluna's avatar
dtluna committed
294

lain's avatar
lain committed
295 296 297 298 299 300
    get("/statuses/user_timeline", TwitterAPI.Controller, :user_timeline)
    get("/qvitter/statuses/user_timeline", TwitterAPI.Controller, :user_timeline)
    get("/users/show", TwitterAPI.Controller, :show_user)

    get("/statuses/followers", TwitterAPI.Controller, :followers)
    get("/statuses/friends", TwitterAPI.Controller, :friends)
301
    get("/statuses/blocks", TwitterAPI.Controller, :blocks)
lain's avatar
lain committed
302 303
    get("/statuses/show/:id", TwitterAPI.Controller, :fetch_status)
    get("/statusnet/conversation/:id", TwitterAPI.Controller, :fetch_conversation)
dtluna's avatar
dtluna committed
304

HJ's avatar
HJ committed
305
    post("/account/register", TwitterAPI.Controller, :register)
306
    post("/account/password_reset", TwitterAPI.Controller, :password_reset)
lain's avatar
lain committed
307

308 309 310 311 312 313
    get(
      "/account/confirm_email/:user_id/:token",
      TwitterAPI.Controller,
      :confirm_email,
      as: :confirm_email
    )
lain's avatar
lain committed
314

315 316
    post("/account/resend_confirmation_email", TwitterAPI.Controller, :resend_confirmation_email)

lain's avatar
lain committed
317 318
    get("/search", TwitterAPI.Controller, :search)
    get("/statusnet/tags/timeline/:tag", TwitterAPI.Controller, :public_and_external_timeline)
319 320
  end

lain's avatar
lain committed
321
  scope "/api", Pleroma.Web do
href's avatar
href committed
322
    pipe_through(:api)
lain's avatar
lain committed
323 324 325 326 327 328 329 330 331 332 333 334

    get("/statuses/public_timeline", TwitterAPI.Controller, :public_timeline)

    get(
      "/statuses/public_and_external_timeline",
      TwitterAPI.Controller,
      :public_and_external_timeline
    )

    get("/statuses/networkpublic_timeline", TwitterAPI.Controller, :public_and_external_timeline)
  end

335 336 337 338 339 340
  scope "/api", Pleroma.Web, as: :twitter_api_search do
    pipe_through(:api)
    get("/pleroma/search_user", TwitterAPI.Controller, :search_user)
  end

  scope "/api", Pleroma.Web, as: :authenticated_twitter_api do
lain's avatar
lain committed
341
    pipe_through(:authenticated_api)
342

lain's avatar
lain committed
343 344
    get("/account/verify_credentials", TwitterAPI.Controller, :verify_credentials)
    post("/account/verify_credentials", TwitterAPI.Controller, :verify_credentials)
dtluna's avatar
dtluna committed
345

lain's avatar
lain committed
346 347 348
    post("/account/update_profile", TwitterAPI.Controller, :update_profile)
    post("/account/update_profile_banner", TwitterAPI.Controller, :update_banner)
    post("/qvitter/update_background_image", TwitterAPI.Controller, :update_background)
lain's avatar
lain committed
349

lain's avatar
lain committed
350 351 352 353
    get("/statuses/home_timeline", TwitterAPI.Controller, :friends_timeline)
    get("/statuses/friends_timeline", TwitterAPI.Controller, :friends_timeline)
    get("/statuses/mentions", TwitterAPI.Controller, :mentions_timeline)
    get("/statuses/mentions_timeline", TwitterAPI.Controller, :mentions_timeline)
lain's avatar
lain committed
354
    get("/statuses/dm_timeline", TwitterAPI.Controller, :dm_timeline)
355
    get("/qvitter/statuses/notifications", TwitterAPI.Controller, :notifications)
dtluna's avatar
dtluna committed
356

357 358 359 360
    # XXX: this is really a pleroma API, but we want to keep the pleroma namespace clean
    #      for now.
    post("/qvitter/statuses/notifications/read", TwitterAPI.Controller, :notifications_read)

lain's avatar
lain committed
361 362
    post("/statuses/update", TwitterAPI.Controller, :status_update)
    post("/statuses/retweet/:id", TwitterAPI.Controller, :retweet)
363
    post("/statuses/unretweet/:id", TwitterAPI.Controller, :unretweet)
lain's avatar
lain committed
364
    post("/statuses/destroy/:id", TwitterAPI.Controller, :delete_post)
dtluna's avatar
dtluna committed
365

366 367 368
    post("/statuses/pin/:id", TwitterAPI.Controller, :pin)
    post("/statuses/unpin/:id", TwitterAPI.Controller, :unpin)

369
    get("/pleroma/friend_requests", TwitterAPI.Controller, :friend_requests)
370 371
    post("/pleroma/friendships/approve", TwitterAPI.Controller, :approve_friend_request)
    post("/pleroma/friendships/deny", TwitterAPI.Controller, :deny_friend_request)
372

lain's avatar
lain committed
373 374 375 376
    post("/friendships/create", TwitterAPI.Controller, :follow)
    post("/friendships/destroy", TwitterAPI.Controller, :unfollow)
    post("/blocks/create", TwitterAPI.Controller, :block)
    post("/blocks/destroy", TwitterAPI.Controller, :unblock)
dtluna's avatar
dtluna committed
377

lain's avatar
lain committed
378 379
    post("/statusnet/media/upload", TwitterAPI.Controller, :upload)
    post("/media/upload", TwitterAPI.Controller, :upload_json)
380
    post("/media/metadata/create", TwitterAPI.Controller, :update_media)
dtluna's avatar
dtluna committed
381

lain's avatar
lain committed
382 383 384
    post("/favorites/create/:id", TwitterAPI.Controller, :favorite)
    post("/favorites/create", TwitterAPI.Controller, :favorite)
    post("/favorites/destroy/:id", TwitterAPI.Controller, :unfavorite)
dtluna's avatar
dtluna committed
385

lain's avatar
lain committed
386
    post("/qvitter/update_avatar", TwitterAPI.Controller, :update_avatar)
lain's avatar
lain committed
387

lain's avatar
lain committed
388 389
    get("/friends/ids", TwitterAPI.Controller, :friends_ids)
    get("/friendships/no_retweets/ids", TwitterAPI.Controller, :empty_array)
390

lain's avatar
lain committed
391
    get("/mutes/users/ids", TwitterAPI.Controller, :empty_array)
392
    get("/qvitter/mutes", TwitterAPI.Controller, :raw_empty_array)
393

lain's avatar
lain committed
394
    get("/externalprofile/show", TwitterAPI.Controller, :external_profile)
Maxim Filippov's avatar
Maxim Filippov committed
395 396

    get("/oauth_tokens", TwitterAPI.Controller, :oauth_tokens)
Maxim Filippov's avatar
Maxim Filippov committed
397
    delete("/oauth_tokens/:id", TwitterAPI.Controller, :revoke_token)
lain's avatar
lain committed
398
  end
lain's avatar
lain committed
399

400 401 402 403
  pipeline :ap_relay do
    plug(:accepts, ["activity+json"])
  end

lain's avatar
lain committed
404
  pipeline :ostatus do
405
    plug(:accepts, ["html", "xml", "atom", "activity+json"])
lain's avatar
lain committed
406 407
  end

408 409 410 411
  pipeline :oembed do
    plug(:accepts, ["json", "xml"])
  end

lain's avatar
lain committed
412
  scope "/", Pleroma.Web do
lain's avatar
lain committed
413
    pipe_through(:ostatus)
lain's avatar
lain committed
414

lain's avatar
lain committed
415 416 417 418 419
    get("/objects/:uuid", OStatus.OStatusController, :object)
    get("/activities/:uuid", OStatus.OStatusController, :activity)
    get("/notice/:id", OStatus.OStatusController, :notice)
    get("/users/:nickname/feed", OStatus.OStatusController, :feed)
    get("/users/:nickname", OStatus.OStatusController, :feed_redirect)
lain's avatar
lain committed
420

href's avatar
href committed
421 422 423 424
    post("/users/:nickname/salmon", OStatus.OStatusController, :salmon_incoming)
    post("/push/hub/:nickname", Websub.WebsubController, :websub_subscription_request)
    get("/push/subscriptions/:id", Websub.WebsubController, :websub_subscription_confirmation)
    post("/push/subscriptions/:id", Websub.WebsubController, :websub_incoming)
lain's avatar
lain committed
425 426
  end

427 428 429 430 431 432
  scope "/", Pleroma.Web do
    pipe_through(:oembed)

    get("/oembed", OEmbed.OEmbedController, :url)
  end

lain's avatar
lain committed
433
  pipeline :activitypub do
lain's avatar
lain committed
434 435
    plug(:accepts, ["activity+json"])
    plug(Pleroma.Web.Plugs.HTTPSignaturePlug)
lain's avatar
lain committed
436 437
  end

438 439
  scope "/", Pleroma.Web.ActivityPub do
    # XXX: not really ostatus
lain's avatar
lain committed
440
    pipe_through(:ostatus)
441

lain's avatar
lain committed
442 443 444
    get("/users/:nickname/followers", ActivityPubController, :followers)
    get("/users/:nickname/following", ActivityPubController, :following)
    get("/users/:nickname/outbox", ActivityPubController, :outbox)
445
    get("/objects/:uuid/likes", ActivityPubController, :object_likes)
446 447
  end

448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464
  pipeline :activitypub_client do
    plug(:accepts, ["activity+json"])
    plug(:fetch_session)
    plug(Pleroma.Plugs.OAuthPlug)
    plug(Pleroma.Plugs.BasicAuthDecoderPlug)
    plug(Pleroma.Plugs.UserFetcherPlug)
    plug(Pleroma.Plugs.SessionAuthenticationPlug)
    plug(Pleroma.Plugs.LegacyAuthenticationPlug)
    plug(Pleroma.Plugs.AuthenticationPlug)
    plug(Pleroma.Plugs.UserEnabledPlug)
    plug(Pleroma.Plugs.SetUserSessionIdPlug)
    plug(Pleroma.Plugs.EnsureUserKeyPlug)
  end

  scope "/", Pleroma.Web.ActivityPub do
    pipe_through([:activitypub_client])

465
    get("/api/ap/whoami", ActivityPubController, :whoami)
466 467 468 469
    get("/users/:nickname/inbox", ActivityPubController, :read_inbox)
    post("/users/:nickname/outbox", ActivityPubController, :update_outbox)
  end

href's avatar
href committed
470 471 472 473
  scope "/relay", Pleroma.Web.ActivityPub do
    pipe_through(:ap_relay)
    get("/", ActivityPubController, :relay)
  end
474

href's avatar
href committed
475 476 477
  scope "/", Pleroma.Web.ActivityPub do
    pipe_through(:activitypub)
    post("/inbox", ActivityPubController, :inbox)
478
    post("/users/:nickname/inbox", ActivityPubController, :inbox)
href's avatar
href committed
479
  end
lain's avatar
lain committed
480

href's avatar
href committed
481 482
  scope "/.well-known", Pleroma.Web do
    pipe_through(:well_known)
lain's avatar
lain committed
483

href's avatar
href committed
484 485 486 487
    get("/host-meta", WebFinger.WebFingerController, :host_meta)
    get("/webfinger", WebFinger.WebFingerController, :webfinger)
    get("/nodeinfo", Nodeinfo.NodeinfoController, :schemas)
  end
dashie's avatar
dashie committed
488

href's avatar
href committed
489 490
  scope "/nodeinfo", Pleroma.Web do
    get("/:version", Nodeinfo.NodeinfoController, :nodeinfo)
lain's avatar
lain committed
491
  end
lain's avatar
lain committed
492

lain's avatar
lain committed
493
  scope "/", Pleroma.Web.MastodonAPI do
lain's avatar
lain committed
494
    pipe_through(:mastodon_html)
lain's avatar
lain committed
495

lain's avatar
lain committed
496 497 498 499
    get("/web/login", MastodonAPIController, :login)
    post("/web/login", MastodonAPIController, :login_post)
    get("/web/*path", MastodonAPIController, :index)
    delete("/auth/sign_out", MastodonAPIController, :logout)
lain's avatar
lain committed
500 501
  end

href's avatar
href committed
502 503
  pipeline :remote_media do
  end
lain's avatar
lain committed
504

href's avatar
href committed
505
  scope "/proxy/", Pleroma.Web.MediaProxy do
lain's avatar
lain committed
506 507
    pipe_through(:remote_media)
    get("/:sig/:url", MediaProxyController, :remote)
href's avatar
href committed
508
    get("/:sig/:url/:filename", MediaProxyController, :remote)
href's avatar
href committed
509 510
  end

511 512 513 514 515 516
  if Mix.env() == :dev do
    scope "/dev" do
      pipe_through([:mailbox_preview])

      forward("/mailbox", Plug.Swoosh.MailboxPreview, base_path: "/dev/mailbox")
    end
href's avatar
href committed
517 518
  end

lain's avatar
lain committed
519
  scope "/", Fallback do
HJ's avatar
HJ committed
520
    get("/registration/:token", RedirectController, :registration_page)
521 522
    get("/:maybe_nickname_or_id", RedirectController, :redirector_with_meta)
    get("/*path", RedirectController, :redirector)
523 524

    options("/*path", RedirectController, :empty)
lain's avatar
lain committed
525 526 527 528 529
  end
end

defmodule Fallback.RedirectController do
  use Pleroma.Web, :controller
530
  alias Pleroma.Web.Metadata
531
  alias Pleroma.User
lain's avatar
lain committed
532

533
  def redirector(conn, _params, code \\ 200) do
href's avatar
href committed
534 535
    conn
    |> put_resp_content_type("text/html")
536
    |> send_file(code, index_file_path())
lain's avatar
lain committed
537
  end
HJ's avatar
HJ committed
538

539 540 541 542 543 544 545 546 547
  def redirector_with_meta(conn, %{"maybe_nickname_or_id" => maybe_nickname_or_id} = params) do
    with %User{} = user <- User.get_cached_by_nickname_or_id(maybe_nickname_or_id) do
      redirector_with_meta(conn, %{user: user})
    else
      nil ->
        redirector(conn, params)
    end
  end

548
  def redirector_with_meta(conn, params) do
549
    {:ok, index_content} = File.read(index_file_path())
550
    tags = Metadata.build_tags(params)
551 552 553 554 555 556 557
    response = String.replace(index_content, "<!--server-generated-meta-->", tags)

    conn
    |> put_resp_content_type("text/html")
    |> send_resp(200, response)
  end

558
  def index_file_path do
raeno's avatar
raeno committed
559
    Pleroma.Plugs.InstanceStatic.file_path("index.html")
560 561
  end

HJ's avatar
HJ committed
562 563 564
  def registration_page(conn, params) do
    redirector(conn, params)
  end
565 566 567 568 569 570

  def empty(conn, _params) do
    conn
    |> put_status(204)
    |> text("")
  end
lain's avatar
lain committed
571
end