create a job for all image treatments
This commit is contained in:
parent
fce2c03015
commit
b4a7b4bfbd
8 changed files with 91 additions and 60 deletions
|
@ -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
|
21
app/models/concerns/attachment_image_processor_concern.rb
Normal file
21
app/models/concerns/attachment_image_processor_concern.rb
Normal 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
|
|
@ -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
|
Loading…
Add table
Add a link
Reference in a new issue