2019-02-28 18:36:28 +01:00
|
|
|
ActiveStorage::Service.url_expires_in = 1.hour
|
2019-05-02 11:37:35 +02:00
|
|
|
|
|
|
|
# We want to run the virus scan on every ActiveStorage attachment,
|
|
|
|
# regardless of its type (user-uploaded document, instructeur-uploaded attestation, form template, etc.)
|
|
|
|
#
|
|
|
|
# To do this, the best place to work on is the ActiveStorage::Attachment
|
|
|
|
# objects themselves.
|
|
|
|
#
|
|
|
|
# We have to monkey patch ActiveStorage in order to always run an analyzer.
|
|
|
|
# The way analyzable blob interface work is by running the first accepted analyzer.
|
|
|
|
# This is not what we want for the virus scan. Using analyzer interface is still beneficial
|
|
|
|
# as it takes care of downloading the blob.
|
|
|
|
ActiveStorage::Attachment.class_eval do
|
|
|
|
after_create_commit :virus_scan
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def virus_scan
|
|
|
|
ActiveStorage::VirusScanner.new(blob).analyze_later
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
ActiveStorage::Attached::One.class_eval do
|
|
|
|
def virus_scanner
|
|
|
|
if attached?
|
|
|
|
ActiveStorage::VirusScanner.new(attachment.blob)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|