recalculate size on processing (derpibooru/philomena#206)

This commit is contained in:
byte[] 2020-09-27 00:46:38 -04:00
parent 02cbecb193
commit a955a67b24
2 changed files with 7 additions and 3 deletions

View file

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

View file

@ -57,10 +57,14 @@ defmodule Philomena.Images.Thumbnailer do
do: DuplicateReports.generate_reports(image)
defp recompute_meta(image, file, changeset_fn) do
{:ok, %{dimensions: {width, height}}} = Analyzers.analyze(file)
image
|> changeset_fn.(%{
"image_sha512_hash" => Sha512.file(file),
"image_size" => File.stat!(file).size
"image_size" => File.stat!(file).size,
"image_width" => width,
"image_height" => height
})
|> Repo.update!()
end