2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2024-04-29 16:53:21 +02:00
|
|
|
# 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?
|
2024-10-24 10:13:34 +02:00
|
|
|
return if blob.attachments.size != 1
|
2024-05-16 12:54:09 +02:00
|
|
|
return if blob.attachments.last.record_type == "Export"
|
2024-10-24 11:50:41 +02:00
|
|
|
return if !blob.content_type.in?(PROCESSABLE_TYPES)
|
2024-05-07 16:27:08 +02:00
|
|
|
|
2024-04-29 16:53:21 +02:00
|
|
|
ImageProcessorJob.perform_later(blob)
|
|
|
|
end
|
|
|
|
end
|