2019-08-18 18:17:05 +02:00
|
|
|
defmodule PhilomenaWeb.ImageView do
|
|
|
|
use PhilomenaWeb, :view
|
|
|
|
|
2019-10-05 02:27:26 +02:00
|
|
|
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),
|
|
|
|
full: thumb_url(image, show_hidden, :full)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2019-08-18 18:17:05 +02:00
|
|
|
def thumb_url(image, show_hidden, name) do
|
2019-08-18 20:14:36 +02:00
|
|
|
%{year: year, month: month, day: day} = image.created_at
|
|
|
|
deleted = image.hidden_from_users
|
|
|
|
format = image.image_format
|
|
|
|
root = image_url_root()
|
|
|
|
|
|
|
|
id_fragment =
|
|
|
|
if deleted and show_hidden do
|
|
|
|
"#{image.id}-#{image.hidden_image_Key}"
|
|
|
|
else
|
|
|
|
"#{image.id}"
|
|
|
|
end
|
|
|
|
|
|
|
|
"#{root}/#{year}/#{month}/#{day}/#{id_fragment}/#{name}.#{format}"
|
|
|
|
end
|
|
|
|
|
|
|
|
def pretty_url(image, _short, download) do
|
|
|
|
%{year: year, month: month, day: day} = image.created_at
|
|
|
|
root = image_url_root()
|
|
|
|
|
|
|
|
view = if download, do: "download", else: "view"
|
|
|
|
filename = "#{image.id}"
|
|
|
|
format = image.image_format
|
|
|
|
|
|
|
|
"#{root}/#{view}/#{year}/#{month}/#{day}/#{filename}.#{format}"
|
|
|
|
end
|
|
|
|
|
|
|
|
def image_url_root do
|
|
|
|
Application.get_env(:philomena, :image_url_root)
|
2019-08-18 18:17:05 +02:00
|
|
|
end
|
|
|
|
end
|