Merge branch 'patch-2' into 'develop'
[akkoma] / lib / pleroma / web / router.ex
index 13bd393abcfd0f3ae3a3a861bdfd728b1567d577..92732379465af1d6353d7d4c39a8123ac7cbbae6 100644 (file)
@@ -5,11 +5,23 @@ defmodule Pleroma.Web.Router do
 
   @instance Application.get_env(:pleroma, :instance)
   @federating Keyword.get(@instance, :federating)
+  @allow_relay Keyword.get(@instance, :allow_relay)
   @public Keyword.get(@instance, :public)
   @registrations_open Keyword.get(@instance, :registrations_open)
 
-  def user_fetcher(username) do
-    {:ok, Repo.get_by(User, %{nickname: username})}
+  def user_fetcher(username_or_email) do
+    {
+      :ok,
+      cond do
+        # First, try logging in as if it was a name
+        user = Repo.get_by(User, %{nickname: username_or_email}) ->
+          user
+
+        # If we get nil, we try using it as an email
+        user = Repo.get_by(User, %{email: username_or_email}) ->
+          user
+      end
+    }
   end
 
   pipeline :api do
@@ -127,6 +139,7 @@ defmodule Pleroma.Web.Router do
     get("/notifications/:id", MastodonAPIController, :get_notification)
 
     post("/media", MastodonAPIController, :upload)
+    put("/media/:id", MastodonAPIController, :update_media)
 
     get("/lists", MastodonAPIController, :get_lists)
     get("/lists/:id", MastodonAPIController, :get_list)
@@ -140,6 +153,8 @@ defmodule Pleroma.Web.Router do
     get("/domain_blocks", MastodonAPIController, :domain_blocks)
     post("/domain_blocks", MastodonAPIController, :block_domain)
     delete("/domain_blocks", MastodonAPIController, :unblock_domain)
+
+    get("/suggestions", MastodonAPIController, :suggestions)
   end
 
   scope "/api/web", Pleroma.Web.MastodonAPI do
@@ -170,9 +185,16 @@ defmodule Pleroma.Web.Router do
     get("/accounts/:id/following", MastodonAPIController, :following)
     get("/accounts/:id", MastodonAPIController, :user)
 
+    get("/trends", MastodonAPIController, :empty_array)
+
     get("/search", MastodonAPIController, :search)
   end
 
+  scope "/api/v2", Pleroma.Web.MastodonAPI do
+    pipe_through(:api)
+    get("/search", MastodonAPIController, :search2)
+  end
+
   scope "/api", Pleroma.Web do
     pipe_through(:config)
 
@@ -194,9 +216,7 @@ defmodule Pleroma.Web.Router do
     get("/statuses/show/:id", TwitterAPI.Controller, :fetch_status)
     get("/statusnet/conversation/:id", TwitterAPI.Controller, :fetch_conversation)
 
-    if @registrations_open do
-      post("/account/register", TwitterAPI.Controller, :register)
-    end
+    post("/account/register", TwitterAPI.Controller, :register)
 
     get("/search", TwitterAPI.Controller, :search)
     get("/statusnet/tags/timeline/:tag", TwitterAPI.Controller, :public_and_external_timeline)
@@ -269,10 +289,15 @@ defmodule Pleroma.Web.Router do
     get("/friendships/no_retweets/ids", TwitterAPI.Controller, :empty_array)
 
     get("/mutes/users/ids", TwitterAPI.Controller, :empty_array)
+    get("/qvitter/mutes", TwitterAPI.Controller, :raw_empty_array)
 
     get("/externalprofile/show", TwitterAPI.Controller, :external_profile)
   end
 
+  pipeline :ap_relay do
+    plug(:accepts, ["activity+json"])
+  end
+
   pipeline :ostatus do
     plug(:accepts, ["xml", "atom", "html", "activity+json"])
   end
@@ -309,6 +334,13 @@ defmodule Pleroma.Web.Router do
   end
 
   if @federating do
+    if @allow_relay do
+      scope "/relay", Pleroma.Web.ActivityPub do
+        pipe_through(:ap_relay)
+        get("/", ActivityPubController, :relay)
+      end
+    end
+
     scope "/", Pleroma.Web.ActivityPub do
       pipe_through(:activitypub)
       post("/users/:nickname/inbox", ActivityPubController, :inbox)
@@ -347,6 +379,7 @@ defmodule Pleroma.Web.Router do
   end
 
   scope "/", Fallback do
+    get("/registration/:token", RedirectController, :registration_page)
     get("/*path", RedirectController, :redirector)
   end
 end
@@ -361,4 +394,8 @@ defmodule Fallback.RedirectController do
       |> send_file(200, "priv/static/index.html")
     end
   end
+
+  def registration_page(conn, params) do
+    redirector(conn, params)
+  end
 end