From: raeno Date: Fri, 14 Dec 2018 18:55:40 +0000 (+0100) Subject: Handle "users/:id" links as well. Fix comments in MR. X-Git-Url: https://git.squeep.com/?a=commitdiff_plain;h=46486595ff96e0af0c3193e60879a8e67f77b933;p=akkoma Handle "users/:id" links as well. Fix comments in MR. --- diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 49928bc13..28ff08a39 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -294,6 +294,10 @@ defmodule Pleroma.User do user.info.locked || false end + def get_by_id(id) do + Repo.get_by(User, id: id) + end + def get_by_ap_id(ap_id) do Repo.get_by(User, ap_id: ap_id) end @@ -320,11 +324,20 @@ defmodule Pleroma.User do Cachex.fetch!(:user_cache, key, fn _ -> get_by_ap_id(ap_id) end) end + def get_cached_by_id(id) do + key = "id:#{id}" + Cachex.fetch!(:user_cache, key, fn _ -> get_by_id(id) end) + end + def get_cached_by_nickname(nickname) do key = "nickname:#{nickname}" Cachex.fetch!(:user_cache, key, fn _ -> get_or_fetch_by_nickname(nickname) end) end + def get_cached_by_nickname_or_id(nickname_or_id) do + get_cached_by_nickname(nickname_or_id) || get_cached_by_id(nickname_or_id) + end + def get_by_nickname(nickname) do Repo.get_by(User, nickname: nickname) end diff --git a/lib/pleroma/web/ostatus/metadata.ex b/lib/pleroma/web/ostatus/metadata.ex index 792b4a4bd..120a89a8b 100644 --- a/lib/pleroma/web/ostatus/metadata.ex +++ b/lib/pleroma/web/ostatus/metadata.ex @@ -11,8 +11,7 @@ defmodule Pleroma.Web.Metadata do end def meta_enabled?(type) do - config = Pleroma.Config.get(:metadata, []) - Keyword.get(config, type, false) + Pleroma.Config.get([:metadata, type], false) end # opengraph for single status @@ -70,6 +69,6 @@ defmodule Pleroma.Web.Metadata do end def pleroma_domain do - Pleroma.Config.get([:instance, :domain], "UNKNOWN_DOMAIN") + Pleroma.Web.Endpoint.host() end end diff --git a/lib/pleroma/web/ostatus/ostatus_controller.ex b/lib/pleroma/web/ostatus/ostatus_controller.ex index 55dbcab93..5dbee20e1 100644 --- a/lib/pleroma/web/ostatus/ostatus_controller.ex +++ b/lib/pleroma/web/ostatus/ostatus_controller.ex @@ -16,8 +16,10 @@ defmodule Pleroma.Web.OStatus.OStatusController do def feed_redirect(conn, %{"nickname" => nickname}) do case get_format(conn) do "html" -> - with %User{} = user <- User.get_cached_by_nickname(nickname) do + with %User{} = user <- User.get_cached_by_nickname_or_id(nickname) do Fallback.RedirectController.redirector_with_meta(conn, %{user: user}) + else + nil -> {:error, :not_found} end "activity+json" -> diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index 914cd6a6d..ad97698dd 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -449,11 +449,11 @@ defmodule Fallback.RedirectController do def redirector(conn, _params) do conn |> put_resp_content_type("text/html") - |> send_file(200, Application.app_dir(:pleroma, "priv/static/index.html")) + |> send_file(200, index_file_path()) end def redirector_with_meta(conn, params) do - {:ok, index_content} = File.read(Application.app_dir(:pleroma, "priv/static/index.html")) + {:ok, index_content} = File.read(index_file_path()) tags = Metadata.build_tags(params) response = String.replace(index_content, "", tags) @@ -462,6 +462,10 @@ defmodule Fallback.RedirectController do |> send_resp(200, response) end + def index_file_path do + Application.app_dir(:pleroma, "priv/static/index.html") + end + def registration_page(conn, params) do redirector(conn, params) end