2019-05-02 11:37:35 +02:00
|
|
|
class ActiveStorage::VirusScanner
|
|
|
|
def initialize(blob)
|
|
|
|
@blob = blob
|
|
|
|
end
|
|
|
|
|
|
|
|
attr_reader :blob
|
|
|
|
|
|
|
|
PENDING = 'pending'
|
|
|
|
INFECTED = 'infected'
|
|
|
|
SAFE = 'safe'
|
|
|
|
|
|
|
|
def pending?
|
|
|
|
blob.metadata[:virus_scan_result] == PENDING
|
|
|
|
end
|
|
|
|
|
|
|
|
def infected?
|
|
|
|
blob.metadata[:virus_scan_result] == INFECTED
|
|
|
|
end
|
|
|
|
|
|
|
|
def safe?
|
|
|
|
blob.metadata[:virus_scan_result] == SAFE
|
|
|
|
end
|
|
|
|
|
2019-05-16 18:59:34 +02:00
|
|
|
def done?
|
|
|
|
started? && blob.metadata[:virus_scan_result] != PENDING
|
2019-05-02 11:37:35 +02:00
|
|
|
end
|
|
|
|
|
2019-05-16 18:59:34 +02:00
|
|
|
def started?
|
|
|
|
blob.metadata[:virus_scan_result].present?
|
2019-05-02 11:37:35 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def metadata
|
2020-01-28 12:02:06 +01:00
|
|
|
blob.open do |file|
|
2019-05-16 18:59:34 +02:00
|
|
|
if ClamavService.safe_file?(file.path)
|
|
|
|
{ virus_scan_result: SAFE, scanned_at: Time.zone.now }
|
|
|
|
else
|
|
|
|
{ virus_scan_result: INFECTED, scanned_at: Time.zone.now }
|
2019-05-02 11:37:35 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|