Handle "users/:id" links as well. Fix comments in MR.

This commit is contained in:
raeno 2018-12-14 19:55:40 +01:00
parent c5c3ad90d0
commit 46486595ff
4 changed files with 24 additions and 6 deletions

View file

@ -294,6 +294,10 @@ def locked?(%User{} = user) do
user.info.locked || false user.info.locked || false
end end
def get_by_id(id) do
Repo.get_by(User, id: id)
end
def get_by_ap_id(ap_id) do def get_by_ap_id(ap_id) do
Repo.get_by(User, ap_id: ap_id) Repo.get_by(User, ap_id: ap_id)
end end
@ -320,11 +324,20 @@ def get_cached_by_ap_id(ap_id) do
Cachex.fetch!(:user_cache, key, fn _ -> get_by_ap_id(ap_id) end) Cachex.fetch!(:user_cache, key, fn _ -> get_by_ap_id(ap_id) end)
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 def get_cached_by_nickname(nickname) do
key = "nickname:#{nickname}" key = "nickname:#{nickname}"
Cachex.fetch!(:user_cache, key, fn _ -> get_or_fetch_by_nickname(nickname) end) Cachex.fetch!(:user_cache, key, fn _ -> get_or_fetch_by_nickname(nickname) end)
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 def get_by_nickname(nickname) do
Repo.get_by(User, nickname: nickname) Repo.get_by(User, nickname: nickname)
end end

View file

@ -11,8 +11,7 @@ def build_tags(params) do
end end
def meta_enabled?(type) do def meta_enabled?(type) do
config = Pleroma.Config.get(:metadata, []) Pleroma.Config.get([:metadata, type], false)
Keyword.get(config, type, false)
end end
# opengraph for single status # opengraph for single status
@ -70,6 +69,6 @@ defp user_avatar_url(user) do
end end
def pleroma_domain do def pleroma_domain do
Pleroma.Config.get([:instance, :domain], "UNKNOWN_DOMAIN") Pleroma.Web.Endpoint.host()
end end
end end

View file

@ -16,8 +16,10 @@ defmodule Pleroma.Web.OStatus.OStatusController do
def feed_redirect(conn, %{"nickname" => nickname}) do def feed_redirect(conn, %{"nickname" => nickname}) do
case get_format(conn) do case get_format(conn) do
"html" -> "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}) Fallback.RedirectController.redirector_with_meta(conn, %{user: user})
else
nil -> {:error, :not_found}
end end
"activity+json" -> "activity+json" ->

View file

@ -449,11 +449,11 @@ defmodule Fallback.RedirectController do
def redirector(conn, _params) do def redirector(conn, _params) do
conn conn
|> put_resp_content_type("text/html") |> put_resp_content_type("text/html")
|> send_file(200, Application.app_dir(:pleroma, "priv/static/index.html")) |> send_file(200, index_file_path())
end end
def redirector_with_meta(conn, params) do 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) tags = Metadata.build_tags(params)
response = String.replace(index_content, "<!--server-generated-meta-->", tags) response = String.replace(index_content, "<!--server-generated-meta-->", tags)
@ -462,6 +462,10 @@ def redirector_with_meta(conn, params) do
|> send_resp(200, response) |> send_resp(200, response)
end end
def index_file_path do
Application.app_dir(:pleroma, "priv/static/index.html")
end
def registration_page(conn, params) do def registration_page(conn, params) do
redirector(conn, params) redirector(conn, params)
end end