From 687d1685f088970274dcf37daf268eb007cfc1f1 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Fri, 23 Apr 2021 09:57:23 +0200 Subject: [PATCH] Fix metadata remote image URL Signed-off-by: Thomas Citharel --- lib/service/rich_media/parser.ex | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/service/rich_media/parser.ex b/lib/service/rich_media/parser.ex index 2ea91f995..1d45b53d5 100644 --- a/lib/service/rich_media/parser.ex +++ b/lib/service/rich_media/parser.ex @@ -208,7 +208,7 @@ defmodule Mobilizon.Service.RichMedia.Parser do defp check_parsed_data(%{title: title} = data) when is_binary(title) and byte_size(title) > 0 do - {:ok, data} + data end defp check_parsed_data(data) do @@ -285,15 +285,20 @@ defmodule Mobilizon.Service.RichMedia.Parser do image_remote_url = cond do - is_nil(image_uri.host) -> "#{uri.scheme}://#{uri.host}#{image_remote_url}" + is_nil(image_uri.host) -> "#{uri.scheme}://#{uri.host}#{correct_path(image_remote_url)}" is_nil(image_uri.scheme) -> "#{uri.scheme}:#{image_remote_url}" true -> image_remote_url end - Map.put(data, :image_remote_url, image_remote_url) + data = Map.put(data, :image_remote_url, image_remote_url) + {:ok, data} end - defp check_remote_picture_path(data), do: data + defp check_remote_picture_path(data), do: {:ok, data} + + # Sometimes paths have "/" in front, sometimes not + defp correct_path("/" <> _ = path), do: path + defp correct_path(path), do: "/#{path}" # Twitter requires a well-know crawler user-agent to show server-rendered data defp default_user_agent("https://twitter.com/" <> _) do