update image size after optimization

This commit is contained in:
byte[] 2020-01-01 12:13:07 -05:00
parent bdee305936
commit df3467df7b
2 changed files with 14 additions and 8 deletions

View file

@ -158,13 +158,13 @@ defmodule Philomena.Images.Image do
def thumbnail_changeset(image, attrs) do
image
|> cast(attrs, [:image_sha512_hash])
|> cast(attrs, [:image_sha512_hash, :image_size])
|> change(thumbnails_generated: true, duplication_checked: true)
end
def process_changeset(image, attrs) do
image
|> cast(attrs, [:image_sha512_hash])
|> cast(attrs, [:image_sha512_hash, :image_size])
|> change(processed: true)
end

View file

@ -29,11 +29,11 @@ defmodule Philomena.Images.Thumbnailer do
{:ok, analysis} = Analyzers.analyze(file)
apply_edit_script(image, Processors.process(analysis, file, @versions))
recompute_sha512(image, file, &Image.thumbnail_changeset/2)
recompute_meta(image, file, &Image.thumbnail_changeset/2)
generate_dupe_reports(image)
apply_edit_script(image, Processors.post_process(analysis, file))
recompute_sha512(image, file, &Image.process_changeset/2)
recompute_meta(image, file, &Image.process_changeset/2)
end
@ -58,12 +58,18 @@ defmodule Philomena.Images.Thumbnailer do
do: symlink(image_file(image), Path.join(thumb_dir, destination))
defp recompute_sha512(image, file, changeset_fn),
do: Repo.update!(changeset_fn.(image, %{"image_sha512_hash" => Sha512.file(file)}))
defp generate_dupe_reports(image),
do: DuplicateReports.generate_reports(image)
defp recompute_meta(image, file, changeset_fn) do
image
|> changeset_fn.(%{
"image_sha512_hash" => Sha512.file(file),
"image_size" => File.stat!(file).size
})
|> Repo.update!()
end
# Copy from source to destination, creating parent directories along
# the way and setting the appropriate permission bits when necessary.
@ -119,4 +125,4 @@ defmodule Philomena.Images.Thumbnailer do
defp image_thumbnail_root,
do: Application.get_env(:philomena, :image_file_root) <> "/thumbs"
end
end