2018-05-11 14:59:20 +02:00
|
|
|
class AntiVirusJob < ApplicationJob
|
|
|
|
include ActiveStorage::Downloading
|
|
|
|
|
|
|
|
attr_reader :blob
|
|
|
|
|
|
|
|
def perform(virus_scan)
|
|
|
|
@blob = ActiveStorage::Blob.find_by(key: virus_scan.blob_key)
|
|
|
|
|
|
|
|
if @blob.present?
|
|
|
|
download_blob_to_tempfile do |file|
|
|
|
|
if ClamavService.safe_file?(file.path)
|
2018-08-28 09:53:19 +02:00
|
|
|
status = VirusScan.statuses.fetch(:safe)
|
2018-05-11 14:59:20 +02:00
|
|
|
else
|
2018-08-28 09:53:19 +02:00
|
|
|
status = VirusScan.statuses.fetch(:infected)
|
2018-05-11 14:59:20 +02:00
|
|
|
end
|
|
|
|
virus_scan.update(scanned_at: Time.now, status: status)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|