attempt to fix some tests

This commit is contained in:
Floatingghost 2024-06-09 18:45:38 +01:00
parent 16bed0562d
commit c65379afea
3 changed files with 20 additions and 22 deletions

View file

@ -534,25 +534,25 @@ def render("card.json", %Card{fields: rich_media}) do
page_url = page_url_data |> to_string page_url = page_url_data |> to_string
image_url_data = image_url = proxied_url(rich_media["image"], page_url_data)
if is_binary(rich_media["image"]) do audio_url = proxied_url(rich_media["audio"], page_url_data)
URI.parse(rich_media["image"]) video_url = proxied_url(rich_media["video"], page_url_data)
else
nil
end
image_url = build_image_url(image_url_data, page_url_data)
%{ %{
type: "link", type: "link",
provider_name: page_url_data.host, provider_name: page_url_data.host,
provider_url: page_url_data.scheme <> "://" <> page_url_data.host, provider_url: page_url_data.scheme <> "://" <> page_url_data.host,
url: page_url, url: page_url,
image: image_url |> MediaProxy.url(), image: image_url,
image_description: rich_media["image:alt"] || "",
title: rich_media["title"] || "", title: rich_media["title"] || "",
description: rich_media["description"] || "", description: rich_media["description"] || "",
pleroma: %{ pleroma: %{
opengraph: rich_media opengraph:
rich_media
|> Maps.put_if_present("image", image_url)
|> Maps.put_if_present("audio", audio_url)
|> Maps.put_if_present("video", video_url)
} }
} }
end end
@ -630,6 +630,14 @@ def render("context.json", %{activity: activity, activities: activities, user: u
} }
end end
defp proxied_url(url, page_url_data) do
if is_binary(url) do
build_image_url(URI.parse(url), page_url_data) |> MediaProxy.url()
else
nil
end
end
def get_reply_to(activity, %{replied_to_activities: replied_to_activities}) do def get_reply_to(activity, %{replied_to_activities: replied_to_activities}) do
object = Object.normalize(activity, fetch: false) object = Object.normalize(activity, fetch: false)
@ -734,19 +742,7 @@ defp build_application(%{"type" => _type, "name" => name, "url" => url}),
defp build_application(_), do: nil defp build_application(_), do: nil
# Workaround for Elixir issue #10771
# Avoid applying URI.merge unless necessary
# TODO: revert to always attempting URI.merge(image_url_data, page_url_data)
# when Elixir 1.12 is the minimum supported version
@spec build_image_url(struct() | nil, struct()) :: String.t() | nil @spec build_image_url(struct() | nil, struct()) :: String.t() | nil
defp build_image_url(
%URI{scheme: image_scheme, host: image_host} = image_url_data,
%URI{} = _page_url_data
)
when not is_nil(image_scheme) and not is_nil(image_host) do
image_url_data |> to_string
end
defp build_image_url(%URI{} = image_url_data, %URI{} = page_url_data) do defp build_image_url(%URI{} = image_url_data, %URI{} = page_url_data) do
URI.merge(page_url_data, image_url_data) |> to_string URI.merge(page_url_data, image_url_data) |> to_string
end end

View file

@ -48,6 +48,7 @@ def url(url) do
else else
url url
end end
|> IO.inspect()
end end
@spec url_proxiable?(String.t()) :: boolean() @spec url_proxiable?(String.t()) :: boolean()

View file

@ -31,6 +31,7 @@ defp parse_url(url) do
{:ok, html} <- Floki.parse_document(html) do {:ok, html} <- Floki.parse_document(html) do
html html
|> maybe_parse() |> maybe_parse()
|> IO.inspect()
|> clean_parsed_data() |> clean_parsed_data()
|> check_parsed_data() |> check_parsed_data()
end end