create a job for all image treatments

This commit is contained in:
Lisa Durand 2024-04-29 16:53:21 +02:00 committed by Eric Leroy-Terquem
parent fce2c03015
commit b4a7b4bfbd
No known key found for this signature in database
GPG key ID: ECE60B4C1FA2ABB3
8 changed files with 91 additions and 60 deletions

View file

@ -1,22 +0,0 @@
module AttachmentAutoRotateConcern
extend ActiveSupport::Concern
included do
after_create_commit :auto_rotate
end
private
def auto_rotate
return if blob.nil?
return if ["image/jpeg", "image/jpg"].exclude?(blob.content_type)
blob.open do |file|
Tempfile.create(["rotated", File.extname(file)]) do |output|
processed = AutoRotateService.new.process(file, output)
blob.upload(processed) # also update checksum & byte_size accordingly
blob.save!
end
end
end
end

View file

@ -0,0 +1,21 @@
# Run a virus scan on all attachments after they are analyzed.
#
# We're using a class extension to ensure that all attachments get scanned,
# regardless on how they were created. This could be an ActiveStorage::Analyzer,
# but as of Rails 6.1 only the first matching analyzer is ever run on
# a blob (and we may want to analyze the dimension of a picture as well
# as scanning it).
module AttachmentImageProcessorConcern
extend ActiveSupport::Concern
included do
after_create_commit :process_image
end
private
def process_image
return if blob.nil?
ImageProcessorJob.perform_later(blob)
end
end

View file

@ -1,4 +1,4 @@
module BlobTitreIdentiteWatermarkConcern
module BlobImageProcessorConcern
def watermark_pending?
watermark_required? && !watermark_done?
end
@ -7,10 +7,8 @@ module BlobTitreIdentiteWatermarkConcern
watermarked_at.present?
end
def watermark_later
if watermark_pending?
TitreIdentiteWatermarkJob.perform_later(self)
end
def variant_required?
attachments.any? { _1.record.class == Champs::TitreIdentiteChamp || _1.record.class == Champs::PieceJustificativeChamp }
end
private