diff --git a/lib/philomena/images/image.ex b/lib/philomena/images/image.ex index d6d5ccce..1630082d 100644 --- a/lib/philomena/images/image.ex +++ b/lib/philomena/images/image.ex @@ -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 diff --git a/lib/philomena/images/thumbnailer.ex b/lib/philomena/images/thumbnailer.ex index 674e55f6..8e9a236a 100644 --- a/lib/philomena/images/thumbnailer.ex +++ b/lib/philomena/images/thumbnailer.ex @@ -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 \ No newline at end of file +end