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 @@ 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

View file

@ -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

View file

@ -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" ->

View file

@ -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, "<!--server-generated-meta-->", 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