mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-24 04:27:59 +01:00
Move all affected versions
This commit is contained in:
parent
82c84fcccb
commit
7094f14072
1 changed files with 17 additions and 9 deletions
|
@ -37,14 +37,15 @@ defmodule Philomena.Images.Thumbnailer do
|
||||||
end
|
end
|
||||||
|
|
||||||
def thumbnail_urls(image, hidden_key) do
|
def thumbnail_urls(image, hidden_key) do
|
||||||
Processors.versions(image.image_mime_type, generated_sizes(image))
|
image
|
||||||
|
|> all_versions()
|
||||||
|> Enum.map(fn name ->
|
|> Enum.map(fn name ->
|
||||||
Path.join(image_url_base(image, hidden_key), name)
|
Path.join(image_url_base(image, hidden_key), name)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
def hide_thumbnails(image, key) do
|
def hide_thumbnails(image, key) do
|
||||||
moved_files = Processors.versions(image.image_mime_type, generated_sizes(image))
|
moved_files = all_versions(image)
|
||||||
|
|
||||||
source_prefix = visible_image_thumb_prefix(image)
|
source_prefix = visible_image_thumb_prefix(image)
|
||||||
target_prefix = hidden_image_thumb_prefix(image, key)
|
target_prefix = hidden_image_thumb_prefix(image, key)
|
||||||
|
@ -53,7 +54,7 @@ defmodule Philomena.Images.Thumbnailer do
|
||||||
end
|
end
|
||||||
|
|
||||||
def unhide_thumbnails(image, key) do
|
def unhide_thumbnails(image, key) do
|
||||||
moved_files = Processors.versions(image.image_mime_type, generated_sizes(image))
|
moved_files = all_versions(image)
|
||||||
|
|
||||||
source_prefix = hidden_image_thumb_prefix(image, key)
|
source_prefix = hidden_image_thumb_prefix(image, key)
|
||||||
target_prefix = visible_image_thumb_prefix(image)
|
target_prefix = visible_image_thumb_prefix(image)
|
||||||
|
@ -62,7 +63,7 @@ defmodule Philomena.Images.Thumbnailer do
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy_thumbnails(image) do
|
def destroy_thumbnails(image) do
|
||||||
affected_files = Processors.versions(image.image_mime_type, generated_sizes(image))
|
affected_files = all_versions(image)
|
||||||
|
|
||||||
hidden_prefix = hidden_image_thumb_prefix(image, image.hidden_image_key)
|
hidden_prefix = hidden_image_thumb_prefix(image, image.hidden_image_key)
|
||||||
visible_prefix = visible_image_thumb_prefix(image)
|
visible_prefix = visible_image_thumb_prefix(image)
|
||||||
|
@ -136,24 +137,31 @@ defmodule Philomena.Images.Thumbnailer do
|
||||||
|> ExAws.request!()
|
|> ExAws.request!()
|
||||||
end
|
end
|
||||||
|
|
||||||
def bulk_rename(file_names, source_prefix, target_prefix) do
|
defp bulk_rename(file_names, source_prefix, target_prefix) do
|
||||||
Enum.map(file_names, fn name ->
|
Enum.map(file_names, fn name ->
|
||||||
source = Path.join(source_prefix, name)
|
source = Path.join(source_prefix, name)
|
||||||
target = Path.join(target_prefix, name)
|
target = Path.join(target_prefix, name)
|
||||||
|
|
||||||
ExAws.request!(S3.put_object_copy(bucket(), target, bucket(), source, @acl))
|
ExAws.request(S3.put_object_copy(bucket(), target, bucket(), source, @acl))
|
||||||
ExAws.request!(S3.delete_object(bucket(), source))
|
ExAws.request(S3.delete_object(bucket(), source))
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
def bulk_delete(file_names, prefix) do
|
defp bulk_delete(file_names, prefix) do
|
||||||
Enum.map(file_names, fn name ->
|
Enum.map(file_names, fn name ->
|
||||||
target = Path.join(prefix, name)
|
target = Path.join(prefix, name)
|
||||||
|
|
||||||
ExAws.request!(S3.delete_object(bucket(), target))
|
ExAws.request(S3.delete_object(bucket(), target))
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp all_versions(image) do
|
||||||
|
generated = Processors.versions(image.image_mime_type, generated_sizes(image))
|
||||||
|
full = ["full.#{image.image_format}"]
|
||||||
|
|
||||||
|
generated ++ full
|
||||||
|
end
|
||||||
|
|
||||||
# This method wraps the following two for code that doesn't care
|
# This method wraps the following two for code that doesn't care
|
||||||
# and just wants the files (most code should take this path)
|
# and just wants the files (most code should take this path)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue