diff --git a/app/services/model_exporters/model_exporter.rb b/app/services/model_exporters/model_exporter.rb index 38975ec79..faac2e0a0 100644 --- a/app/services/model_exporters/model_exporter.rb +++ b/app/services/model_exporters/model_exporter.rb @@ -1,11 +1,13 @@ # frozen_string_literal: true require 'fileutils' +require 'active_storage/downloading' module ModelExporters class ModelExporter attr_accessor :assets_to_copy attr_accessor :tiny_mce_assets_to_copy + include ActiveStorage::Downloading def initialize @assets_to_copy = [] @@ -15,22 +17,16 @@ module ModelExporters def copy_files(assets, attachment_name, dir_name) assets.flatten.each do |a| next unless a.public_send(attachment_name).attached? + blob = a.public_send(attachment_name).blob + dir = FileUtils.mkdir_p(File.join(dir_name, a.id.to_s)).first + destination_path = File.join(dir, a.file_name) + + blob.open do |file| + system '/path/to/virus/scanner', file.path + FileUtils.cp(file.path, destination_path) + end yield if block_given? - dir = FileUtils.mkdir_p(File.join(dir_name, a.id.to_s)).first - - tempfile = Tempfile.new - tempfile.binmode - a.public_send(attachment_name).blob.download { |chunk| tempfile.write(chunk) } - tempfile.flush - tempfile.rewind - FileUtils.cp( - tempfile.path, - File.join(dir, a.file_name) - ) - ensure - tempfile.close - tempfile.unlink end end