- defp handle_preview("image/" <> _ = content_type, %{params: params} = conn, url) do
- with {:ok, %{status: status, body: body}} when status in 200..299 <-
- url
- |> MediaProxy.url()
- |> Tesla.get(opts: [adapter: [timeout: preview_timeout()]]),
- {:ok, path} <- MogrifyHelper.store_as_temporary_file(url, body),
- resize_dimensions <-
- Map.get(
- params,
- "limit_dimensions",
- Config.get([:media_preview_proxy, :limit_dimensions])
- ),
- %Mogrify.Image{} <- MogrifyHelper.in_place_resize_to_limit(path, resize_dimensions),
- {:ok, image_binary} <- File.read(path),
- _ <- File.rm(path) do
- conn
- |> put_resp_header("content-type", content_type)
- |> send_resp(200, image_binary)
- else
- {_, %{status: _}} ->
- send_resp(conn, :failed_dependency, "Can't fetch the image.")
+ defp handle_preview("image/gif" = _content_type, conn, url) do
+ mediaproxy_url = url |> MediaProxy.url()