forked from AkkomaGang/akkoma
Add more information about failed verifications
This commit is contained in:
parent
8a4437d2be
commit
b2112302ce
3 changed files with 19 additions and 13 deletions
|
@ -2077,10 +2077,14 @@ def parse_bio(bio, user) when is_binary(bio) and bio != "" do
|
||||||
# TODO: get profile URLs other than user.ap_id
|
# TODO: get profile URLs other than user.ap_id
|
||||||
profile_urls = [user.ap_id]
|
profile_urls = [user.ap_id]
|
||||||
|
|
||||||
bio
|
CommonUtils.format_input(bio, "text/plain",
|
||||||
|> CommonUtils.format_input("text/plain",
|
|
||||||
mentions_format: :full,
|
mentions_format: :full,
|
||||||
rel: &RelMe.maybe_put_rel_me(&1, profile_urls)
|
rel: fn link ->
|
||||||
|
case RelMe.maybe_put_rel_me(link, profile_urls) do
|
||||||
|
"me" -> "me"
|
||||||
|
_ -> nil
|
||||||
|
end
|
||||||
|
end
|
||||||
)
|
)
|
||||||
|> elem(0)
|
|> elem(0)
|
||||||
end
|
end
|
||||||
|
|
|
@ -37,15 +37,18 @@ defp parse_url(url) do
|
||||||
end
|
end
|
||||||
|
|
||||||
def maybe_put_rel_me("http" <> _ = target_page, profile_urls) when is_list(profile_urls) do
|
def maybe_put_rel_me("http" <> _ = target_page, profile_urls) when is_list(profile_urls) do
|
||||||
{:ok, rel_me_hrefs} = parse(target_page)
|
with {:parse, {:ok, rel_me_hrefs}} <- {:parse, parse(target_page)},
|
||||||
true = Enum.any?(rel_me_hrefs, fn x -> x in profile_urls end)
|
{:link_match, true} <-
|
||||||
|
{:link_match, Enum.any?(rel_me_hrefs, fn x -> x in profile_urls end)} do
|
||||||
"me"
|
"me"
|
||||||
|
else
|
||||||
|
e -> {:error, {:could_not_verify, target_page, e}}
|
||||||
|
end
|
||||||
rescue
|
rescue
|
||||||
_ -> nil
|
e -> {:error, {:could_not_fetch, target_page, e}}
|
||||||
end
|
end
|
||||||
|
|
||||||
def maybe_put_rel_me(_, _) do
|
def maybe_put_rel_me(_, _) do
|
||||||
nil
|
{:error, :invalid_url}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -26,13 +26,12 @@ test "parse/1" do
|
||||||
test "maybe_put_rel_me/2" do
|
test "maybe_put_rel_me/2" do
|
||||||
profile_urls = ["https://social.example.org/users/lain"]
|
profile_urls = ["https://social.example.org/users/lain"]
|
||||||
attr = "me"
|
attr = "me"
|
||||||
fallback = nil
|
|
||||||
|
|
||||||
assert Pleroma.Web.RelMe.maybe_put_rel_me("http://example.com/rel_me/null", profile_urls) ==
|
assert Pleroma.Web.RelMe.maybe_put_rel_me("http://example.com/rel_me/null", profile_urls) ==
|
||||||
fallback
|
{:error, {:could_not_verify, "http://example.com/rel_me/null", {:link_match, false}}}
|
||||||
|
|
||||||
assert Pleroma.Web.RelMe.maybe_put_rel_me("http://example.com/rel_me/error", profile_urls) ==
|
assert {:error, {:could_not_fetch, "http://example.com/rel_me/error", _}} =
|
||||||
fallback
|
Pleroma.Web.RelMe.maybe_put_rel_me("http://example.com/rel_me/error", profile_urls)
|
||||||
|
|
||||||
assert Pleroma.Web.RelMe.maybe_put_rel_me("http://example.com/rel_me/anchor", profile_urls) ==
|
assert Pleroma.Web.RelMe.maybe_put_rel_me("http://example.com/rel_me/anchor", profile_urls) ==
|
||||||
attr
|
attr
|
||||||
|
|
Loading…
Reference in a new issue