Fix crash while scraping images
This commit is contained in:
parent
9264c9a97d
commit
c9cc9f2428
|
@ -159,7 +159,7 @@ defmodule Frenzy.Pipeline.ScrapeStage do
|
||||||
{"src", new_src}
|
{"src", new_src}
|
||||||
|
|
||||||
_ ->
|
_ ->
|
||||||
{"src", image_to_data_uri(convert_to_data_uris, src)}
|
{"src", image_to_data_uri(src, convert_to_data_uris)}
|
||||||
end
|
end
|
||||||
|
|
||||||
attr ->
|
attr ->
|
||||||
|
@ -176,7 +176,7 @@ defmodule Frenzy.Pipeline.ScrapeStage do
|
||||||
@content_type_allowlist ["image/jpeg", "image/png", "image/heic", "image/heif", "image/tiff"]
|
@content_type_allowlist ["image/jpeg", "image/png", "image/heic", "image/heif", "image/tiff"]
|
||||||
|
|
||||||
# convert images to data URIs so that they're stored by clients as part of the body
|
# convert images to data URIs so that they're stored by clients as part of the body
|
||||||
defp image_to_data_uri(true, src) do
|
defp image_to_data_uri(src, true) do
|
||||||
case HTTPoison.get(src) do
|
case HTTPoison.get(src) do
|
||||||
{:ok, %HTTPoison.Response{status_code: 200, body: body, headers: headers}} ->
|
{:ok, %HTTPoison.Response{status_code: 200, body: body, headers: headers}} ->
|
||||||
{"Content-Type", content_type} =
|
{"Content-Type", content_type} =
|
||||||
|
@ -193,5 +193,5 @@ defmodule Frenzy.Pipeline.ScrapeStage do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp image_to_data_uri(false, src), do: src
|
defp image_to_data_uri(src, false), do: src
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue