From de8001a1ff655e754172986ba9b39f0174971dfc Mon Sep 17 00:00:00 2001 From: "byte[]" Date: Sat, 17 Apr 2021 22:28:03 -0400 Subject: [PATCH] obj storage prep: skip generating urls for symlink version targets --- lib/philomena/images/thumbnailer.ex | 6 ++++++ lib/philomena_web/views/image_view.ex | 19 +++++++++---------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/lib/philomena/images/thumbnailer.ex b/lib/philomena/images/thumbnailer.ex index 0720be0d..1868831a 100644 --- a/lib/philomena/images/thumbnailer.ex +++ b/lib/philomena/images/thumbnailer.ex @@ -22,6 +22,12 @@ defmodule Philomena.Images.Thumbnailer do full: nil ] + def thumbnail_versions do + Enum.filter(@versions, fn {_name, dimensions} -> + not is_nil(dimensions) + end) + end + def thumbnail_urls(image, hidden_key) do Path.join([image_thumb_dir(image), "*"]) |> Path.wildcard() diff --git a/lib/philomena_web/views/image_view.ex b/lib/philomena_web/views/image_view.ex index 7d003deb..c63977d9 100644 --- a/lib/philomena_web/views/image_view.ex +++ b/lib/philomena_web/views/image_view.ex @@ -2,6 +2,7 @@ defmodule PhilomenaWeb.ImageView do use PhilomenaWeb, :view alias Philomena.Tags.Tag + alias Philomena.Images.Thumbnailer def show_vote_counts?(%{hide_vote_counts: true}), do: false def show_vote_counts?(_user), do: true @@ -45,16 +46,14 @@ defmodule PhilomenaWeb.ImageView do end def thumb_urls(image, show_hidden) do - %{ - thumb_tiny: thumb_url(image, show_hidden, :thumb_tiny), - thumb_small: thumb_url(image, show_hidden, :thumb_small), - thumb: thumb_url(image, show_hidden, :thumb), - small: thumb_url(image, show_hidden, :small), - medium: thumb_url(image, show_hidden, :medium), - large: thumb_url(image, show_hidden, :large), - tall: thumb_url(image, show_hidden, :tall), - full: pretty_url(image, true, false) - } + Thumbnailer.thumbnail_versions() + |> Map.new(fn {name, {width, height}} -> + if image.image_width > width or image.image_height > height do + {name, thumb_url(image, show_hidden, name)} + else + {name, thumb_url(image, show_hidden, :full)} + end + end) |> append_full_url(image, show_hidden) |> append_gif_urls(image, show_hidden) end