From e855646d8b72eedc12a37d2663fc0eda79e765c3 Mon Sep 17 00:00:00 2001 From: Vasily Fedoseyev Date: Sat, 6 Apr 2024 14:48:03 +0300 Subject: [PATCH] =?UTF-8?q?to=5Ffile=20=D1=83=D0=B6=D0=B5=20=D0=BF=D1=80?= =?UTF-8?q?=D0=BE=D0=B2=D0=B5=D1=80=D1=8F=D0=B5=D1=82=20=D0=BD=D0=B0=D0=BB?= =?UTF-8?q?=D0=B8=D1=87=D0=B8=D0=B5=20=D1=84=D0=B0=D0=B9=D0=BB=D0=BE=D0=B2?= =?UTF-8?q?,=20=D0=B0=20=D0=B2=D0=BE=D1=82=20=D0=B7=D0=B0=D0=BA=D1=80?= =?UTF-8?q?=D1=8B=D0=B2=D0=B0=D1=82=D1=8C=20=D0=BD=D0=B0=D0=B4=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/paperclip/recursive_thumbnail.rb | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/lib/paperclip/recursive_thumbnail.rb b/lib/paperclip/recursive_thumbnail.rb index 2e55cff..cc091c3 100644 --- a/lib/paperclip/recursive_thumbnail.rb +++ b/lib/paperclip/recursive_thumbnail.rb @@ -1,16 +1,21 @@ +# frozen_string_literal: true + module Paperclip class RecursiveThumbnail < Thumbnail - def initialize file, options = {}, attachment = nil - - # если по каким-то причинам не сформировался файл - # для прыдущего размера не кидаем ексепшен и - # генерим файл из оригинального + def initialize(file, options = {}, attachment = nil) source_style = options[:thumbnail] || :original - # TODO: вообще queued_for_write[source_style] место в NoCacheS3#to_file - f = attachment&.queued_for_write&.dig(source_style)&.tap(&:flush)&.tap(&:rewind) - # TODO: и надо сносить файл если все же была загрузка - f ||= attachment.to_file(source_style) rescue file # rubocop:disable Style/RescueModifier - super(f, options, attachment) + # если по каким-то причинам не сформировался файл прыдущего размера - генерим из оригинального + source_file = begin + attachment.to_file(source_style) + rescue + Paperclip.log "Using original for #{options}" + file + end + super(source_file, options, attachment) + ensure + if source_file != file && source_file.respond_to?(:close!) && !attachment&.queued_for_write&.value?(source_file) + source_file.close! + end end end end