You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.4 KiB

  1. # frozen_string_literal: true
  2. module Paperclip
  3. module AttachmentExtensions
  4. # We overwrite this method to support delayed processing in
  5. # Sidekiq. Since we process the original file to reduce disk
  6. # usage, and we still want to generate thumbnails straight
  7. # away, it's the only style we need to exclude
  8. def process_style?(style_name, style_args)
  9. if style_name == :original && instance.respond_to?(:delay_processing?) && instance.delay_processing?
  10. false
  11. else
  12. style_args.empty? || style_args.include?(style_name)
  13. end
  14. end
  15. def reprocess_original!
  16. old_original_path = path(:original)
  17. reprocess!(:original)
  18. new_original_path = path(:original)
  19. if new_original_path != old_original_path
  20. @queued_for_delete << old_original_path
  21. flush_deletes
  22. end
  23. end
  24. def variant?(other_filename)
  25. return true if original_filename == other_filename
  26. return false if original_filename.nil?
  27. formats = styles.values.map(&:format).compact
  28. return false if formats.empty?
  29. other_extension = File.extname(other_filename)
  30. formats.include?(other_extension.delete('.')) && File.basename(other_filename, other_extension) == File.basename(original_filename, File.extname(original_filename))
  31. end
  32. end
  33. end
  34. Paperclip::Attachment.prepend(Paperclip::AttachmentExtensions)