From 55eac3c6384cb2f4cff4323ea55910c515ee2e16 Mon Sep 17 00:00:00 2001 From: liamwhite Date: Mon, 4 Mar 2024 10:57:46 -0500 Subject: [PATCH] fix propagation of replaced file in edit script (#192) fixes derpibooru/philomena#281 --- lib/philomena/images/thumbnailer.ex | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/philomena/images/thumbnailer.ex b/lib/philomena/images/thumbnailer.ex index 6d96256e..4750847a 100644 --- a/lib/philomena/images/thumbnailer.ex +++ b/lib/philomena/images/thumbnailer.ex @@ -76,16 +76,26 @@ defmodule Philomena.Images.Thumbnailer do file = download_image_file(image) {:ok, analysis} = Analyzers.analyze(file) - apply_edit_script(image, Processors.process(analysis, file, generated_sizes(image))) + file = apply_edit_script(image, file, Processors.process(analysis, file, generated_sizes(image))) generate_dupe_reports(image) recompute_meta(image, file, &Image.thumbnail_changeset/2) - apply_edit_script(image, Processors.post_process(analysis, file)) + file = apply_edit_script(image, file, Processors.post_process(analysis, file)) recompute_meta(image, file, &Image.process_changeset/2) end - defp apply_edit_script(image, changes), - do: Enum.map(changes, &apply_change(image, &1)) + defp apply_edit_script(image, file, changes) do + Enum.reduce(changes, file, fn change, existing_file -> + apply_change(image, change) + + case change do + {:replace_original, new_file} -> + new_file + _ -> + existing_file + end + end) + end defp apply_change(image, {:intensities, intensities}), do: ImageIntensities.create_image_intensity(image, intensities)